Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: project setting page does not display correctly after creating a…
Browse files Browse the repository at this point in the history
… new project (#127)

* Fetch and re-fetch projects from network first time

* fix type error

* fix type error

Co-authored-by: basel.issmail <basel.issmail@gmail.com>
Co-authored-by: rot1024 <aayhrot@gmail.com>
  • Loading branch information
3 people committed Nov 11, 2021
1 parent fbf6e9d commit c120dcc
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 159 deletions.
10 changes: 8 additions & 2 deletions src/components/organisms/Dashboard/hooks.ts
Expand Up @@ -6,6 +6,7 @@ import type { User } from "@reearth/components/molecules/Common/Header";
import type { Project, Team } from "@reearth/components/molecules/Dashboard";
import {
useMeQuery,
useProjectQuery,
useCreateTeamMutation,
PublishmentStatus,
useCreateProjectMutation,
Expand Down Expand Up @@ -103,8 +104,13 @@ export default (teamId?: string) => {
[refetch],
);

const { data: projectData } = useProjectQuery({
variables: { teamId: teamId ?? "" },
skip: !teamId,
});

const projects = useMemo(() => {
return (team?.projects.nodes ?? [])
return (projectData?.projects.nodes ?? [])
.map<Project | undefined>(project =>
project
? {
Expand All @@ -119,7 +125,7 @@ export default (teamId?: string) => {
: undefined,
)
.filter((project): project is Project => !!project);
}, [team?.projects.nodes]);
}, [projectData?.projects.nodes]);

const [createNewProject] = useCreateProjectMutation({
refetchQueries: ["Project"],
Expand Down
34 changes: 17 additions & 17 deletions src/components/organisms/EarthEditor/OutlinePane/hooks.tsx
Expand Up @@ -21,6 +21,7 @@ import {
Maybe,
useGetWidgetsQuery,
PluginExtensionType,
GetLayersFromLayerIdQuery,
} from "@reearth/gql";
import {
useSceneId,
Expand All @@ -42,18 +43,6 @@ const convertFormat = (format: Format) => {
return undefined;
};

type GQLLayer = {
__typename?: "LayerGroup" | "LayerItem";
id: string;
name: string;
isVisible: boolean;
pluginId?: string | null;
extensionId?: string | null;
linkedDatasetSchemaId?: string | null;
linkedDatasetId?: string | null;
layers?: Maybe<GQLLayer>[];
};

export default () => {
const intl = useIntl();
const [sceneId] = useSceneId();
Expand Down Expand Up @@ -254,16 +243,21 @@ export default () => {
const addLayerGroup = useCallback(() => {
if (!rootLayerId) return;

const layers: Maybe<GQLLayer>[] =
const layers: (Maybe<GQLLayer> | undefined)[] =
data?.layer?.__typename === "LayerGroup" ? data.layer.layers : [];
const children = (l: Maybe<GQLLayer>) => (l?.__typename == "LayerGroup" ? l.layers : undefined);
const children = (l: Maybe<GQLLayer> | undefined) =>
l?.__typename == "LayerGroup" ? l.layers : undefined;

const layerIndex =
selected?.type === "layer"
? deepFind(layers, l => l?.id === selected.layerId, children)[1]
? deepFind<Maybe<GQLLayer> | undefined>(
layers,
l => l?.id === selected.layerId,
children,
)[1]
: undefined;
const parentLayer = layerIndex?.length
? deepGet(layers, layerIndex.slice(0, -1), children)
? deepGet<Maybe<GQLLayer> | undefined>(layers, layerIndex.slice(0, -1), children)
: undefined;
if ((layerIndex && layerIndex.length > 5) || parentLayer?.linkedDatasetSchemaId) return;

Expand Down Expand Up @@ -372,7 +366,13 @@ export default () => {
};
};

const convertLayer = (layer: Maybe<GQLLayer>): Layer | undefined =>
type GQLLayer = Omit<NonNullable<GetLayersFromLayerIdQuery["layer"]>, "layers"> & {
linkedDatasetSchemaId?: string | null;
linkedDatasetId?: string | null;
layers?: (GQLLayer | null | undefined)[];
};

const convertLayer = (layer: Maybe<GQLLayer> | undefined): Layer | undefined =>
!layer
? undefined
: layer.__typename === "LayerGroup"
Expand Down
12 changes: 3 additions & 9 deletions src/components/organisms/EarthEditor/PropertyPane/convert.ts
Expand Up @@ -263,22 +263,16 @@ export const convertLinkableDatasets = (
.filter((s): s is DatasetSchema => !!s);
};

type GQLLayer = {
__typename?: "LayerGroup" | "LayerItem";
id: string;
name: string;
isVisible: boolean;
pluginId?: string | null;
extensionId?: string | null;
type GQLLayer = Omit<NonNullable<GetLayersFromLayerIdQuery["layer"]>, "layers"> & {
linkedDatasetSchemaId?: string | null;
linkedDatasetId?: string | null;
layers?: Maybe<GQLLayer>[];
layers?: (GQLLayer | null | undefined)[];
};

export function convertLayers(data: GetLayersFromLayerIdQuery | undefined): Layer[] {
const layers = data?.layer?.__typename === "LayerGroup" ? data.layer.layers : [];

function mapper(layer: Maybe<GQLLayer>): Layer | undefined {
function mapper(layer: Maybe<GQLLayer> | undefined): Layer | undefined {
if (!layer) return undefined;
return {
id: layer.id,
Expand Down
3 changes: 3 additions & 0 deletions src/components/organisms/Settings/Project/queries.ts
Expand Up @@ -17,6 +17,9 @@ export const PROJECT = gql`
publicImage
alias
publishmentStatus
scene {
id
}
}
}
}
Expand Down
263 changes: 133 additions & 130 deletions src/gql/graphql-client-api.tsx

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/gql/graphql.schema.json
Expand Up @@ -17133,7 +17133,20 @@
{
"name": "args",
"description": null,
"args": [],
"args": [
{
"name": "includeDeprecated",
"description": null,
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": "false",
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
Expand Down

0 comments on commit c120dcc

Please sign in to comment.