Skip to content

Commit

Permalink
feat(tags): use tags/tagId/tagName as URL
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhender committed Feb 10, 2024
1 parent fff1254 commit 4cbb5d5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/components/ArticlesDropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Tag} from '~/server-utils/stampy'
import {TOCItem, Category, ADVANCED, INTRODUCTORY} from '~/routes/questions.toc'
import {sortFuncs} from '~/routes/tags.$tag'
import {sortFuncs} from '~/routes/tags.$tagId.$'
import Button from '~/components/Button'
import './dropdown.css'

Expand Down Expand Up @@ -39,16 +39,16 @@ export const ArticlesDropdown = ({toc, categories}: ArticlesDropdownProps) => (
{categories
?.sort(sortFuncs['by number of questions'])
.slice(0, 12)
.map(({rowId, name}) => (
.map(({rowId, name, tagId}) => (
<Link
key={rowId}
className="articles-dropdown-teal-entry"
to={`/tags/${name}`}
to={`/tags/${tagId}/${name}`}
text={name}
/>
))}

<Button action="/tags/" className="dropdown-button bordered grey dropdown-button-label">
<Button action="/tags" className="dropdown-button bordered grey dropdown-button-label">
Browse all categories
</Button>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/routes/tags.$tag.tsx → app/routes/tags.$tagId.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {ListTable} from '~/components/Table/ListTable'
import {CategoriesNav} from '~/components/CategoriesNav/Menu'

export const loader = async ({request, params}: Parameters<LoaderFunction>[0]) => {
const {tag: tagFromUrl} = params
const {tagId: tagFromUrl} = params
if (!tagFromUrl) {
throw Error('missing tag name')
}

const tags = await loadTags(request)
const currentTag = tags.data.find((tagData) => tagData.name === tagFromUrl)
const currentTag = tags.data.find((tagData) => tagData.tagId === Number(tagFromUrl))
if (currentTag === undefined) {
throw new Response(null, {
status: 404,
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function App() {
}
activeCategoryId={selectedTag.tagId}
onClick={(selectedTag) => {
navigate(`../${selectedTag.name}`, {relative: 'path'})
navigate(`../${selectedTag.tagId}/${selectedTag.name}`, {relative: 'path'})
}}
onChange={setTagsFilter}
/>
Expand Down
2 changes: 1 addition & 1 deletion app/routes/tags._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export const loader = async ({request}: Parameters<LoaderFunction>[0]) => {
const tags = await loadTags(request)
const {data = []} = tags ?? {}
const defaultTag = data[0]
throw redirect(`${encodeURIComponent(defaultTag.name)}`)
throw redirect(`${defaultTag.tagId}/${defaultTag.name}`)
}

0 comments on commit 4cbb5d5

Please sign in to comment.