feat: connect the combobox to the api (sortof)

This commit is contained in:
Juan Di Toro 2023-12-09 16:22:22 +01:00
parent 192d7049c8
commit d203ad3400
3 changed files with 43 additions and 36 deletions

View File

@ -17,38 +17,13 @@ import {
PopoverTrigger PopoverTrigger
} from "@/components/ui/popover" } from "@/components/ui/popover"
import { ChevronDownIcon } from "@heroicons/react/24/solid" import { ChevronDownIcon } from "@heroicons/react/24/solid"
import useSWR from "swr"
type Status = { import { getAvailableSites } from "@/utils"
value: string
label: string
}
const statuses: Status[] = [
{
value: "backlog",
label: "Backlog"
},
{
value: "todo",
label: "Todo"
},
{
value: "in progress",
label: "In Progress"
},
{
value: "done",
label: "Done"
},
{
value: "canceled",
label: "Canceled"
}
]
export function SitesCombobox() { export function SitesCombobox() {
const {data: statuses} = useSWR('/api/statuses', getAvailableSites)
const [open, setOpen] = React.useState(false) const [open, setOpen] = React.useState(false)
const [selectedStatus, setSelectedStatus] = React.useState<Status | null>( const [selectedStatus, setSelectedStatus] = React.useState<SelectOptions | null>(
null null
) )
@ -67,7 +42,7 @@ export function SitesCombobox() {
<CommandList> <CommandList>
<CommandEmpty>No results found.</CommandEmpty> <CommandEmpty>No results found.</CommandEmpty>
<CommandGroup> <CommandGroup>
{statuses.map((status) => ( {statuses?.map((status) => (
<CommandItem <CommandItem
className="text-white" className="text-white"
key={status.value} key={status.value}

7
src/types.d.ts vendored
View File

@ -4,4 +4,9 @@ type SearchResult = {
title: string title: string
description: string description: string
slug: string slug: string
} }
type SelectOptions = {
value: string
label: string
}

View File

@ -44,3 +44,30 @@ export async function getResults({
] ]
} }
export async function getAvailableSites() {
const statuses: SelectOptions[] = [
{
value: "backlog",
label: "Backlog"
},
{
value: "todo",
label: "Todo"
},
{
value: "in progress",
label: "In Progress"
},
{
value: "done",
label: "Done"
},
{
value: "canceled",
label: "Canceled"
}
]
return statuses;
}