summaryrefslogtreecommitdiff
path: root/packages/client/src
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2022-03-09 22:18:14 +0900
committerGitHub <noreply@github.com>2022-03-09 22:18:14 +0900
commita07037affc38d9f753682dacc4d941838648c74d (patch)
treeb82de02d43e0489711a727cef015bd76f0ad09a9 /packages/client/src
parentUpdate CHANGELOG.md (diff)
downloadmisskey-a07037affc38d9f753682dacc4d941838648c74d.tar.gz
misskey-a07037affc38d9f753682dacc4d941838648c74d.tar.bz2
misskey-a07037affc38d9f753682dacc4d941838648c74d.zip
テーマ選択から重複要素を排除するように (#8385)
Diffstat (limited to 'packages/client/src')
-rw-r--r--packages/client/src/pages/settings/theme.vue4
-rw-r--r--packages/client/src/scripts/array.ts11
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<T>(xs: T[]): T[] {
return [...new Set(xs)];
}
+export function uniqueBy<TValue, TKey>(values: TValue[], keySelector: (value: TValue) => TKey): TValue[] {
+ const map = new Map<TKey, TValue>();
+
+ 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);
}