-
+
+
@@ -36,6 +45,7 @@
import { ref, computed, watch, onMounted } from 'vue'
import { accentLightItem, accentDarkItem } from '@/utils/storage'
import { hexToHSL } from '@/composables/useColorConversion'
+import ColorPicker from '@/components/Colors/ColorPicker.vue'
import ButtonPrimary from '@/components/ButtonPrimary.vue'
import CardToggle from '@/components/Cards/Toggle.vue'
import IconPipe from '@/components/Icons/Pipe.vue'
@@ -51,14 +61,32 @@ const toggleAccentUserBubble = useToggleStorage(accentUserBubbleItem, 'dsx-toggl
const lightHex = ref('')
const darkHex = ref('')
+// Centralized color picker configuration
+const colorPickers = [
+ {
+ id: 'lightColor',
+ modelValue: lightHex,
+ label: 'Accent',
+ subLabel: 'Light',
+ handler: onLightChange,
+ },
+ {
+ id: 'darkColor',
+ modelValue: darkHex,
+ label: 'Accent',
+ subLabel: 'Dark',
+ handler: onDarkChange,
+ },
+]
+
// Watch for changes in storage and update the reactive variables
-accentLightItem.watch((newVal) => {
+const stopLightWatcher = accentLightItem.watch((newVal) => {
if (newVal !== lightHex.value) {
lightHex.value = newVal
}
})
-accentDarkItem.watch((newVal) => {
+const stopDarkWatcher = accentDarkItem.watch((newVal) => {
if (newVal !== darkHex.value) {
darkHex.value = newVal
}
@@ -97,13 +125,20 @@ onMounted(async () => {
}
// Load stored accent colors (or fallback to defaults)
- const storedLight = await accentLightItem.getValue()
- const storedDark = await accentDarkItem.getValue()
- lightHex.value = storedLight || accentLightItem.fallback
- darkHex.value = storedDark || accentDarkItem.fallback
-
- // Set the initial CSS content in the style tag
- styleTag.innerHTML = cssString.value
+ try {
+ const [storedLight, storedDark] = await Promise.all([accentLightItem.getValue(), accentDarkItem.getValue()])
+
+ lightHex.value = storedLight || accentLightItem.fallback
+ darkHex.value = storedDark || accentDarkItem.fallback
+
+ // Set the initial CSS content in the style tag
+ styleTag.innerHTML = cssString.value
+ } catch (error) {
+ console.error('Failed to load accent colors:', error)
+ // Set fallback values
+ lightHex.value = accentLightItem.fallback
+ darkHex.value = accentDarkItem.fallback
+ }
})
// Update the injected CSS whenever the computed cssString changes
@@ -131,73 +166,10 @@ function resetColors() {
onLightChange()
onDarkChange()
}
-
-
+// Clean up watchers when component is unmounted
+onUnmounted(() => {
+ stopLightWatcher()
+ stopDarkWatcher()
+})
+
From e978c3cab1bc7b0a34ca0b10d2b5a4950001a417 Mon Sep 17 00:00:00 2001
From: itsmartashub <44645238+itsmartashub@users.noreply.github.com>
Date: Tue, 9 Sep 2025 21:33:47 +0200
Subject: [PATCH 4/4] refactor(custom/colors): Wrap accent color logic into
separate composable
---
components/Custom/Colors/ColorPicker.vue | 24 +---
components/Custom/Colors/Index.vue | 142 ++++-------------------
composables/useAccentColors.js | 61 ++++++++++
utils/storage.js | 4 +-
4 files changed, 89 insertions(+), 142 deletions(-)
create mode 100644 composables/useAccentColors.js
diff --git a/components/Custom/Colors/ColorPicker.vue b/components/Custom/Colors/ColorPicker.vue
index d2828b4..7a7f10c 100644
--- a/components/Custom/Colors/ColorPicker.vue
+++ b/components/Custom/Colors/ColorPicker.vue
@@ -7,10 +7,10 @@
:value="modelValue"
@input="$emit('update:modelValue', $event.target.value)"
@change="$emit('change', $event)"
- :aria-label="`Select ${label} ${subLabel} color`"
+ :aria-label="`Select accent ${mode} color`"
/>
- {{ label }} {{ subLabel }}
+ Accent {{ mode }}
@@ -18,24 +18,10 @@
diff --git a/components/Custom/Colors/Index.vue b/components/Custom/Colors/Index.vue
index 904883f..fae02e4 100644
--- a/components/Custom/Colors/Index.vue
+++ b/components/Custom/Colors/Index.vue
@@ -1,25 +1,12 @@