Skip to content

Commit

Permalink
fix: Change search dialog on click item link
Browse files Browse the repository at this point in the history
  • Loading branch information
0niel committed Sep 15, 2023
1 parent de27bf1 commit 3f3ea80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/layout/command-palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export default function CommandPalette({ open, setOpen }: CommandPaletteProps) {
},
)

const fetchPost = (postId: number, reason: PostItemReason) => {
const fetchPost = (slug: string, reason: PostItemReason) => {
return () => {
setOpen(false)
void router.push(reason === PostItemReason.FOUND ? `/finds/${postId}` : `/losses/${postId}`)
void router.push(reason === PostItemReason.FOUND ? `/finds/${slug}` : `/losses/${slug}`)
}
}

Expand All @@ -65,13 +65,13 @@ export default function CommandPalette({ open, setOpen }: CommandPaletteProps) {

const onSelectedOptionEnter = (
open: boolean,
selectedOption: { id: number; reason: PostItemReason } | null,
selectedOption: { id: number; slug: string; reason: PostItemReason } | null,
) => {
return (event: KeyboardEventHandler<HTMLInputElement>) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (open && selectedOption && event.key === 'Enter') {
fetchPost(selectedOption.id, selectedOption.reason)()
fetchPost(selectedOption.slug, selectedOption.reason)()
}
}
}
Expand Down Expand Up @@ -117,7 +117,11 @@ export default function CommandPalette({ open, setOpen }: CommandPaletteProps) {
onKeyDown={(e: any) =>
onSelectedOptionEnter(
open,
activeOption as { id: number; reason: PostItemReason } | null,
activeOption as {
id: number
slug: string
reason: PostItemReason
} | null,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
)(e)
}
Expand Down Expand Up @@ -156,7 +160,7 @@ export default function CommandPalette({ open, setOpen }: CommandPaletteProps) {
<Combobox.Option
key={item.id}
value={item}
onClick={fetchPost(item.id, item.reason)}
onClick={fetchPost(item.slug, item.reason)}
className={({ active }) =>
classNames(
'cursor-default select-none px-4 py-2',
Expand Down
2 changes: 2 additions & 0 deletions src/server/api/routers/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ async function searchPosts(query: string, reason: PostItemReason) {
name: true,
description: true,
reason: true,
slug: true,
},
where: {
status,
Expand All @@ -376,6 +377,7 @@ async function searchPosts(query: string, reason: PostItemReason) {
name: true,
description: true,
reason: true,
slug: true,
},
where: {
status,
Expand Down

0 comments on commit 3f3ea80

Please sign in to comment.