Skip to content
Snippets Groups Projects
Commit 2404089e authored by Yusuf Akgül's avatar Yusuf Akgül :hatching_chick:
Browse files

added search and sort to ui

parent 9e97eb0f
No related branches found
No related tags found
1 merge request!6Sort + Search UI
Pipeline #34436 failed
"use client"
export default function DashboardLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<section>
<div>
{children}
</div>
</section>
);
}
\ No newline at end of file
import { InfiniteScrollGames } from "@/components/InfiniteScroll"; import { InfiniteScrollGames } from "@/components/InfiniteScroll";
import Search from "@/components/search";
import Sort from "@/components/sort-games";
// renders a list of games infinitely (presumably) // renders a list of games infinitely (presumably)
export default async function GamesPage() { export default async function GamesPage() {
return ( return (
<div className="py-5"> <main className="relative lg:gap-10 xl:grid xl:grid-cols-[1fr_300px]">
<InfiniteScrollGames /> <div className="grid">
</div> <Search className="p-3 lg:w-2/3 2xl:w-1/3" />
<InfiniteScrollGames />
</div>
<div className="hidden xl:block">
<Sort />
</div>
</main>
) )
} }
\ No newline at end of file
...@@ -10,8 +10,8 @@ export default async function ContentLayout({ ...@@ -10,8 +10,8 @@ export default async function ContentLayout({
children, children,
}: DashboardLayoutProps) { }: DashboardLayoutProps) {
return ( return (
<div className="flex min-h-screen flex-col space-y-6"> <div className="flex min-h-screen flex-col">
<div className="container grid flex-1 gap-12 md:grid-cols-[200px_1fr]"> <div className="mx-6 my-6 flex-1 md:grid md:grid-cols-[220px_1fr] md:gap-6 lg:grid-cols-[240px_1fr] lg:gap-10">
<aside className="hidden w-[200px] flex-col md:flex"> <aside className="hidden w-[200px] flex-col md:flex">
<div className="sticky top-0"> <div className="sticky top-0">
<DashboardNav items={dashboardConfig.sidebarNav} /> <DashboardNav items={dashboardConfig.sidebarNav} />
......
...@@ -18,6 +18,7 @@ export function InfiniteScrollGames() { ...@@ -18,6 +18,7 @@ export function InfiniteScrollGames() {
['infiniteGames'], ['infiniteGames'],
async ({ pageParam = 1 }) => async ({ pageParam = 1 }) =>
await fetch(`/api/games/?page=${pageParam}`, await fetch(`/api/games/?page=${pageParam}`,
{ cache: 'force-cache' }
).then((result) => result.json() as Promise<IGame[]>), ).then((result) => result.json() as Promise<IGame[]>),
{ {
getNextPageParam: (lastPage, pages) => { getNextPageParam: (lastPage, pages) => {
...@@ -27,7 +28,7 @@ export function InfiniteScrollGames() { ...@@ -27,7 +28,7 @@ export function InfiniteScrollGames() {
) )
return ( return (
<Card className="p-5"> <Card className="p-6">
{status === 'error' {status === 'error'
? ?
(<span>Error: {(error as Error).message}</span>) (<span>Error: {(error as Error).message}</span>)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { useState } from 'react'; import { useState } from 'react';
import { Button } from './ui/button';
import { Icons } from './ui/icons'; import { Icons } from './ui/icons';
import { Input } from './ui/input'; import { Input } from './ui/input';
import { toast } from './ui/use-toast'; import { toast } from './ui/use-toast';
...@@ -23,17 +24,17 @@ export default function Search({ className, ...props }: DocsSearchProps) { ...@@ -23,17 +24,17 @@ export default function Search({ className, ...props }: DocsSearchProps) {
return ( return (
<form <form
onSubmit={onSubmit} onSubmit={onSubmit}
className={cn("relative w-full", className)} className={cn("relative w-full flex justify-end items-center", className)}
{...props} {...props}
> >
<Input <Input
type="search" type="search"
placeholder="Search..." placeholder="Search..."
className="h-8 w-full sm:w-64 sm:pr-12" className="rounded-full pr-12"
/> />
<kbd className="pointer-events-none absolute right-1.5 top-1.5 hidden h-5 select-none items-center gap-1 rounded border bg-background px-1.5 font-mono text-[10px] font-medium text-muted-foreground opacity-100 sm:flex"> <Button variant="outline" size="lg" className="absolute align-middle h-8 px-2.5 mr-1">
<Icons.ArrowRight /> <Icons.arrowRight className="h-3 w-3" />
</kbd> </Button>
</form> </form>
); );
} }
\ No newline at end of file
...@@ -25,7 +25,7 @@ export default function DashboardNav({ items }: DashboardNavProps) { ...@@ -25,7 +25,7 @@ export default function DashboardNav({ items }: DashboardNavProps) {
return ( return (
<nav className="grid items-start gap-2"> <nav className="grid items-start gap-2">
<div className="flex items-center py-2"> <div className="flex items-center">
<Link href="/" className={cn("rounded-full p-3 hover:bg-accent")}> <Link href="/" className={cn("rounded-full p-3 hover:bg-accent")}>
<Icons.logo className="h-7 w-7 dark:hidden" /> <Icons.logo className="h-7 w-7 dark:hidden" />
<Icons.logoWhite className="h-7 w-7 hidden dark:block" /> <Icons.logoWhite className="h-7 w-7 hidden dark:block" />
......
"use client" "use client"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@radix-ui/react-select"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select";
import { useState } from "react"; import { useState } from "react";
import { Card, CardContent } from "./ui/card"; import { Card } from "./ui/card";
export default function Sort() { export default function Sort() {
const [select, setSelect] = useState<string>(''); const [select, setSelect] = useState<string>('');
...@@ -13,23 +13,51 @@ export default function Sort() { ...@@ -13,23 +13,51 @@ export default function Sort() {
}; };
return ( return (
<Card> <Card className="p-6 grid items-start gap-2">
<CardContent> <Select>
<h1>Filter</h1> <SelectTrigger className="w-full">
<SelectValue placeholder="Sort by..." />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Sorting</SelectLabel>
<SelectItem value="">Any</SelectItem>
<SelectItem value="name">Name</SelectItem>
<SelectItem value="rating">Rating</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<div className="flex flex-col space-y-2"> <h1 className="pt-3">Filter</h1>
<label>Sort By</label> <Select>
<Select> <SelectTrigger className="w-full">
<SelectTrigger className="w-[180px]"> <SelectValue placeholder="By genre..." />
<SelectValue placeholder="Theme" /> </SelectTrigger>
</SelectTrigger> <SelectContent>
<SelectContent> <SelectGroup>
<SelectItem value="light">Any</SelectItem> <SelectLabel>Genre</SelectLabel>
<SelectItem value="dark">Name</SelectItem> <SelectItem value="">Any</SelectItem>
</SelectContent> <SelectItem value="action">Action</SelectItem>
</Select> <SelectItem value="simulation">Simulation</SelectItem>
</div> </SelectGroup>
</CardContent> </SelectContent>
</Select>
<Select>
<SelectTrigger className="w-full">
<SelectValue placeholder="By platform..." />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Platform</SelectLabel>
<SelectItem value="">Any</SelectItem>
<SelectItem value="pc">PC</SelectItem>
<SelectItem value="playstation">Playstation</SelectItem>
<SelectItem value="xbox">Xbox</SelectItem>
<SelectItem value="nintendo">Nintendo</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</Card> </Card>
) )
} }
\ No newline at end of file
"use client"
import * as React from "react"
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
import { cn } from "@/lib/utils"
const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn("relative overflow-hidden", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
))
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 border-t border-t-transparent p-[1px]",
className
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
))
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
export { ScrollArea, ScrollBar }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"@clerk/themes": "^1.7.3", "@clerk/themes": "^1.7.3",
"@prisma/client": "^4.14.1", "@prisma/client": "^4.14.1",
"@radix-ui/react-dropdown-menu": "^2.0.4", "@radix-ui/react-dropdown-menu": "^2.0.4",
"@radix-ui/react-scroll-area": "^1.0.3",
"@radix-ui/react-select": "^1.2.1", "@radix-ui/react-select": "^1.2.1",
"@radix-ui/react-slot": "^1.0.1", "@radix-ui/react-slot": "^1.0.1",
"@radix-ui/react-toast": "^1.1.3", "@radix-ui/react-toast": "^1.1.3",
...@@ -909,6 +910,27 @@ ...@@ -909,6 +910,27 @@
"react-dom": "^16.8 || ^17.0 || ^18.0" "react-dom": "^16.8 || ^17.0 || ^18.0"
} }
}, },
"node_modules/@radix-ui/react-scroll-area": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-scroll-area/-/react-scroll-area-1.0.3.tgz",
"integrity": "sha512-sBX9j8Q+0/jReNObEAveKIGXJtk3xUoSIx4cMKygGtO128QJyVDn01XNOFsyvihKDCTcu7SINzQ2jPAZEhIQtw==",
"dependencies": {
"@babel/runtime": "^7.13.10",
"@radix-ui/number": "1.0.0",
"@radix-ui/primitive": "1.0.0",
"@radix-ui/react-compose-refs": "1.0.0",
"@radix-ui/react-context": "1.0.0",
"@radix-ui/react-direction": "1.0.0",
"@radix-ui/react-presence": "1.0.0",
"@radix-ui/react-primitive": "1.0.2",
"@radix-ui/react-use-callback-ref": "1.0.0",
"@radix-ui/react-use-layout-effect": "1.0.0"
},
"peerDependencies": {
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0"
}
},
"node_modules/@radix-ui/react-select": { "node_modules/@radix-ui/react-select": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-1.2.1.tgz",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment