Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mutdmour committed Nov 2, 2023
1 parent 25fba3f commit c9e4f7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/editor-ui/src/stores/ui.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
DEBUG_PAYWALL_MODAL_KEY,
N8N_PRICING_PAGE_URL,
WORKFLOW_HISTORY_VERSION_RESTORE,
LOCAL_STORAGE_THEME,
} from '@/constants';
import type {
CloudUpdateLinkSourceType,
Expand Down Expand Up @@ -67,15 +66,14 @@ import type { BannerName } from 'n8n-workflow';
import {
addThemeToBody,
getPreferredTheme,
getQueryParam,
getThemeOverride,
isValidTheme,
updateTheme,
} from './ui.utils';

let savedTheme: ThemeOption = 'system';
try {
// query param allows overriding theme for demo view in preview iframe without flickering
const value = getQueryParam('theme') || localStorage.getItem(LOCAL_STORAGE_THEME);
const value = getThemeOverride();
if (isValidTheme(value)) {
savedTheme = value;
addThemeToBody(value);
Expand Down
7 changes: 6 additions & 1 deletion packages/editor-ui/src/stores/ui.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export function isValidTheme(theme: string | null): theme is AppliedThemeOption
return !!theme && ['light', 'dark'].includes(theme);
}

export function getQueryParam(paramName: string): string | null {
// query param allows overriding theme for demo view in preview iframe without flickering
export function getThemeOverride() {
return getQueryParam('theme') || localStorage.getItem(LOCAL_STORAGE_THEME);
}

function getQueryParam(paramName: string): string | null {
return new URLSearchParams(window.location.search).get(paramName);
}

Expand Down

0 comments on commit c9e4f7f

Please sign in to comment.