Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature-recipes'
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed Nov 29, 2023
2 parents e742253 + c1d79c0 commit d9ee965
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/src/hooks/useWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Workspace = {
layers: Layers;
};


export function useWorkspace() {
const notify = useSnackbar();
const [layers, setLayers] = useLayers();
Expand Down
96 changes: 96 additions & 0 deletions client/src/pages/RecipesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { WorkspacesOutlined } from "@mui/icons-material";
import {
Box,
List,
ListItemButton,
ListItemIcon,
ListItemText,
Typography as Type
} from "@mui/material";
import { Flex } from "components/generic/Flex";
import { Scroll } from "components/generic/Scrollbars";
import { useViewTreeContext } from "components/inspector/ViewTree";
import { useWorkspace } from "hooks/useWorkspace";
import { startCase, values } from "lodash";
import { Page } from "pages/Page";
import { ReactNode } from "react";


const paths = (import.meta.glob("/public/recipes/*.workspace", { as: "url" }));
const files = await Promise.all(values(paths).map(f => f()))

function stripExtension(path:string) {
return path.split(".")[0];
}

function basename(path: string) {
return path.split('/').pop()!;
}

export function RecipesPage() {
const { controls, onChange, state } = useViewTreeContext();
const { load } = useWorkspace();

async function open(path:string){
try {
const response = await fetch(path);

if (!response.ok) {
throw new Error('Network response was not ok');
}

const blob = await response.blob();
const filename = basename(path);
const file = new File([blob], filename, { type: blob.type });

load(file)

} catch (error) {
console.error('There was a problem with the fetch operation:', error);
}
}

function renderSection(label: ReactNode, content: ReactNode) {
return (
<Box sx={{ pt: 2 }}>
<Type variant="overline" color="text.secondary">
{label}
</Type>
<Type variant="body2">{content}</Type>
</Box>
);
}

return (
<Page onChange={onChange} stack={state}>
<Page.Content>

<Flex>
<Scroll y>
<Box sx={{ p: 2, width: '100%' }}>
<Type variant="h6">Recipes</Type>
{renderSection(
"Recipes",
<>
<List sx={{ width: '100%', maxWidth: '100%' }}>
{files.map(( path , i) => (
<ListItemButton key={i} onClick={() => open(path)}>
<ListItemIcon>
<WorkspacesOutlined/>
</ListItemIcon>
<ListItemText primary={startCase(stripExtension(basename(path)))} />
</ListItemButton>
))}
</List>
</>
)}
</Box>
</Scroll>
</Flex>
</Page.Content>
<Page.Extras>{controls}</Page.Extras>
</Page>
);
}


9 changes: 9 additions & 0 deletions client/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SettingsOutlined,
SortOutlined as StepsIcon,
ViewInArOutlined,
WorkspacesOutlined,
} from "@mui/icons-material";
import { Dictionary } from "lodash";
import { ReactNode } from "react";
Expand All @@ -18,6 +19,8 @@ import { SettingsPage } from "./SettingsPage";
import { StepsPage } from "./StepsPage";
import { TreePage } from "./TreePage";
import { ViewportPage } from "./ViewportPage";
import { RecipesPage } from "./RecipesPage";


export type PageMeta = {
id: string;
Expand Down Expand Up @@ -75,4 +78,10 @@ export const pages: Dictionary<PageMeta> = {
icon: <InfoOutlined />,
content: AboutPage,
},
recipes: {
id: "recipes",
name: "Recipes",
icon: <WorkspacesOutlined />,
content: RecipesPage,
},
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added client/src/public/recipes/mapf-large.workspace
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added client/src/public/recipes/nine-tile.workspace
Binary file not shown.
Binary file not shown.

0 comments on commit d9ee965

Please sign in to comment.