From a07037affc38d9f753682dacc4d941838648c74d Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Wed, 9 Mar 2022 22:18:14 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=83=BC=E3=83=9E=E9=81=B8=E6=8A=9E?= =?UTF-8?q?=E3=81=8B=E3=82=89=E9=87=8D=E8=A4=87=E8=A6=81=E7=B4=A0=E3=82=92?= =?UTF-8?q?=E6=8E=92=E9=99=A4=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20(#8385)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/pages/settings/theme.vue | 4 ++-- packages/client/src/scripts/array.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/client/src/pages/settings/theme.vue b/packages/client/src/pages/settings/theme.vue index 92a6fee7a4..d134a092b6 100644 --- a/packages/client/src/pages/settings/theme.vue +++ b/packages/client/src/pages/settings/theme.vue @@ -101,7 +101,7 @@ import { ColdDeviceStorage } from '@/store'; import { i18n } from '@/i18n'; import { defaultStore } from '@/store'; import { instance } from '@/instance'; -import { concat } from '@/scripts/array'; +import { concat, uniqueBy } from '@/scripts/array'; import { fetchThemes, getThemes } from '@/theme-store'; import * as symbols from '@/symbols'; @@ -128,7 +128,7 @@ export default defineComponent({ const instanceThemes = []; if (instance.defaultLightTheme != null) instanceThemes.push(JSON5.parse(instance.defaultLightTheme)); if (instance.defaultDarkTheme != null) instanceThemes.push(JSON5.parse(instance.defaultDarkTheme)); - const themes = computed(() => instanceThemes.concat(builtinThemes.concat(installedThemes.value))); + const themes = computed(() => uniqueBy(instanceThemes.concat(builtinThemes.concat(installedThemes.value)), theme => theme.id)); const darkThemes = computed(() => themes.value.filter(t => t.base === 'dark' || t.kind === 'dark')); const lightThemes = computed(() => themes.value.filter(t => t.base === 'light' || t.kind === 'light')); const darkTheme = ColdDeviceStorage.ref('darkTheme'); diff --git a/packages/client/src/scripts/array.ts b/packages/client/src/scripts/array.ts index d63f0475d0..29d027de14 100644 --- a/packages/client/src/scripts/array.ts +++ b/packages/client/src/scripts/array.ts @@ -52,6 +52,17 @@ export function unique(xs: T[]): T[] { return [...new Set(xs)]; } +export function uniqueBy(values: TValue[], keySelector: (value: TValue) => TKey): TValue[] { + const map = new Map(); + + for (const value of values) { + const key = keySelector(value); + if (!map.has(key)) map.set(key, value); + } + + return [...map.values()]; +} + export function sum(xs: number[]): number { return xs.reduce((a, b) => a + b, 0); }