Skip to content

Commit

Permalink
persist selected folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Sep 15, 2024
1 parent d1eae33 commit 55d6c1c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
18 changes: 10 additions & 8 deletions apps/color-buddy/src/content-modules/ComparePal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
let showDiff = false;
let colorSpace = ComparisonPal?.colorSpace || "lab";
let selectedFolder: { isPreMade: boolean; name: string } = {
isPreMade: false,
name: "",
};
$: selectedFolder = $configStore.selectedFolder;
$: familiarPals = $examplePalStore.palettes
.map((x) => x.palette)
.filter((x) => selectedFolder.isPreMade && x.type === selectedFolder.name);
Expand Down Expand Up @@ -80,7 +77,10 @@
<button
class={buttonStyle}
on:click={() => {
selectedFolder = { isPreMade: true, name: folder };
configStore.setSelectedFolder({
isPreMade: true,
name: folder,
});
}}
class:underline={selectedFolder?.isPreMade &&
selectedFolder?.name === folder}
Expand All @@ -94,9 +94,11 @@
{#each folders as folder}
<button
class={buttonStyle}
on:click={() => {
selectedFolder = { isPreMade: false, name: folder };
}}
on:click={() =>
configStore.setSelectedFolder({
isPreMade: false,
name: folder,
})}
class:underline={selectedFolder?.isPreMade === false &&
selectedFolder?.name === folder}
>
Expand Down
24 changes: 7 additions & 17 deletions apps/color-buddy/src/content-modules/Manage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
$: familiarPals = $examplePalStore.palettes.map((x) => x.palette);
$: currentPal = $colorStore.palettes[$colorStore.currentPal];
$: colorSpace = currentPal.colorSpace;
$: selectedFolder = $configStore.selectedFolder;
function usePal(palette: Palette) {
colorStore.createNewPal(convertPalToSpace(palette, colorSpace));
focusStore.clearColors();
selectedFolder = { isPreMade: false, name: "" };
configStore.setSelectedFolder({ isPreMade: false, name: "" });
}
function makeOperations(
Expand Down Expand Up @@ -151,10 +152,6 @@
$: folders = Array.from(
new Set($colorStore.palettes.map((pal) => pal.folder.toLowerCase()))
).sort((a, b) => a.length - b.length);
let selectedFolder: { isPreMade: boolean; name: string } = {
isPreMade: false,
name: "",
};
</script>

<div class="bg-stone-300 py-2 px-6 flex-col">
Expand All @@ -180,7 +177,8 @@
.split(" ")
.filter((x) => x !== "font-bold")
.join(" ")}
on:click={() => (selectedFolder = { isPreMade: true, name: folder })}
on:click={() =>
configStore.setSelectedFolder({ isPreMade: true, name: folder })}
class:underline={selectedFolder?.isPreMade &&
selectedFolder?.name === folder}
>
Expand All @@ -196,7 +194,8 @@
.split(" ")
.filter((x) => x !== "font-bold")
.join(" ")}
on:click={() => (selectedFolder = { isPreMade: false, name: folder })}
on:click={() =>
configStore.setSelectedFolder({ isPreMade: false, name: folder })}
class:underline={selectedFolder?.name === folder}
>
{folder.length ? `${folder}/` : "root/"}
Expand All @@ -205,16 +204,7 @@
</div>
{#if selectedFolder?.isPreMade === false && selectedFolder?.name !== ""}
<div class="bg-stone-200 px-4">
<FolderConfig
folder={selectedFolder.name}
setFolder={(newFolder) => {
if (newFolder) {
selectedFolder = { isPreMade: false, name: newFolder };
} else {
selectedFolder = { isPreMade: false, name: "" };
}
}}
/>
<FolderConfig folder={selectedFolder.name} />
</div>
{/if}

Expand Down
6 changes: 3 additions & 3 deletions apps/color-buddy/src/controls/FolderConfig.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import colorStore from "../stores/color-store";
import configStore from "../stores/config-store";
import Tooltip from "../components/Tooltip.svelte";
import { buttonStyle } from "../lib/styles";
export let setFolder: (folder?: string) => void;
export let folder: string;
let renaming = false;
function doRename(newFolder: string) {
Expand All @@ -15,7 +15,7 @@
return hit ? { ...pal, folder: newFolder } : pal;
});
colorStore.setPalettes(pals);
setFolder(newFolder);
configStore.setSelectedFolder({ isPreMade: false, name: newFolder });
renaming = false;
}
</script>
Expand All @@ -29,7 +29,7 @@
pal.folder === folder ? { ...pal, folder: "" } : pal
);
colorStore.setPalettes(pals);
setFolder("");
configStore.setSelectedFolder({ isPreMade: false, name: "" });
}}
>
Delete
Expand Down
4 changes: 4 additions & 0 deletions apps/color-buddy/src/stores/config-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface StoreData {
manageBrowsePreviewIdx: number;
route: "examples" | "compare" | "eval" | "manage";
scatterplotMode: "moving" | "putting";
selectedFolder: { isPreMade: boolean; name: string };
showColorBackground: "always show" | "show on drag" | "never show";
showGamutMarkers: boolean;
tempPal: Palette | undefined;
Expand Down Expand Up @@ -52,6 +53,7 @@ const InitialStore: StoreData = {
mainColumnSelectedExample: -1,
manageBrowsePreviewIdx: -1,
route: "examples",
selectedFolder: { isPreMade: false, name: "" },
scatterplotMode: "moving",
showColorBackground: "show on drag",
showGamutMarkers: true,
Expand Down Expand Up @@ -159,6 +161,8 @@ function createStore() {
setTour: (n: StoreData["tour"]) => persist((old) => ({ ...old, tour: n })),
setManageBrowsePreviewIdx: (n: StoreData["manageBrowsePreviewIdx"]) =>
persist((old) => ({ ...old, manageBrowsePreviewIdx: n })),
setSelectedFolder: (n: StoreData["selectedFolder"]) =>
persist((old) => ({ ...old, selectedFolder: n })),
};
}

Expand Down

0 comments on commit 55d6c1c

Please sign in to comment.