"use client" import { useState } from "react" import { IconLayoutGrid, IconList, IconPlus, IconUpload, IconSearch, IconSortAscending, IconSortDescending, IconFolder, IconFileText, IconTable, IconPresentation, } from "@tabler/icons-react" import { useFiles, type SortField, type ViewMode } from "@/hooks/use-files" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" export type NewFileType = "folder" | "document" | "spreadsheet" | "presentation" export function FileToolbar({ onNew, onUpload, }: { onNew: (type: NewFileType) => void onUpload: () => void }) { const { state, dispatch } = useFiles() const [searchFocused, setSearchFocused] = useState(false) const sortLabels: Record = { name: "Name", modified: "Modified", size: "Size", type: "Type", } const handleSort = (field: SortField) => { const direction = state.sortBy === field && state.sortDirection === "asc" ? "desc" : "asc" dispatch({ type: "SET_SORT", payload: { field, direction } }) } return (
onNew("folder")}> Folder onNew("document")}> Document onNew("spreadsheet")}> Spreadsheet onNew("presentation")}> Presentation File upload
dispatch({ type: "SET_SEARCH", payload: e.target.value }) } onFocus={() => setSearchFocused(true)} onBlur={() => setSearchFocused(false)} className="h-8 pl-8 text-sm" />
{(Object.keys(sortLabels) as SortField[]).map((field) => ( handleSort(field)}> {sortLabels[field]} {state.sortBy === field && ( {state.sortDirection === "asc" ? "↑" : "↓"} )} ))} { if (v) dispatch({ type: "SET_VIEW_MODE", payload: v as ViewMode }) }} size="sm" >
) }