diff --git a/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/__tests__/store.test.ts b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/__tests__/store.test.ts index c657904b..f5c8579a 100644 --- a/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/__tests__/store.test.ts +++ b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/__tests__/store.test.ts @@ -1,5 +1,5 @@ -import { defaultSettings, mergeState } from '../store' -import { MAX_OPERATIONS } from '../constants' +import { mergeState } from '../store' +import { defaultSettings, MAX_OPERATIONS } from '../constants' describe('ToolbarRandomizeMenu/store/mergeState', () => { const defaultPayload = { diff --git a/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/constants.ts b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/constants.ts index 914f0223..ea88516f 100644 --- a/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/constants.ts +++ b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/constants.ts @@ -1 +1,46 @@ +import type { Setting } from './types' + export const MAX_OPERATIONS = 6 + +export const defaultSettings: Setting[] = [ + { + label: 'flip', + checked: true + }, + { + label: 'flop', + checked: false + }, + { + label: 'grayscale', + checked: false + }, + { + label: 'negate', + checked: false + }, + { + label: 'blur', + checked: true + }, + { + label: 'rotate', + checked: true + }, + { + label: 'modulate', + checked: false + }, + { + label: 'gamma', + checked: true + }, + { + label: 'tint', + checked: false + }, + { + label: 'normalise', + checked: false + } +] as const diff --git a/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/store.ts b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/store.ts index a912038a..73538fc6 100644 --- a/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/store.ts +++ b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/store.ts @@ -1,8 +1,9 @@ import { create } from 'zustand' import { persist } from 'zustand/middleware' -import { array, boolean, object, string } from 'yup' -import { MAX_OPERATIONS } from './constants' +import { defaultSettings, MAX_OPERATIONS } from './constants' +import { SITE_TITLE } from '@site/config' +import { isSettingsValid } from './utility' import type { Label, Setting } from './types' /* eslint no-unused-vars: 0 */ @@ -16,49 +17,6 @@ interface Store { toggleSettingChecked: (label: Label) => void } -export const defaultSettings: Setting[] = [ - { - label: 'flip', - checked: true - }, - { - label: 'flop', - checked: false - }, - { - label: 'grayscale', - checked: false - }, - { - label: 'negate', - checked: false - }, - { - label: 'blur', - checked: true - }, - { - label: 'rotate', - checked: true - }, - { - label: 'modulate', - checked: false - }, - { - label: 'gamma', - checked: true - }, - { - label: 'tint', - checked: false - }, - { - label: 'normalise', - checked: false - } -] as const - export const useRandomizeStore = create( persist( (set, get) => ({ @@ -102,7 +60,7 @@ export const useRandomizeStore = create( }) }), { - name: 'scissors-randomize-settings', + name: `${SITE_TITLE.toLowerCase()}-randomize-settings`, merge: mergeState } ) @@ -143,16 +101,3 @@ export function mergeState(persistedState: unknown, currentState: State): settings: defaultSettings } } - -export const isSettingsValid = (settings: unknown): boolean => { - const optionSchema = object({ - label: string() - .oneOf(defaultSettings.map(s => s.label)) - .defined() - .required(), - checked: boolean().defined().required() - }) - const settingsSchema = array(optionSchema).length(defaultSettings.length).defined().required() - - return settingsSchema.isValidSync(settings) -} diff --git a/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/utility.ts b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/utility.ts new file mode 100644 index 00000000..3390d12c --- /dev/null +++ b/apps/frontend/src/widgets/SettingsPanel/Toolbar/ToolbarRandomizeMenu/utility.ts @@ -0,0 +1,16 @@ +import { array, boolean, object, string } from 'yup' + +import { defaultSettings } from './constants' + +export const isSettingsValid = (settings: unknown): boolean => { + const optionSchema = object({ + label: string() + .oneOf(defaultSettings.map(s => s.label)) + .defined() + .required(), + checked: boolean().defined().required() + }) + const settingsSchema = array(optionSchema).length(defaultSettings.length).defined().required() + + return settingsSchema.isValidSync(settings) +}