diff --git a/app/routes/tags.$tag.tsx b/app/routes/tags.$tag.tsx index 9739642a..44e07d46 100644 --- a/app/routes/tags.$tag.tsx +++ b/app/routes/tags.$tag.tsx @@ -24,14 +24,15 @@ export const loader = async ({request, params}: Parameters[0]) = try { const tags = await loadTags(request) - return {tag, tags} + return {tag, ...tags} } catch (error: unknown) { console.error(`error fetching tag "${tag}":`, error) - // return { - // error: error?.toString(), - // timestamp: new Date().toISOString(), - // data: [], - // } + return { + error: error?.toString(), + timestamp: new Date().toISOString(), + data: new Array(), + tag, + } } } @@ -47,10 +48,11 @@ export async function fetchTag(tagName: string): Promise { const json: Awaited> = await response.json() if ('error' in json) console.error(json.error) const {data, timestamp} = json + const currentTagData = data.filter((tagData) => tagData.name === tagName)[0] reloadInBackgroundIfNeeded(url, timestamp) - return data + return currentTagData }) } @@ -142,15 +144,14 @@ export function Tags({tags}: Props) { } export default function App() { - const {tag, tags} = useLoaderData>() - const {data = []} = tags ?? {} + const {tag, data} = useLoaderData>() const [selectedTag, setSelectedTag] = useState(null) const [tagsFilter, setTagsFilter] = useState('') const {toc} = useToC() - const [sortBy, setSortBy] = useState('alphabetically') + const [sortBy] = useState('alphabetically') - const tagWithQuestions = data.filter((tagData) => tagData.name === tag)[0] + const currentTagData = data.filter((tagData) => tagData.name === tag)[0] useEffect(() => { if (selectedTag === null) { setSelectedTag(data.filter((tag) => tag.questions.length > 0)[0]) @@ -181,15 +182,15 @@ export default function App() { {selectedTag === null ? null : (
-

{tagWithQuestions.name}

- {tagWithQuestions.questions.length === 0 ? ( +

{currentTagData.name}

+ {currentTagData.questions.length === 0 ? (
No questions found
) : (

- {tagWithQuestions.questions.length} pages tagged {`"${tagWithQuestions.name}"`} + {currentTagData.questions.length} pages tagged {`"${currentTagData.name}"`}

)} - {selectedTag && } + {selectedTag && }
)}