1- import { createFileRoute , Link , useNavigate } from "@tanstack/react-router" ;
1+ import {
2+ Drawer ,
3+ DrawerBody ,
4+ DrawerContent ,
5+ DrawerHeader ,
6+ } from "@heroui/drawer" ;
7+ import {
8+ createFileRoute ,
9+ Link ,
10+ useNavigate ,
11+ useRouter ,
12+ } from "@tanstack/react-router" ;
213import { zodSearchValidator } from "@tanstack/router-zod-adapter" ;
3- import { CircleSlash } from "lucide-react" ;
14+ import { CircleSlash , SquarePen } from "lucide-react" ;
15+ import { useState } from "react" ;
416import { z } from "zod" ;
17+ import { useAuth } from "../../../auth" ;
18+ import { Form } from "../../../components/Form" ;
519import { Format } from "../../../components/Format" ;
620import { FullTable } from "../../../components/FullTable" ;
721import { Uniqolor } from "../../../components/Uniqolor" ;
8- import type { Group } from "@superstreamer/api/client" ;
9- import type { Asset } from "@superstreamer/api/client" ;
22+ import type { Asset , Group } from "@superstreamer/api/client" ;
1023
1124export const Route = createFileRoute ( "/(dashboard)/_layout/assets" ) ( {
1225 component : RouteComponent ,
@@ -33,6 +46,7 @@ function RouteComponent() {
3346 const navigate = useNavigate ( { from : Route . fullPath } ) ;
3447 const { assets, groups } = Route . useLoaderData ( ) ;
3548 const filter = Route . useLoaderDeps ( ) ;
49+ const [ editAsset , setEditAsset ] = useState < Asset | null > ( null ) ;
3650
3751 if ( ! assets . data || ! groups . data ) {
3852 return null ;
@@ -63,6 +77,10 @@ function RouteComponent() {
6377 label : "Created" ,
6478 allowsSorting : true ,
6579 } ,
80+ {
81+ id : "actions" ,
82+ label : "Actions" ,
83+ } ,
6684 ] }
6785 { ...assets . data }
6886 filter = { filter }
@@ -72,13 +90,31 @@ function RouteComponent() {
7290 mapRow = { ( item ) => ( {
7391 key : item . id ,
7492 cells : [
75- item . name ,
93+ < Name asset = { item } /> ,
7694 < Playables asset = { item } /> ,
7795 < GroupTag groups = { groups . data } asset = { item } /> ,
7896 < Format format = "date" value = { item . createdAt } /> ,
97+ < div className = "flex items-center" >
98+ < button onClick = { ( ) => setEditAsset ( item ) } >
99+ < SquarePen className = "w-4 h-4" />
100+ </ button >
101+ </ div > ,
79102 ] ,
80103 } ) }
81104 />
105+ < EditAssetDrawer asset = { editAsset } onClose = { ( ) => setEditAsset ( null ) } />
106+ </ div >
107+ ) ;
108+ }
109+
110+ function Name ( { asset } : { asset : Asset } ) {
111+ if ( ! asset . name ) {
112+ return < span > { asset . id } </ span > ;
113+ }
114+ return (
115+ < div >
116+ { asset . name }
117+ < div className = "text-xs opacity-50" > { asset . id } </ div >
82118 </ div >
83119 ) ;
84120}
@@ -101,3 +137,41 @@ function Playables({ asset }: { asset: Asset }) {
101137 </ div >
102138 ) ;
103139}
140+
141+ function EditAssetDrawer ( {
142+ asset,
143+ onClose,
144+ } : {
145+ asset : Asset | null ;
146+ onClose : ( ) => void ;
147+ } ) {
148+ const router = useRouter ( ) ;
149+ const { api } = useAuth ( ) ;
150+
151+ return (
152+ < Drawer isOpen = { asset !== null } onClose = { onClose } >
153+ < DrawerContent >
154+ < DrawerHeader > Asset</ DrawerHeader >
155+ { asset ? (
156+ < DrawerBody >
157+ < div className = "mb-4" > { asset . id } </ div >
158+ < Form
159+ fields = { {
160+ name : {
161+ type : "string" ,
162+ label : "Name" ,
163+ value : asset . name ,
164+ } ,
165+ } }
166+ onSubmit = { async ( values ) => {
167+ await api . assets ( { id : asset . id } ) . put ( values ) ;
168+ await router . invalidate ( ) ;
169+ onClose ( ) ;
170+ } }
171+ />
172+ </ DrawerBody >
173+ ) : null }
174+ </ DrawerContent >
175+ </ Drawer >
176+ ) ;
177+ }
0 commit comments