Skip to content

Commit

Permalink
Setting to Enable Samples (#70)
Browse files Browse the repository at this point in the history
Add a setting to enable samples.
  • Loading branch information
wandyezj authored Sep 18, 2024
1 parent 3b9f99f commit 0e1c64b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
16 changes: 11 additions & 5 deletions src/components/ButtonOpenMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -89,9 +90,14 @@ export function ButtonOpenMenu({
) : (
<></>
)}
<MenuItem icon={<BookDefault28Regular />} onClick={() => setIsOpenDrawerSamples(true)}>
Sample
</MenuItem>

{enableSamples() ? (
<MenuItem icon={<BookDefault28Regular />} onClick={() => setIsOpenDrawerSamples(true)}>
Sample
</MenuItem>
) : (
<></>
)}

<MenuDivider />

Expand Down
6 changes: 3 additions & 3 deletions src/components/PageEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -145,7 +145,7 @@ export function PageEdit({ initialSnip }: { initialSnip: SnipWithSource }) {
<TooltipButton tip="Delete" icon={<DeleteRegular />} onClick={buttonDeleteSnip} />

{/** Label */}
{getSourceBadge(snip)}
{enableEmbed() ? getSourceBadge(snip) : <></>}

{/** Settings */}
<TooltipButton tip="Settings" icon={<SettingsRegular />} onClick={buttonSettings} />
Expand Down
11 changes: 10 additions & 1 deletion src/core/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSetting } from "./setting";
import { getSetting } from "../setting";

/**
* Enable the import button on the edit page
Expand Down
4 changes: 2 additions & 2 deletions src/core/enableEmbed.ts → src/core/settings/enableEmbed.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSetting } from "./setting";
import { getSetting } from "../setting";

/**
* Enable creating a local copy of a gist.
Expand Down
9 changes: 9 additions & 0 deletions src/core/settings/enableSamples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getSetting } from "../setting";

/**
* Enable open menu samples button.
*/
export function enableSamples(): boolean {
const enable = getSetting("enableSamples");
return enable;
}

0 comments on commit 0e1c64b

Please sign in to comment.