Skip to content

Commit

Permalink
fix issue where local-project gets saved as user's last loaded project
Browse files Browse the repository at this point in the history
  • Loading branch information
bthaile committed Apr 21, 2023
1 parent b07959e commit eef79cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/containers/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useGetProject, { useProject } from 'providers/Project/projectHooks';
import React, { CSSProperties } from 'react';
import { Box, Button, Spinner, ThemeUICSSObject } from 'theme-ui';
import { userDataKeys, UserLocalStorage } from 'util/localstorage';
import { LOCAL_PROJECT_ID } from 'util/url';
import useToggleExplorer from '../../hooks/useToggleExplorer';
import EditorLayout from './EditorLayout';

Expand Down Expand Up @@ -126,6 +127,16 @@ const Playground = ({ projectId }: PlaygroundProps) => {
const userProjectId = userStorage.getDataByKey(userDataKeys.PROJECT_ID);
const loadingProjectId = projectId || userProjectId;

console.log(
'projectId',
'path',
location.pathname,
'id',
projectId,
'user',
userProjectId,
);

let project: Project;
let isLocal: boolean;
let isLoading: boolean;
Expand Down Expand Up @@ -166,6 +177,7 @@ const Playground = ({ projectId }: PlaygroundProps) => {
'Click <ok> to go to home page or last loaded project',
],
};

if (loadingProjectId === userProjectId) {
// issue loading project clear last saved loaded project id
userStorage.setData(userDataKeys.PROJECT_ID, null);
Expand All @@ -186,8 +198,10 @@ const Playground = ({ projectId }: PlaygroundProps) => {
// update location to reflect project loaded
window.history.replaceState({}, '', loadingProjectId);
}
// project loaded successfully save as user's last project
userStorage.setData(userDataKeys.PROJECT_ID, loadingProjectId);
if (loadingProjectId !== LOCAL_PROJECT_ID) {
// project loaded successfully save as user's last project
userStorage.setData(userDataKeys.PROJECT_ID, loadingProjectId);
}

return (
<ProjectProvider project={project} isLocal={isLocal} client={client}>
Expand Down
2 changes: 1 addition & 1 deletion src/providers/Project/projectHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function useGetProject(
isClone: boolean;
isLoading: boolean;
} {
const isNewProject = projectId == null || projectId === LOCAL_PROJECT_ID;
const isNewProject = !projectId || projectId === LOCAL_PROJECT_ID;

const { loading, data: remoteData } = useQuery(GET_PROJECT, {
variables: { projectId: projectId },
Expand Down

0 comments on commit eef79cb

Please sign in to comment.