|
1 | 1 | import { useState } from 'react' |
2 | 2 | import { Input } from '@/components/ui/input' |
3 | 3 | import { Button } from '@/components/ui/button' |
4 | | -import { ExternalLink } from 'lucide-react' |
5 | | -import { VinylBrowser } from '@/components/VinylBrowser' |
| 4 | +import { ExternalLink, LayoutGrid, LayoutList, AlignJustify } from 'lucide-react' |
| 5 | +import { VinylBrowser, type View } from '@/components/VinylBrowser' |
6 | 6 | import { GitHubLogoIcon } from '@radix-ui/react-icons' |
| 7 | +import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group' |
| 8 | +import { |
| 9 | + Select, |
| 10 | + SelectContent, |
| 11 | + SelectItem, |
| 12 | + SelectTrigger, |
| 13 | + SelectValue, |
| 14 | +} from '@/components/ui/select' |
| 15 | +import { sortOptions, type SortingOption } from '@/lib/sort' |
7 | 16 |
|
8 | 17 | export const App = () => { |
9 | 18 | const [user, setUser] = useState('davidlyons') |
10 | 19 | const [page, setPage] = useState(1) |
| 20 | + const [view, setView] = useState<View>('covers-text') |
| 21 | + const [sort, setSort] = useState<SortingOption>(sortOptions[0]) |
11 | 22 |
|
12 | 23 | return ( |
13 | 24 | <div className="overflow-hidden pt-14 pb-8 min-[1680px]:pb-14"> |
14 | 25 | <div className="container"> |
15 | | - <div className="mb-5 flex items-center gap-2 text-sm"> |
16 | | - <span className="font-bold">Discogs user</span> |
17 | | - <Input |
18 | | - className="w-auto" |
19 | | - name="user" |
20 | | - placeholder="Discogs username" |
21 | | - value={user} |
22 | | - onChange={(e) => { |
23 | | - setUser(e.target.value) |
24 | | - setPage(1) // reset page to 1 when user changes |
25 | | - }} |
26 | | - /> |
27 | | - <Button variant="outline" size="icon" aria-label="Open Discogs profile" asChild> |
28 | | - <a |
29 | | - href={`https://www.discogs.com/user/${user}`} |
30 | | - target="_blank" |
31 | | - rel="noopener noreferrer" |
| 26 | + <div className="mb-5 flex flex-wrap justify-center gap-4 text-sm md:justify-between"> |
| 27 | + {/* username input */} |
| 28 | + <div className="flex items-center gap-2"> |
| 29 | + <span className="font-bold">Discogs user</span> |
| 30 | + <Input |
| 31 | + className="w-auto" |
| 32 | + name="user" |
| 33 | + placeholder="Discogs username" |
| 34 | + value={user} |
| 35 | + onChange={(e) => { |
| 36 | + setUser(e.target.value) |
| 37 | + setPage(1) // reset page to 1 when user changes |
| 38 | + }} |
| 39 | + /> |
| 40 | + <Button variant="outline" size="icon" aria-label="Open Discogs profile" asChild> |
| 41 | + <a |
| 42 | + href={`https://www.discogs.com/user/${user}`} |
| 43 | + target="_blank" |
| 44 | + rel="noopener noreferrer" |
| 45 | + > |
| 46 | + <ExternalLink /> |
| 47 | + </a> |
| 48 | + </Button> |
| 49 | + </div> |
| 50 | + |
| 51 | + <div className="flex flex-wrap items-center justify-center gap-6"> |
| 52 | + {/* layout / view control */} |
| 53 | + <ToggleGroup |
| 54 | + type="single" |
| 55 | + spacing={2} |
| 56 | + variant="outline" |
| 57 | + value={view} |
| 58 | + onValueChange={(value: View) => { |
| 59 | + if (value) setView(value) |
| 60 | + }} |
32 | 61 | > |
33 | | - <ExternalLink /> |
34 | | - </a> |
35 | | - </Button> |
| 62 | + <ToggleGroupItem value="covers-text" title="Covers and text"> |
| 63 | + <LayoutList /> |
| 64 | + </ToggleGroupItem> |
| 65 | + <ToggleGroupItem value="covers" title="Covers only"> |
| 66 | + <LayoutGrid /> |
| 67 | + </ToggleGroupItem> |
| 68 | + <ToggleGroupItem value="text" title="Text only"> |
| 69 | + <AlignJustify /> |
| 70 | + </ToggleGroupItem> |
| 71 | + </ToggleGroup> |
| 72 | + |
| 73 | + {/* sort select */} |
| 74 | + <div className="flex items-center"> |
| 75 | + Sort |
| 76 | + <Select |
| 77 | + value={sort ? JSON.stringify(sort) : ''} |
| 78 | + onValueChange={(value) => { |
| 79 | + setSort(JSON.parse(value)) |
| 80 | + setPage(1) // reset page to 1 when sort changes |
| 81 | + }} |
| 82 | + > |
| 83 | + <SelectTrigger className="ms-3 w-40"> |
| 84 | + <SelectValue placeholder="sort" /> |
| 85 | + </SelectTrigger> |
| 86 | + <SelectContent position="popper" align="end"> |
| 87 | + {sortOptions.map((option) => ( |
| 88 | + <SelectItem value={JSON.stringify(option)} key={option.value}> |
| 89 | + {option.label} |
| 90 | + </SelectItem> |
| 91 | + ))} |
| 92 | + </SelectContent> |
| 93 | + </Select> |
| 94 | + </div> |
| 95 | + </div> |
36 | 96 | </div> |
37 | 97 |
|
38 | | - <VinylBrowser user={user} page={page} setPage={setPage} /> |
| 98 | + <VinylBrowser user={user} page={page} setPage={setPage} view={view} sort={sort} /> |
39 | 99 | </div> |
40 | 100 |
|
| 101 | + {/* github repo link */} |
41 | 102 | <div className="bottom-4 left-4 text-center max-[1680px]:mt-8 min-[1680px]:fixed"> |
42 | 103 | <a |
43 | 104 | href="https://github.com/davidlyons/discogs" |
|
0 commit comments