From 0e1c64b6fb508bc4e6de983a518504b519481701 Mon Sep 17 00:00:00 2001 From: wandyezj Date: Wed, 18 Sep 2024 14:28:34 -0700 Subject: [PATCH] Setting to Enable Samples (#70) Add a setting to enable samples. --- src/components/ButtonOpenMenu.tsx | 16 +++++++++++----- src/components/PageEdit.tsx | 6 +++--- src/core/setting.ts | 11 ++++++++++- src/core/{ => settings}/enableEditImport.ts | 2 +- src/core/{ => settings}/enableEmbed.ts | 4 ++-- src/core/{ => settings}/enableGists.ts | 2 +- src/core/settings/enableSamples.ts | 9 +++++++++ 7 files changed, 37 insertions(+), 13 deletions(-) rename src/core/{ => settings}/enableEditImport.ts (80%) rename src/core/{ => settings}/enableEmbed.ts (78%) rename src/core/{ => settings}/enableGists.ts (83%) create mode 100644 src/core/settings/enableSamples.ts diff --git a/src/components/ButtonOpenMenu.tsx b/src/components/ButtonOpenMenu.tsx index 3f92bfb..9cb5e11 100644 --- a/src/components/ButtonOpenMenu.tsx +++ b/src/components/ButtonOpenMenu.tsx @@ -24,11 +24,12 @@ import { DrawerSnips } from "./DrawerSnips"; import { getId, idEditButtonOpen, idEditButtonOpenSnip } from "./id"; import { DrawerSamples } from "./DrawerSamples"; import { DrawerEmbed } from "./DrawerEmbed"; -import { enableEmbed } from "../core/enableEmbed"; +import { enableEmbed } from "../core/settings/enableEmbed"; import { newDefaultSnip } from "../core/newDefaultSnip"; import { LogTag, log } from "../core/log"; import { DrawerGists } from "./DrawerGists"; -import { enableGists } from "../core/enableGists"; +import { enableGists } from "../core/settings/enableGists"; +import { enableSamples } from "../core/settings/enableSamples"; export function ButtonOpenMenu({ openSnip, @@ -89,9 +90,14 @@ export function ButtonOpenMenu({ ) : ( <> )} - } onClick={() => setIsOpenDrawerSamples(true)}> - Sample - + + {enableSamples() ? ( + } onClick={() => setIsOpenDrawerSamples(true)}> + Sample + + ) : ( + <> + )} diff --git a/src/components/PageEdit.tsx b/src/components/PageEdit.tsx index bc39666..1a24032 100644 --- a/src/components/PageEdit.tsx +++ b/src/components/PageEdit.tsx @@ -25,10 +25,10 @@ import { copyTextToClipboard } from "../core/copyTextToClipboard"; import { LogTag, log } from "../core/log"; import { ButtonEmbedCopy } from "./ButtonEmbedCopy"; import { ButtonOpenMenu } from "./ButtonOpenMenu"; -import { enableEmbed } from "../core/enableEmbed"; +import { enableEmbed } from "../core/settings/enableEmbed"; import { idEditButtonCopyToClipboard } from "./id"; import { getSetting } from "../core/setting"; -import { enableEditImport } from "../core/enableEditImport"; +import { enableEditImport } from "../core/settings/enableEditImport"; function buttonRun() { window.location.href = "./run.html#back"; @@ -145,7 +145,7 @@ export function PageEdit({ initialSnip }: { initialSnip: SnipWithSource }) { } onClick={buttonDeleteSnip} /> {/** Label */} - {getSourceBadge(snip)} + {enableEmbed() ? getSourceBadge(snip) : <>} {/** Settings */} } onClick={buttonSettings} /> diff --git a/src/core/setting.ts b/src/core/setting.ts index 8492fc1..4de434d 100644 --- a/src/core/setting.ts +++ b/src/core/setting.ts @@ -17,13 +17,22 @@ export const settingsMetadata = { defaultValue: "", } as SettingString, + /** + * Show the samples in the open menu. + */ + enableSamples: { + name: "Enable Samples", + type: "boolean", + defaultValue: false, + } as SettingBoolean, + /** * Show the embed button on the edit page and in the open menu. */ enableEmbed: { name: "Enable Embed", type: "boolean", - defaultValue: true, + defaultValue: false, } as SettingBoolean, /** diff --git a/src/core/enableEditImport.ts b/src/core/settings/enableEditImport.ts similarity index 80% rename from src/core/enableEditImport.ts rename to src/core/settings/enableEditImport.ts index 8959769..bf37db7 100644 --- a/src/core/enableEditImport.ts +++ b/src/core/settings/enableEditImport.ts @@ -1,4 +1,4 @@ -import { getSetting } from "./setting"; +import { getSetting } from "../setting"; /** * Enable the import button on the edit page diff --git a/src/core/enableEmbed.ts b/src/core/settings/enableEmbed.ts similarity index 78% rename from src/core/enableEmbed.ts rename to src/core/settings/enableEmbed.ts index 8695708..6df604e 100644 --- a/src/core/enableEmbed.ts +++ b/src/core/settings/enableEmbed.ts @@ -1,5 +1,5 @@ -import { getHost } from "./globals"; -import { getSetting } from "./setting"; +import { getHost } from "../globals"; +import { getSetting } from "../setting"; export function enableEmbed(): boolean { const host = getHost(); diff --git a/src/core/enableGists.ts b/src/core/settings/enableGists.ts similarity index 83% rename from src/core/enableGists.ts rename to src/core/settings/enableGists.ts index a78cccd..251e684 100644 --- a/src/core/enableGists.ts +++ b/src/core/settings/enableGists.ts @@ -1,4 +1,4 @@ -import { getSetting } from "./setting"; +import { getSetting } from "../setting"; /** * Enable creating a local copy of a gist. diff --git a/src/core/settings/enableSamples.ts b/src/core/settings/enableSamples.ts new file mode 100644 index 0000000..fa5d736 --- /dev/null +++ b/src/core/settings/enableSamples.ts @@ -0,0 +1,9 @@ +import { getSetting } from "../setting"; + +/** + * Enable open menu samples button. + */ +export function enableSamples(): boolean { + const enable = getSetting("enableSamples"); + return enable; +}