Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/roam/src/components/settings/utils/accessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { z } from "zod";
import {
DG_BLOCK_PROP_SETTINGS_PAGE_TITLE,
DISCOURSE_NODE_PAGE_PREFIX,
TOP_LEVEL_BLOCK_PROP_KEYS,
STATIC_TOP_LEVEL_ENTRIES,
FeatureFlagsSchema,
GlobalSettingsSchema,
PersonalSettingsSchema,
Expand Down Expand Up @@ -274,7 +274,7 @@ const setBlockPropBasedSettings = ({

export const getFeatureFlags = (): FeatureFlags => {
const { blockProps } = getBlockPropBasedSettings({
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags],
keys: [STATIC_TOP_LEVEL_ENTRIES.featureFlags.key],
});

return FeatureFlagsSchema.parse(blockProps || {});
Expand All @@ -292,14 +292,14 @@ export const setFeatureFlag = (
const validatedValue = z.boolean().parse(value);

setBlockPropBasedSettings({
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags, key],
keys: [STATIC_TOP_LEVEL_ENTRIES.featureFlags.key, key],
value: validatedValue,
});
};

export const getGlobalSettings = (): GlobalSettings => {
const { blockProps } = getBlockPropBasedSettings({
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.global],
keys: [STATIC_TOP_LEVEL_ENTRIES.global.key],
});

return GlobalSettingsSchema.parse(blockProps || {});
Expand Down Expand Up @@ -337,7 +337,7 @@ export const setGlobalSetting = (keys: string[], value: json): void => {
}

setBlockPropBasedSettings({
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.global, ...keys],
keys: [STATIC_TOP_LEVEL_ENTRIES.global.key, ...keys],
value,
});
};
Expand Down
6 changes: 3 additions & 3 deletions apps/roam/src/components/settings/utils/pullWatchers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type json, normalizeProps } from "~/utils/getBlockProps";
import type { AddPullWatch, PullBlock } from "roamjs-components/types";
import {
TOP_LEVEL_BLOCK_PROP_KEYS,
STATIC_TOP_LEVEL_ENTRIES,
getPersonalSettingsKey,
FeatureFlagsSchema,
GlobalSettingsSchema,
Expand Down Expand Up @@ -165,8 +165,8 @@ export const setupPullWatchOnSettingsPage = (
const watches: Parameters<AddPullWatch>[] = [];

const featureFlagsBlockUid =
blockUids[TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags];
const globalSettingsBlockUid = blockUids[TOP_LEVEL_BLOCK_PROP_KEYS.global];
blockUids[STATIC_TOP_LEVEL_ENTRIES.featureFlags.key];
const globalSettingsBlockUid = blockUids[STATIC_TOP_LEVEL_ENTRIES.global.key];
const personalSettingsKey = getPersonalSettingsKey();
const personalSettingsBlockUid = blockUids[personalSettingsKey];

Expand Down
15 changes: 4 additions & 11 deletions apps/roam/src/components/settings/utils/zodSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,19 @@ export const getPersonalSettingsKey = (): string => {
return cachedPersonalSettingsKey;
};

const staticTopLevelEntries = [
{
propKey: "featureFlags" as const,
export const STATIC_TOP_LEVEL_ENTRIES = {
featureFlags: {
key: "Feature Flags",
schema: FeatureFlagsSchema,
},
{
propKey: "global" as const,
global: {
key: "Global",
schema: GlobalSettingsSchema,
},
];

export const TOP_LEVEL_BLOCK_PROP_KEYS = {
featureFlags: "Feature Flags",
global: "Global",
} as const;

export const getTopLevelBlockPropsConfig = () => [
...staticTopLevelEntries,
...Object.values(STATIC_TOP_LEVEL_ENTRIES),
{ key: getPersonalSettingsKey(), schema: PersonalSettingsSchema },
];

Expand Down
Loading