π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: add theme query parameter support for shared views
Pranav C688c7ad3ba6a
diff --git a/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue b/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vueindex 04fb763a59..64735e47fc 100644--- a/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue+++ b/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue@@ -201,6 +201,58 @@ const surveyMode = computed({},})+const themeOptions = [+ { label: 'Light', value: 'light' },+ { label: 'Dark', value: 'dark' },+]++const themeSetLocal = ref(false)++const themeSet = computed(() => {+ return !!activeView.value?.meta?.defaultTheme || themeSetLocal.value+})++const toggleThemeSet = async () => {+ themeSetLocal.value = !themeSet.value+ if (!activeView.value) return+ if (isUpdating.value.language) return++ isUpdating.value.language = true+ try {+ if (!themeSetLocal.value) {+ activeView.value = { ...(activeView.value as any), meta: { ...activeView.value.meta, defaultTheme: null } }+ } else {+ activeView.value = { ...(activeView.value as any), meta: { ...activeView.value.meta, defaultTheme: 'light' } }+ }++ await updateSharedView()+ } finally {+ isUpdating.value.language = false+ }+}++const defaultTheme = computed({+ get: () => {+ if (!activeView.value?.meta) return null++ if (typeof activeView.value?.meta === 'string') {+ activeView.value.meta = JSON.parse(activeView.value.meta)+ }++ return (activeView.value?.meta as any)?.defaultTheme+ },+ set: (theme) => {+ if (!activeView.value?.meta) return++ if (typeof activeView.value?.meta === 'string') {+ activeView.value.meta = JSON.parse(activeView.value.meta)+ }++ activeView.value.meta = { ...(activeView.value.meta as any), defaultTheme: theme }+ updateSharedView()+ },+})+const formPreFill = computed({get: () => ({preFillEnabled: parseProp(activeView.value?.meta)?.preFillEnabled ?? false,@@ -260,9 +312,20 @@ function sharedViewUrl(withPrefill = true) {viewType = 'view'}- return `${encodeURI(`${dashboardUrl.value}#/nc/${viewType}/${activeView.value.uuid}${surveyMode.value ? '/survey' : ''}`)}${- withPrefill && preFillFormSearchParams.value ? `?${preFillFormSearchParams.value}` : ''- }`+ const baseUrl = `${dashboardUrl.value}#/nc/${viewType}/${activeView.value.uuid}${surveyMode.value ? '/survey' : ''}`+ const queryParams = []++ // Add prefill parameters+ if (withPrefill && preFillFormSearchParams.value) {+ queryParams.push(preFillFormSearchParams.value)+ }++ // Add theme parameter if defaultTheme is set+ if (defaultTheme.value) {+ queryParams.push(`theme=${defaultTheme.value}`)+ }++ return `${encodeURI(baseUrl)}${queryParams.length > 0 ? `?${queryParams.join('&')}` : ''}`}const toggleViewShare = async () => {@@ -524,6 +587,41 @@ const copyCustomUrl = async (custUrl = '') => {</div></div>+ <div+ v-if="activeView?.type === ViewTypes.FORM"+ class="flex flex-col justify-between gap-y-3 mt-1 py-2 px-3 bg-nc-bg-gray-extralight rounded-md"+ >+ <div class="flex flex-row items-center justify-between">+ <div class="text-nc-content-gray-extreme flex items-center space-x-1">+ <div>Default Theme</div>+ <NcTooltip class="flex items-center">+ <template #title>Set the default theme (light or dark) for this shared form</template>+ <GeneralIcon icon="info" class="flex-none text-gray-400 cursor-pointer"></GeneralIcon>+ </NcTooltip>+ </div>+ <a-switch+ v-e="['c:share:view:theme:toggle']"+ :checked="themeSet"+ :loading="isUpdating.language"+ data-testid="nc-modal-share-view__themeToggle"+ size="small"+ :disabled="isReadOnly"+ @click="toggleThemeSet"+ />+ </div>+ <Transition mode="out-in" name="layout">+ <div v-if="themeSet" class="flex gap-2 mt-2 w-2/3">+ <NcSelect+ v-model:value="defaultTheme"+ data-testid="nc-modal-share-view__themeSelect"+ :options="themeOptions"+ class="w-full nc-select-shadow"+ :disabled="isReadOnly"+ />+ </div>+ </Transition>+ </div>+<divv-if="activeView?.type === ViewTypes.FORM"class="nc-pre-filled-mode-wrapper flex flex-col justify-between gap-y-3 mt-1 py-2 px-3 bg-nc-bg-gray-extralight rounded-md"diff --git a/packages/nc-gui/composables/useTheme.ts b/packages/nc-gui/composables/useTheme.tsindex 990e9630b8..fdfbd0c26b 100644--- a/packages/nc-gui/composables/useTheme.ts+++ b/packages/nc-gui/composables/useTheme.ts@@ -1,4 +1,5 @@import { barcodeCache } from '../components/smartsheet/grid/canvas/utils/canvas'+import { isSharedViewRoute } from '~/utils/routeUtils'export type ThemeMode = 'system' | 'light' | 'dark'@@ -235,6 +236,14 @@ export const useTheme = createSharedComposable(() => {selectedTheme.value = saved}+ // Check for theme query parameter on shared views (without persisting to localStorage)+ if (isSharedViewRoute(route.value) && route.value.query?.theme) {+ const queryTheme = route.value.query.theme as string+ if (['light', 'dark'].includes(queryTheme)) {+ selectedTheme.value = queryTheme as 'light' | 'dark'+ }+ }+const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')systemPreference.value = mediaQuery.matches ? 'dark' : 'light'diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex 28fa190500..11ed159753 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -186,6 +186,7 @@ interface SharedViewMeta extends Record<string, any> {transitionDuration?: number // in mswithTheme?: booleantheme?: Partial<ThemeConfig>+ defaultTheme?: 'light' | 'dark'allowCSVDownload?: booleanrtl?: booleanpreFillEnabled?: boolean