From 2f1b21263a66d54f6727baf7b7360f658f4da28a Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 3 Sep 2022 18:13:09 +0300 Subject: [PATCH 1/3] feat: wrapper component for Chrome -emits input event on color change Signed-off-by: mertmit --- .../components/general/ChromeWrapper.vue | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 packages/nc-gui-v2/components/general/ChromeWrapper.vue diff --git a/packages/nc-gui-v2/components/general/ChromeWrapper.vue b/packages/nc-gui-v2/components/general/ChromeWrapper.vue new file mode 100644 index 0000000000..43028707a5 --- /dev/null +++ b/packages/nc-gui-v2/components/general/ChromeWrapper.vue @@ -0,0 +1,30 @@ + + + + + From 5ae2882334ad9b34f53a6b30e5a4438e26eed6e3 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 3 Sep 2022 18:13:35 +0300 Subject: [PATCH 2/3] fix: use events instead of watch for color handling Signed-off-by: mertmit --- .../components/general/ColorPicker.vue | 22 +++--- packages/nc-gui-v2/composables/useProject.ts | 16 +++-- .../pages/[projectType]/[projectId]/index.vue | 70 +++++++++---------- .../nc-gui-v2/pages/index/index/index.vue | 67 ++++++------------ 4 files changed, 77 insertions(+), 98 deletions(-) diff --git a/packages/nc-gui-v2/components/general/ColorPicker.vue b/packages/nc-gui-v2/components/general/ColorPicker.vue index e5bb3bdc1d..5302c398ab 100644 --- a/packages/nc-gui-v2/components/general/ColorPicker.vue +++ b/packages/nc-gui-v2/components/general/ColorPicker.vue @@ -1,5 +1,4 @@ @@ -50,11 +50,11 @@ watch(picked, (n, _o) => { v-for="(color, i) of colors.slice((colId - 1) * rowSize, colId * rowSize)" :key="`color-${colId}-${i}`" class="color-selector" - :class="compare(typeof picked === 'string' ? picked : picked.hex8, color) ? 'selected' : ''" + :class="compare(picked, color) ? 'selected' : ''" :style="{ 'background-color': `${color}` }" @click="selectColor(color)" > - {{ compare(typeof picked === 'string' ? picked : picked.hex8, color) ? '✓' : '' }} + {{ compare(picked, color) ? '✓' : '' }} @@ -64,7 +64,7 @@ watch(picked, (n, _o) => { Pick Color
- +
diff --git a/packages/nc-gui-v2/composables/useProject.ts b/packages/nc-gui-v2/composables/useProject.ts index da9f6d1b92..57bcbb0302 100644 --- a/packages/nc-gui-v2/composables/useProject.ts +++ b/packages/nc-gui-v2/composables/useProject.ts @@ -10,7 +10,7 @@ const [setup, use] = useInjectionState((_projectId?: MaybeRef) => { const { $api } = useNuxtApp() const route = useRoute() const { includeM2M } = useGlobal() - const { setTheme } = useTheme() + const { setTheme, theme } = useTheme() const projectId = computed(() => (_projectId ? unref(_projectId) : (route.params.projectId as string))) const project = ref({}) @@ -99,15 +99,21 @@ const [setup, use] = useInjectionState((_projectId?: MaybeRef) => { } } - async function saveTheme(theme: Partial) { + async function saveTheme(_theme: Partial) { + const fullTheme = { + primaryColor: theme.value.primaryColor, + accentColor: theme.value.accentColor, + ..._theme, + } + await updateProject({ - color: theme.primaryColor, + color: fullTheme.primaryColor, meta: { ...projectMeta.value, - theme, + theme: fullTheme, }, }) - setTheme(theme) + setTheme(fullTheme) } watch( diff --git a/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue b/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue index d6954d9c05..45120dfbd5 100644 --- a/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue +++ b/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue @@ -1,6 +1,5 @@ From da3127fc44fee09eaa0d9d930e5abd4e643824eb Mon Sep 17 00:00:00 2001 From: mertmit Date: Sun, 4 Sep 2022 00:31:15 +0300 Subject: [PATCH 3/3] fix: project list color badge Signed-off-by: mertmit --- .../pages/[projectType]/[projectId]/index.vue | 1 - .../nc-gui-v2/pages/index/index/index.vue | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue b/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue index 45120dfbd5..f8714b8781 100644 --- a/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue +++ b/packages/nc-gui-v2/pages/[projectType]/[projectId]/index.vue @@ -17,7 +17,6 @@ import { useProject, useRoute, useTabs, - useTheme, useUIPermission, } from '#imports' import { TabType } from '~/composables' diff --git a/packages/nc-gui-v2/pages/index/index/index.vue b/packages/nc-gui-v2/pages/index/index/index.vue index f1fab12607..3ee94d20bd 100644 --- a/packages/nc-gui-v2/pages/index/index/index.vue +++ b/packages/nc-gui-v2/pages/index/index/index.vue @@ -83,8 +83,25 @@ const handleProjectColor = async (projectId: string, color: string) => { }, }), }) + // Update local project + const localProject = projects.value?.find((p) => p.id === projectId) + if (localProject) { + localProject.color = color + localProject.meta = JSON.stringify({ + ...meta, + theme: { + primaryColor: color, + accentColor: complement.toHex8String(), + }, + }) + } } } + +const getProjectPrimary = (project: ProjectType) => { + const meta = project?.meta && typeof project.meta === 'string' ? JSON.parse(project.meta) : project.meta || {} + return meta?.theme?.primaryColor || themeV2Colors['royal-blue'].DEFAULT +}