Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
buddy-web3 committed Feb 29, 2024
1 parent b26d0bb commit fdd4f84
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
8 changes: 6 additions & 2 deletions app/components/CategoriesNav/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ interface CategoriesNavProps {
* Id of selected category
*/
activeCategoryId: number
/**
* Class name for the component
*/
className?: string
}

export const CategoriesNav = ({categories, activeCategoryId}: CategoriesNavProps) => {
export const CategoriesNav = ({categories, activeCategoryId, className}: CategoriesNavProps) => {
const [search, onSearch] = useState('')
return (
<div className={'categoriesGroup bordered col-4-5'}>
<div className={['categoriesGroup bordered col-4-5', className].join(' ')}>
<h4>Categories</h4>
<div>
<SearchInput onChange={onSearch} placeholderText="Filter by keyword" />
Expand Down
26 changes: 13 additions & 13 deletions app/routes/tags.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ export default function Tags() {
const [sortBy] = useState<keyof typeof sortFuncs>('alphabetically')

useEffect(() => {
if (selectedTag !== currentTag) {
setSelectedTag(currentTag)
if (currentTag === undefined) {
setSelectedTag(null)
} else {
if (selectedTag !== currentTag) {
setSelectedTag(currentTag)
}
}
}, [selectedTag, tags, currentTag])
if (selectedTag === null) {
return null
}
const isTagsPage = window.location.pathname.split('/').slice(-2)[0] === 'tags'

return (
<Page>
<main>
<div className="article-container">
{mobile && !isTagsPage ? null : (
<CategoriesNav
categories={tags.filter((tag) => tag.questions.length > 0).sort(sortFuncs[sortBy])}
activeCategoryId={selectedTag.tagId}
/>
)}
{(mobile && isTagsPage) || selectedTag === null ? null : (
<CategoriesNav
categories={tags.filter((tag) => tag.questions.length > 0).sort(sortFuncs[sortBy])}
activeCategoryId={selectedTag?.tagId || 0}
className={mobile && selectedTag !== null ? 'desktop-only' : ''}
/>
{selectedTag === null ? null : (
<article>
<h1 className="padding-bottom-40">{selectedTag.name}</h1>
<div className="padding-bottom-24">
Expand Down
14 changes: 9 additions & 5 deletions app/routes/tags.all.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import {reloadInBackgroundIfNeeded} from '~/server-utils/kv-cache'
export const loader = async ({request, params}: Parameters<LoaderFunction>[0]) => {
const {data: tags, timestamp} = await loadTags(request)

const tagId = params['*'] && params['*'].split('/')[0]
let tagId = params['*'] && params['*'].split('/')[0]
if (tagId === '') {
tagId = undefined
}

const currentTag = tagId
? tags.find(({tagId: checkedId, name}) => [checkedId.toString(), name].includes(tagId))
: tags[0]
? tags.find(({tagId: checkedId, name}) => [checkedId.toString(), name].includes(tagId!))
: undefined

if (currentTag === undefined) {
if (currentTag === undefined && tagId !== undefined) {
throw new Response(null, {
status: 404,
statusText: 'Unable to find requested tag',
statusText: 'Unable to find requested tag -d',
})
}

Expand Down

0 comments on commit fdd4f84

Please sign in to comment.