Skip to content

Commit

Permalink
Turn on persistance in examples/lints (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew authored Oct 21, 2024
1 parent 617099b commit 60df5ff
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
20 changes: 16 additions & 4 deletions apps/color-buddy/src/example/NewExampleModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
$: {
if (typeof externalModalState === "number") {
const example = $exampleStore.examples[externalModalState] as any;
if (example.svg) {
let example = $exampleStore.examples[externalModalState] as any;
if (!example) {
example = $exampleStore.examples[0];
}
console.log(example);
if (example && example.svg) {
value = example.svg;
modalState = "input-svg";
}
if (example.vega) {
if (example && example.vega) {
value = example.vega;
modalState = "input-vega";
}
Expand Down Expand Up @@ -270,7 +274,15 @@
<button
class={buttonStyle}
on:click={() => {
const example = { vega: value, name: "Custom Example", size: 300 };
let example = { vega: value, name: "Custom Example", size: 300 };
if (typeof externalModalState === "number") {
example = {
...example,
...$exampleStore.examples[externalModalState],
vega: value,
};
}
console.log(example);
if (typeof externalModalState === "number") {
exampleStore.updateExample(example, externalModalState);
} else {
Expand Down
36 changes: 19 additions & 17 deletions apps/color-buddy/src/example/PreviewSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import configStore from "../stores/config-store";
import Tooltip from "../components/Tooltip.svelte";
export let exampleName: string;
$: SVGs = $exampleStore.examples.filter((x) => (x as any).svg);
$: vis = $exampleStore.examples.filter((x) => (x as any).vega);
$: examples = $exampleStore.examples as any[];
</script>

<Tooltip targetBody={false} bg="bg-white" top={0} positionAlongRightEdge={true}>
Expand All @@ -21,24 +20,27 @@
Discs
</button>
<div class="w-full border border-stone-300 my-2" />
{#each SVGs as example, idx}
<button
class={simpleTooltipRowStyle}
on:click={() => configStore.setManageBrowsePreviewIdx(idx)}
>
{example.name}
</button>
{#each examples as example, idx}
{#if example.svg}
<button
class={simpleTooltipRowStyle}
on:click={() => configStore.setManageBrowsePreviewIdx(idx)}
>
{example.name}
</button>
{/if}
{/each}
<div class="w-full border border-stone-300 my-2" />
{#each vis as example, idx}
<button
class={simpleTooltipRowStyle}
on:click={() => configStore.setManageBrowsePreviewIdx(idx)}
>
{example.name}
</button>
{#each examples as example, idx}
{#if example.vega}
<button
class={simpleTooltipRowStyle}
on:click={() => configStore.setManageBrowsePreviewIdx(idx)}
>
{example.name}
</button>
{/if}
{/each}
<div class="w-full border border-stone-300 my-2" />
</div>
<button
slot="target"
Expand Down
7 changes: 5 additions & 2 deletions apps/color-buddy/src/stores/example-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ function createStore() {
return acc;
}, {} as any);
if (x) {
const examples = x.examples.filter((x: any) => !preBuiltMap[x.name]);
const newStore = { examples: [...prebuiltExamples, ...examples] };
// if there are prebuilt examples, add them to the store
x.examples.forEach((x: any) => {
preBuiltMap[x.name] = x;
});
const newStore = { examples: Object.values(preBuiltMap) };
set(newStore as StoreData);
} else {
set({ ...InitialStore, examples: prebuiltExamples });
Expand Down
6 changes: 3 additions & 3 deletions apps/color-buddy/src/stores/lint-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ function createStore() {
let lints = (storeBase.lints || []) as LintProgram[];
// force-ably set lints to defaults
// TODO turn off for release...
lints = lints.map(
(x: LintProgram) => builtInIndex[x.id] || x
) as LintProgram[];
// lints = lints.map(
// (x: LintProgram) => builtInIndex[x.id] || x
// ) as LintProgram[];
const missingBuiltIns = PREBUILT_LINTS.filter(
(x) => !lints.find((y) => y.id === x.id)
).map((x) => ({
Expand Down

0 comments on commit 60df5ff

Please sign in to comment.