feat(About page): import/export favorites

Fix #186
This commit is contained in:
ShareVB committed 2025-09-14 20:08:42 +02:00
1 parent 76551387d7
commit 3ad698544c
3 files changed
+44

No files matched your search

+6
View File
@@ -74,6 +74,12 @@ about:
bug report in the [issues
section](https://github.com/sharevb/it-tools/issues/new/choose) in the
GitHub repository.
import-favorites: Import Favorites
export-favorites: Export Favorites
put-your-favorites-json-array-here: Put your favorites JSON array here...
import-button: Import
favorites-imported-successfully: Favorites imported successfully!
error-importing-favorites-e: 'Error importing favorites: {0}'
favoriteButton:
remove: Remove from favorites
add: Add to favorites
+37
View File
@@ -1,8 +1,12 @@
<script setup lang="ts">
import _ from 'lodash';
import { useHead } from '@vueuse/head';
import { useMessage } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { useToolStore } from '@/tools/tools.store';
const { t } = useI18n();
const toolStore = useToolStore();
const desc = 'Collection of handy online tools for developers, with great UX. IT Tools is a free and open-source collection of handy online tools for developers & people working in IT.';
@@ -42,11 +46,44 @@ useHead({
});
const orderedTools = computed(() => _.orderBy(toolStore.tools, ['category', 'name'], ['asc', 'asc']));
const { favoriteToolsName } = storeToRefs(toolStore);
const message = useMessage();
const importFavoritesJson = ref('');
function importFavorites() {
try {
favoriteToolsName.value = JSON.parse(importFavoritesJson.value);
message.success(t('about.favorites-imported-successfully'));
}
catch (e: any) {
message.error(t('about.error-importing-favorites-e', [e]));
}
}
const favoritesJson = computed(() => JSON.stringify(favoriteToolsName.value));
</script>
<template>
<c-markdown :markdown="$t('about.content-fork')" mx-auto mt-50px />
<n-card :title="$t('about.import-favorites')" mx-auto mt-50px>
<c-input-text
v-model:value="importFavoritesJson"
:placeholder="$t('about.put-your-favorites-json-array-here')"
multiline
monospace
mb-2
/>
<c-button @click="importFavorites">
{{ $t('about.import-button') }}
</c-button>
</n-card>
<n-card :title="$t('about.export-favorites')" mx-auto mt-50px>
<textarea-copyable
v-model:value="favoritesJson"
/>
</n-card>
<n-card :title="$t('about.alltools-title', { toolsCount: toolStore.tools.length })" mx-auto mt-50px>
<n-table>
<thead>
+1
View File
@@ -80,6 +80,7 @@ export const useToolStore = defineStore('tools', () => {
tools,
favoriteTools,
toolsByCategory,
favoriteToolsName,
newTools: computed(() => tools.value.filter(({ isNew }) => isNew)),
addToolToFavorites({ tool }: { tool: MaybeRef<Tool> }) {