mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
fix(i18n): tool search in current language and handle switching
Fix #486
This commit is contained in:
1 parent
be4d22587f
commit
e5a2017f7d
5 files changed
+168
-107
No files matched your search
@@ -9574,6 +9574,24 @@ tools:
|
||||
cidr-expands-to-hostcount-ips-exceeding-limit-of-max_cidr_ips: CIDR expands to {0} IPs, exceeding limit of {1}
|
||||
tag-reachable: Reachable
|
||||
tag-unreachable: Unreachable
|
||||
command-palette:
|
||||
store:
|
||||
texts:
|
||||
pages: Pages
|
||||
learn-more-about-it-tools: Learn more about IT-Tools.
|
||||
actions-0: Actions
|
||||
report-a-bug-or-an-issue-to-help-improve-it-tools: Report a bug or an issue to help improve it-tools.
|
||||
report-a-bug-or-an-issue: Report a bug or an issue
|
||||
view-the-source-code-of-it-tools-on-github: View the source code of it-tools on Github.
|
||||
external: External
|
||||
github-repository: Github repository
|
||||
actions: Actions
|
||||
toggle-dark-mode-on-or-off: Toggle dark mode on or off.
|
||||
toggle-dark-mode: Toggle dark mode
|
||||
tools-0: Tools
|
||||
get-a-random-tool-from-the-list: Get a random tool from the list.
|
||||
random-tool: Random tool
|
||||
tools: Tools
|
||||
collapsibleToolMenu:
|
||||
text:
|
||||
expanding: Expanding...
|
||||
|
||||
@@ -27,13 +27,15 @@ watchEffect(() => {
|
||||
document.documentElement.style.setProperty('--app-topbar-height', `${Math.round(navbarHeight.value)}px`);
|
||||
});
|
||||
|
||||
const { t } = useI18n();
|
||||
const { t, locale } = useI18n();
|
||||
|
||||
const toolStore = useToolStore();
|
||||
const { favoriteTools, toolsByCategory } = storeToRefs(toolStore);
|
||||
|
||||
const tools = computed<ToolCategory[]>(() => [
|
||||
...(favoriteTools.value.length > 0 ? [{ name: t('tools.categories.favorite-tools'), components: favoriteTools.value }] : []),
|
||||
...(favoriteTools.value.length > 0
|
||||
? [{ name: t('tools.categories.favorite-tools'), components: favoriteTools.value }]
|
||||
: []),
|
||||
...toolsByCategory.value,
|
||||
]);
|
||||
</script>
|
||||
@@ -44,9 +46,7 @@ const tools = computed<ToolCategory[]>(() => [
|
||||
<RouterLink to="/" class="hero-wrapper">
|
||||
<HeroGradient class="gradient" />
|
||||
<div class="text-wrapper">
|
||||
<div class="title">
|
||||
IT - TOOLS
|
||||
</div>
|
||||
<div class="title">IT - TOOLS</div>
|
||||
<div class="divider" />
|
||||
<div class="subtitle">
|
||||
{{ $t('home.subtitle') }}
|
||||
@@ -109,12 +109,20 @@ const tools = computed<ToolCategory[]>(() => [
|
||||
</c-tooltip>
|
||||
|
||||
<c-tooltip :tooltip="$t('home.uiLib')" position="bottom">
|
||||
<c-button v-if="config.app.env === 'development'" to="/c-lib" circle variant="text" :aria-label="$t('home.uiLib')">
|
||||
<c-button
|
||||
v-if="config.app.env === 'development'"
|
||||
to="/c-lib"
|
||||
circle
|
||||
variant="text"
|
||||
:aria-label="$t('home.uiLib')"
|
||||
>
|
||||
<icon-mdi:brush-variant text-20px />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
<command-palette />
|
||||
<Suspense>
|
||||
<command-palette :key="locale" />
|
||||
</Suspense>
|
||||
|
||||
<div>
|
||||
<NavbarButtons v-if="!styleStore.isSmallScreen" />
|
||||
|
||||
@@ -11,85 +11,89 @@ import DiceIcon from '~icons/mdi/dice-5';
|
||||
import InfoIcon from '~icons/mdi/information-outline';
|
||||
import { useFlexSearch } from '@/composable/flexSearch';
|
||||
|
||||
import { translate as t } from '@/plugins/i18n.plugin';
|
||||
|
||||
const maxSearchResultsPerCategory = import.meta.env.VITE_MAX_SEARCH_RESULT || 25;
|
||||
|
||||
export const useCommandPaletteStore = defineStore('command-palette', () => {
|
||||
const toolStore = useToolStore();
|
||||
const styleStore = useStyleStore();
|
||||
const router = useRouter();
|
||||
const searchPrompt = ref('');
|
||||
export const useCommandPaletteStore = (locale: string) =>
|
||||
defineStore(`command-palette-${locale}`, () => {
|
||||
const toolStore = useToolStore();
|
||||
const styleStore = useStyleStore();
|
||||
const router = useRouter();
|
||||
const searchPrompt = ref('');
|
||||
|
||||
const toolsOptions = toolStore.tools.map(tool => ({
|
||||
...tool,
|
||||
to: tool.path,
|
||||
toolCategory: tool.category,
|
||||
category: 'Tools',
|
||||
}));
|
||||
const toolsOptions = toolStore.tools.map((tool) => ({
|
||||
...tool,
|
||||
to: tool.path,
|
||||
toolCategory: tool.category,
|
||||
category: t('tools.command-palette.store.texts.tools'),
|
||||
}));
|
||||
|
||||
const searchOptions: PaletteOption[] = [
|
||||
...toolsOptions,
|
||||
{
|
||||
name: 'Random tool',
|
||||
description: 'Get a random tool from the list.',
|
||||
action: () => {
|
||||
const { path } = _.sample(toolStore.tools)!;
|
||||
router.push(path);
|
||||
const searchOptions: PaletteOption[] = [
|
||||
...toolsOptions,
|
||||
{
|
||||
name: t('tools.command-palette.store.texts.random-tool'),
|
||||
description: t('tools.command-palette.store.texts.get-a-random-tool-from-the-list'),
|
||||
action: () => {
|
||||
const { path } = _.sample(toolStore.tools)!;
|
||||
router.push(path);
|
||||
},
|
||||
icon: DiceIcon,
|
||||
category: t('tools.command-palette.store.texts.tools-0'),
|
||||
keywords: ['random', 'tool', 'pick', 'choose', 'select'],
|
||||
closeOnSelect: true,
|
||||
},
|
||||
icon: DiceIcon,
|
||||
category: 'Tools',
|
||||
keywords: ['random', 'tool', 'pick', 'choose', 'select'],
|
||||
closeOnSelect: true,
|
||||
},
|
||||
{
|
||||
name: 'Toggle dark mode',
|
||||
description: 'Toggle dark mode on or off.',
|
||||
action: () => styleStore.toggleDark(),
|
||||
icon: SunIcon,
|
||||
category: 'Actions',
|
||||
keywords: ['dark', 'theme', 'toggle', 'mode', 'light', 'system'],
|
||||
},
|
||||
{
|
||||
name: 'Github repository',
|
||||
href: 'https://github.com/sharevb/it-tools',
|
||||
category: 'External',
|
||||
description: 'View the source code of it-tools on Github.',
|
||||
keywords: ['github', 'repo', 'repository', 'source', 'code'],
|
||||
icon: GithubIcon,
|
||||
},
|
||||
{
|
||||
name: 'Report a bug or an issue',
|
||||
description: 'Report a bug or an issue to help improve it-tools.',
|
||||
href: 'https://github.com/sharevb/it-tools/issues/new/choose',
|
||||
category: 'Actions',
|
||||
keywords: ['report', 'issue', 'bug', 'problem', 'error'],
|
||||
icon: BugIcon,
|
||||
},
|
||||
{
|
||||
name: 'About',
|
||||
description: 'Learn more about IT-Tools.',
|
||||
to: '/about',
|
||||
category: 'Pages',
|
||||
keywords: ['about', 'learn', 'more', 'info', 'information'],
|
||||
icon: InfoIcon,
|
||||
},
|
||||
];
|
||||
{
|
||||
name: t('tools.command-palette.store.texts.toggle-dark-mode'),
|
||||
description: t('tools.command-palette.store.texts.toggle-dark-mode-on-or-off'),
|
||||
action: () => styleStore.toggleDark(),
|
||||
icon: SunIcon,
|
||||
category: t('tools.command-palette.store.texts.actions'),
|
||||
keywords: ['dark', 'theme', 'toggle', 'mode', 'light', 'system'],
|
||||
},
|
||||
{
|
||||
name: t('tools.command-palette.store.texts.github-repository'),
|
||||
href: 'https://github.com/sharevb/it-tools',
|
||||
category: t('tools.command-palette.store.texts.external'),
|
||||
description: t('tools.command-palette.store.texts.view-the-source-code-of-it-tools-on-github'),
|
||||
keywords: ['github', 'repo', 'repository', 'source', 'code'],
|
||||
icon: GithubIcon,
|
||||
},
|
||||
{
|
||||
name: t('tools.command-palette.store.texts.report-a-bug-or-an-issue'),
|
||||
description: t('tools.command-palette.store.texts.report-a-bug-or-an-issue-to-help-improve-it-tools'),
|
||||
href: 'https://github.com/sharevb/it-tools/issues/new/choose',
|
||||
category: t('tools.command-palette.store.texts.actions-0'),
|
||||
keywords: ['report', 'issue', 'bug', 'problem', 'error'],
|
||||
icon: BugIcon,
|
||||
},
|
||||
{
|
||||
name: t('tools.pomodoro-timer.PomodoroApp.text.about'),
|
||||
description: t('tools.command-palette.store.texts.learn-more-about-it-tools'),
|
||||
to: '/about',
|
||||
category: t('tools.command-palette.store.texts.pages'),
|
||||
keywords: ['about', 'learn', 'more', 'info', 'information'],
|
||||
icon: InfoIcon,
|
||||
},
|
||||
];
|
||||
|
||||
const { searchResult } = useFlexSearch({
|
||||
search: searchPrompt,
|
||||
data: searchOptions,
|
||||
options: {
|
||||
keys: [{ name: 'name', weight: 2 }, 'description', 'keywords', 'category'],
|
||||
},
|
||||
});
|
||||
const { searchResult } = useFlexSearch({
|
||||
search: searchPrompt,
|
||||
data: searchOptions,
|
||||
options: {
|
||||
keys: [{ name: 'name', weight: 2 }, 'description', 'keywords', 'category'],
|
||||
},
|
||||
});
|
||||
|
||||
const filteredSearchResult = computed(() =>
|
||||
_.mapValues(
|
||||
_.groupBy(searchResult.value, option => option.category),
|
||||
categoryOptions => categoryOptions.slice(0, maxSearchResultsPerCategory),
|
||||
));
|
||||
const filteredSearchResult = computed(() =>
|
||||
_.mapValues(
|
||||
_.groupBy(searchResult.value, (option) => option.category),
|
||||
(categoryOptions) => categoryOptions.slice(0, maxSearchResultsPerCategory),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
filteredSearchResult,
|
||||
searchPrompt,
|
||||
};
|
||||
});
|
||||
return {
|
||||
filteredSearchResult,
|
||||
searchPrompt,
|
||||
};
|
||||
})();
|
||||
@@ -3,13 +3,17 @@ import { storeToRefs } from 'pinia';
|
||||
import * as _ from 'es-toolkit/compat';
|
||||
import { useCommandPaletteStore } from './command-palette.store';
|
||||
import type { PaletteOption } from './command-palette.types';
|
||||
import { loadLocaleMessages } from '@/plugins/i18n.plugin';
|
||||
|
||||
const isModalOpen = ref(false);
|
||||
const inputRef = ref();
|
||||
const router = useRouter();
|
||||
const isMac = computed(() => window.navigator.userAgent.toLowerCase().includes('mac'));
|
||||
|
||||
const commandPaletteStore = useCommandPaletteStore();
|
||||
const { locale } = useI18n();
|
||||
await loadLocaleMessages(locale.value);
|
||||
|
||||
const commandPaletteStore = useCommandPaletteStore(locale.value);
|
||||
const { searchPrompt, filteredSearchResult } = storeToRefs(commandPaletteStore);
|
||||
|
||||
const keys = useMagicKeys({
|
||||
@@ -32,7 +36,7 @@ whenever(keys.meta_k, open);
|
||||
whenever(keys.escape, close);
|
||||
|
||||
function open() {
|
||||
return isModalOpen.value = true;
|
||||
return (isModalOpen.value = true);
|
||||
}
|
||||
|
||||
function close() {
|
||||
@@ -67,7 +71,9 @@ function handleKeydown(event: KeyboardEvent) {
|
||||
}
|
||||
|
||||
function getOptionIndex(option: PaletteOption) {
|
||||
return Object.values(filteredSearchResult.value).flat().findIndex(o => o === option);
|
||||
return Object.values(filteredSearchResult.value)
|
||||
.flat()
|
||||
.findIndex((o) => o === option);
|
||||
}
|
||||
|
||||
function activateOption(option: PaletteOption) {
|
||||
@@ -108,7 +114,6 @@ function activateOption(option: PaletteOption) {
|
||||
<div flex-1>
|
||||
<c-button w-full important:justify-start @click="isModalOpen = true">
|
||||
<span flex items-center gap-3 op-40>
|
||||
|
||||
<icon-mdi-search />
|
||||
{{ $t('search.label') }}
|
||||
|
||||
@@ -118,14 +123,36 @@ function activateOption(option: PaletteOption) {
|
||||
</span>
|
||||
</c-button>
|
||||
|
||||
<c-modal v-model:open="isModalOpen" class="palette-modal" overflow-y-auto shadow-xl important:max-w-650px pretty-scrollbar important:pa-12px @keydown="handleKeydown">
|
||||
<c-input-text ref="inputRef" v-model:value="searchPrompt" raw-text :placeholder="$t('search.placeholder')" autofocus clearable />
|
||||
<c-modal
|
||||
v-model:open="isModalOpen"
|
||||
class="palette-modal"
|
||||
overflow-y-auto
|
||||
shadow-xl
|
||||
important:max-w-650px
|
||||
pretty-scrollbar
|
||||
important:pa-12px
|
||||
@keydown="handleKeydown"
|
||||
>
|
||||
<c-input-text
|
||||
ref="inputRef"
|
||||
v-model:value="searchPrompt"
|
||||
raw-text
|
||||
:placeholder="$t('search.placeholder')"
|
||||
autofocus
|
||||
clearable
|
||||
/>
|
||||
|
||||
<div v-for="(options, category) in filteredSearchResult" :key="category">
|
||||
<div ml-3 mt-3 text-sm font-bold text-primary op-60>
|
||||
{{ category }}
|
||||
</div>
|
||||
<command-palette-option v-for="option in options" :key="option.name" :option="option" :selected="selectedOptionIndex === getOptionIndex(option)" @activated="activateOption" />
|
||||
<command-palette-option
|
||||
v-for="option in options"
|
||||
:key="option.name"
|
||||
:option="option"
|
||||
:selected="selectedOptionIndex === getOptionIndex(option)"
|
||||
@activated="activateOption"
|
||||
/>
|
||||
</div>
|
||||
</c-modal>
|
||||
</div>
|
||||
@@ -136,8 +163,8 @@ function activateOption(option: PaletteOption) {
|
||||
font-size: 18px;
|
||||
|
||||
::v-deep(.input-wrapper) {
|
||||
padding: 4px;
|
||||
padding-left: 18px;
|
||||
padding: 4px;
|
||||
padding-left: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-17
@@ -6,36 +6,37 @@ import type { Tool, ToolCategory, ToolWithCategory } from './tools.types';
|
||||
import { tools as allTools } from './index';
|
||||
import { useITStorage } from '@/composable/queryParams';
|
||||
|
||||
import { translate as t } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const useToolStore = defineStore('tools', () => {
|
||||
const favoriteToolsName = useITStorage('favoriteToolsName', []) as Ref<string[]>;
|
||||
const { t } = useI18n();
|
||||
|
||||
const tools = computed<ToolWithCategory[]>(() => allTools
|
||||
.map((tool) => {
|
||||
const tools = computed<ToolWithCategory[]>(() =>
|
||||
allTools.map((tool) => {
|
||||
const toolI18nKey = tool.path.replace(/\//g, '');
|
||||
const category = tool.category || 'Development';
|
||||
|
||||
return ({
|
||||
return {
|
||||
...tool,
|
||||
path: tool.path,
|
||||
name: t(`tools.${toolI18nKey}.title`, tool.name),
|
||||
description: t(`tools.${toolI18nKey}.description`, tool.description),
|
||||
category: t(`tools.categories.${category.toLowerCase()}`, category),
|
||||
});
|
||||
}));
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
const toolsByCategory = computed<ToolCategory[]>(() => {
|
||||
const orderedTools = _.orderBy(tools.value, ['category', 'name'], ['asc', 'asc']);
|
||||
return Object.entries(_.groupBy(orderedTools, tool => tool.category))
|
||||
.map(([name, components]) => ({
|
||||
name,
|
||||
components,
|
||||
}));
|
||||
return Object.entries(_.groupBy(orderedTools, (tool) => tool.category)).map(([name, components]) => ({
|
||||
name,
|
||||
components,
|
||||
}));
|
||||
});
|
||||
|
||||
const favoriteTools = computed(() => {
|
||||
return favoriteToolsName.value
|
||||
.map(favoriteName => tools.value.find(({ name, path }) => name === favoriteName || path === 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
|
||||
});
|
||||
|
||||
@@ -54,17 +55,20 @@ export const useToolStore = defineStore('tools', () => {
|
||||
},
|
||||
|
||||
removeToolFromFavorites({ tool }: { tool: MaybeRef<Tool> }) {
|
||||
favoriteToolsName.value = favoriteToolsName.value.filter(name => get(tool).name !== name && get(tool).path !== name);
|
||||
favoriteToolsName.value = favoriteToolsName.value.filter(name => get(tool).name !== name && get(tool).path !== name);
|
||||
favoriteToolsName.value = favoriteToolsName.value.filter(
|
||||
(name) => get(tool).name !== name && get(tool).path !== name,
|
||||
);
|
||||
favoriteToolsName.value = favoriteToolsName.value.filter(
|
||||
(name) => get(tool).name !== name && get(tool).path !== name,
|
||||
);
|
||||
},
|
||||
|
||||
isToolFavorite({ tool }: { tool: MaybeRef<Tool> }) {
|
||||
return favoriteToolsName.value.includes(get(tool).name)
|
||||
|| favoriteToolsName.value.includes(get(tool).path);
|
||||
return favoriteToolsName.value.includes(get(tool).name) || favoriteToolsName.value.includes(get(tool).path);
|
||||
},
|
||||
|
||||
updateFavoriteTools(newOrder: ToolWithCategory[]) {
|
||||
favoriteToolsName.value = newOrder.map(tool => tool.path);
|
||||
favoriteToolsName.value = newOrder.map((tool) => tool.path);
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user