From faa14bfe1b9051eb9787e8499505c8cc184acfef Mon Sep 17 00:00:00 2001 From: sHa Date: Thu, 1 May 2025 02:51:25 +0300 Subject: [PATCH] refactor: simplify tag handling by removing dependency on tags.json and updating tag object structure --- src/App.svelte | 46 +++++++++++++++-------------------- src/components/Preview.svelte | 15 +++--------- src/components/Row.svelte | 10 +------- 3 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 9c77ec1..9a7fa65 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -55,15 +55,12 @@ applyTheme(); } - // Compute all unique tags as objects with text and optional color + // Compute all unique tags as strings $: allTags = Array.from( - new Map( - logos.flatMap(logo => (logo.tags || []).map(tag => { - if (typeof tag === 'string') return [tag, { text: tag }]; - return [tag.text, tag]; - })) - ).values() - ).sort((a, b) => a.text.localeCompare(b.text)); + new Set( + logos.flatMap(logo => (logo.tags || [])) + ) + ).map(tag => typeof tag === 'object' ? tag.text : tag); $: filteredLogos = logos.filter(logo => { const matchesSearch = logo.name.toLowerCase().includes(searchQuery.toLowerCase()); @@ -179,7 +176,7 @@ } function getTagObj(text) { - return allTags.find(t => t.text === text); + return { text }; } // Listen for outside click to close dropdown @@ -215,17 +212,14 @@
{#each selectedTags as tagText} - {#if getTagObj(tagText)} - - {/if} + {/each}
{#if tagDropdownOpen} diff --git a/src/components/Preview.svelte b/src/components/Preview.svelte index ad6c146..6ea7e43 100644 --- a/src/components/Preview.svelte +++ b/src/components/Preview.svelte @@ -2,8 +2,6 @@ import { onMount, onDestroy, createEventDispatcher } from 'svelte'; import InlineSvg from './InlineSvg.svelte'; import { getDefaultLogoColor } from '../utils/colorTheme.js'; - import tagsData from '../../public/data/tags.json'; - console.log('Loaded tagsData:', tagsData); export let show = false; export let logo = null; @@ -24,11 +22,9 @@ return logo && logo.format && logo.format.toLowerCase() === 'svg'; } - // Helper to get tag object from tags.json by text + // Helper to get tag object - simplified without tags.json function getTagObj(text) { - const tag = tagsData && typeof tagsData === 'object' && tagsData[text] ? { text, ...tagsData[text] } : { text }; - console.log('[LogoModal] Tag lookup:', text, tag, tagsData); - return tag; + return { text: typeof text === 'object' ? text.text : text }; } // Always use $theme directly, do not cache in a function @@ -45,7 +41,6 @@ $: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme); $: if (logo && logo.tags && logo.tags.length) { logo.tags.forEach(tag => { console.log('[LogoModal] Tag:', tag); - getTagObj(tag); }); } @@ -129,11 +124,7 @@ $: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme); {#if logo.tags && logo.tags.length}
{#each logo.tags as tag} - {#if getTagObj(tag).color} - {getTagObj(tag).text} - {:else} - {getTagObj(tag).text} - {/if} + {typeof tag === 'object' ? tag.text : tag} {/each}
{/if} diff --git a/src/components/Row.svelte b/src/components/Row.svelte index ffb0c04..91e4809 100644 --- a/src/components/Row.svelte +++ b/src/components/Row.svelte @@ -7,10 +7,6 @@ export let onPreview = null; import InlineSvg from './InlineSvg.svelte'; import { getDefaultLogoColor } from '../utils/colorTheme.js'; - import tagsData from '../../public/data/tags.json'; - function getTagObj(text) { - return tagsData[text] ? { text, ...tagsData[text] } : { text }; - }
@@ -53,11 +49,7 @@ {#if logo.tags && logo.tags.length}
{#each logo.tags as tag} - {#if getTagObj(tag).color} - {getTagObj(tag).text} - {:else} - {getTagObj(tag).text} - {/if} + {typeof tag === 'object' ? tag.text : tag} {/each}
{/if}