fix(favorites): store favorites regardless of languages (#1202)

Fix #1110
This commit is contained in:
sharevb 2024-10-22 10:21:29 +02:00 committed by GitHub
parent f962c416a3
commit 7ca5933178
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,6 +14,7 @@ export const useToolStore = defineStore('tools', () => {
return ({ return ({
...tool, ...tool,
path: tool.path,
name: t(`tools.${toolI18nKey}.title`, tool.name), name: t(`tools.${toolI18nKey}.title`, tool.name),
description: t(`tools.${toolI18nKey}.description`, tool.description), description: t(`tools.${toolI18nKey}.description`, tool.description),
category: t(`tools.categories.${tool.category.toLowerCase()}`, tool.category), category: t(`tools.categories.${tool.category.toLowerCase()}`, tool.category),
@ -23,8 +24,9 @@ export const useToolStore = defineStore('tools', () => {
const toolsByCategory = computed<ToolCategory[]>(() => { const toolsByCategory = computed<ToolCategory[]>(() => {
return _.chain(tools.value) return _.chain(tools.value)
.groupBy('category') .groupBy('category')
.map((components, name) => ({ .map((components, name, path) => ({
name, name,
path,
components, components,
})) }))
.value(); .value();
@ -32,7 +34,7 @@ export const useToolStore = defineStore('tools', () => {
const favoriteTools = computed(() => { const favoriteTools = computed(() => {
return favoriteToolsName.value return favoriteToolsName.value
.map(favoriteName => tools.value.find(({ name }) => name === favoriteName)) .map(favoriteName => tools.value.find(({ name, path }) => name === favoriteName || path === favoriteName))
.filter(Boolean) as ToolWithCategory[]; // cast because .filter(Boolean) does not remove undefined from type .filter(Boolean) as ToolWithCategory[]; // cast because .filter(Boolean) does not remove undefined from type
}); });
@ -43,15 +45,16 @@ export const useToolStore = defineStore('tools', () => {
newTools: computed(() => tools.value.filter(({ isNew }) => isNew)), newTools: computed(() => tools.value.filter(({ isNew }) => isNew)),
addToolToFavorites({ tool }: { tool: MaybeRef<Tool> }) { addToolToFavorites({ tool }: { tool: MaybeRef<Tool> }) {
favoriteToolsName.value.push(get(tool).name); favoriteToolsName.value.push(get(tool).path);
}, },
removeToolFromFavorites({ tool }: { tool: MaybeRef<Tool> }) { removeToolFromFavorites({ tool }: { tool: MaybeRef<Tool> }) {
favoriteToolsName.value = favoriteToolsName.value.filter(name => get(tool).name !== name); favoriteToolsName.value = favoriteToolsName.value.filter(name => get(tool).name !== name && get(tool).path !== name);
}, },
isToolFavorite({ tool }: { tool: MaybeRef<Tool> }) { isToolFavorite({ tool }: { tool: MaybeRef<Tool> }) {
return favoriteToolsName.value.includes(get(tool).name); return favoriteToolsName.value.includes(get(tool).name)
|| favoriteToolsName.value.includes(get(tool).path);
}, },
}; };
}); });