Skip to content

Commit

Permalink
better way of the add address searchbar modal to show by default when…
Browse files Browse the repository at this point in the history
… the graph is empty
  • Loading branch information
Rodriguespn committed Feb 22, 2024
1 parent 29ae4ef commit c4755c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/PrivateApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const PrivateApp: FC<PrivateAppProps> = ({
/>
<Route
path={`/${userID}/graph`}
element={<UnsavedGraphTemplate showLandingPage={false} showSearchbar={true} />}
element={<UnsavedGraphTemplate showLandingPage={false} />}
/>
<Route path="/graph" element={<Navigate to={`/${userID}/graph`} />} />
<Route path={`/${userID}/graph/new`} element={<UnsavedGraphTemplate showLandingPage={false} showSearchbar={true} />} />
<Route path={`/${userID}/graph/new`} element={<UnsavedGraphTemplate showLandingPage={false} />} />
<Route path={`/${userID}/saved-graph/:uid`} element={<SavedGraphTemplate />} />
<Route path={`/${userID}/billing`} element={<BillingTemplate />} />
<Route path={`/${userID}/graphs`} element={<SavedGraphsTemplate />} />
Expand Down
11 changes: 5 additions & 6 deletions src/components/graph/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const GraphContext = createContext<GraphContextProps>(
interface GraphProps {
initialAddresses: string[];
initialPaths: string[];
showSearchbar: boolean;
onAutoSave?: (graphInfo: PersonalGraphInfo) => void;
onLocalSave?: (graphInfo: SharableGraph) => void;
}
Expand All @@ -133,7 +132,6 @@ interface GraphProps {
const Graph: FC<GraphProps> = ({
initialAddresses,
initialPaths,
showSearchbar,
onAutoSave,
onLocalSave,
}) => {
Expand Down Expand Up @@ -185,7 +183,6 @@ const Graph: FC<GraphProps> = ({
<GraphProvided
initialNodes={initialLayoutedNodes}
initialEdges={initialEdges}
showSearchbar={showSearchbar}
onAutoSave={onAutoSave}
onLocalSave={onLocalSave}
/>
Expand All @@ -198,7 +195,6 @@ const Graph: FC<GraphProps> = ({
interface GraphProvidedProps {
initialNodes: Node[];
initialEdges: Edge[];
showSearchbar: boolean;
onAutoSave?: (graphInfo: PersonalGraphInfo) => void;
onLocalSave?: (graphInfo: SharableGraph) => void;
}
Expand All @@ -212,7 +208,6 @@ const MemoedDraggableWindow = memo(DraggableWindow);
const GraphProvided: FC<GraphProvidedProps> = ({
initialNodes,
initialEdges,
showSearchbar,
onAutoSave,
onLocalSave
}) => {
Expand Down Expand Up @@ -338,7 +333,7 @@ const GraphProvided: FC<GraphProvidedProps> = ({
edges: personalGraphInfo.edges
}
debounceSaveLocal.current(newLocalGraph);
}, [nodes.length, edges.length]);
}, [nodes.length]);

// Undo and Redo -------------------------------------------------------------

Expand Down Expand Up @@ -922,6 +917,10 @@ const GraphProvided: FC<GraphProvidedProps> = ({
personalGraphInfo,
};

const showSearchbar = useMemo(() => {
return initialNodes.length === 0;
}, [initialNodes]);

return (
<>
<GraphContext.Provider value={graphContext}>
Expand Down
3 changes: 0 additions & 3 deletions src/templates/UnsavedGraphTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import useAuthState from "../hooks/useAuthState";

interface UnsavedGraphTemplateProps {
showLandingPage?: boolean;
showSearchbar?: boolean;
}

const UnsavedGraphTemplate: FC<UnsavedGraphTemplateProps> = ({
showLandingPage = true,
showSearchbar = false,
}) => {
const { uid } = useParams<{ uid: string }>();
const { isAuthenticated } = useAuthState();
Expand Down Expand Up @@ -130,7 +128,6 @@ const UnsavedGraphTemplate: FC<UnsavedGraphTemplateProps> = ({
initialAddresses={initialAddresses}
initialPaths={initialPaths}
onLocalSave={saveGraph}
showSearchbar={showSearchbar}
/>
</Transition>
</div>
Expand Down

0 comments on commit c4755c6

Please sign in to comment.