From a1708002f95fd8c1cbfbba6526fa27b4406572f0 Mon Sep 17 00:00:00 2001 From: andrzej Date: Tue, 24 Sep 2024 12:25:31 +0200 Subject: [PATCH] render textinputcell only on large screens --- package-lock.json | 1 - src/app/layout.tsx | 2 +- src/app/publication/columns.tsx | 21 ++++- src/app/publication/create.tsx | 6 +- src/app/publication/page.tsx | 2 +- src/app/story/columns.tsx | 15 +++- src/app/story/page.tsx | 2 +- src/app/tailwind.css | 77 ++++--------------- src/app/ui/tables/inputs/genrePickerInput.tsx | 2 +- src/app/ui/tables/inputs/numberInput.tsx | 22 +++--- src/app/ui/tables/inputs/textInput.tsx | 25 +++--- 11 files changed, 78 insertions(+), 97 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc377c6..21fbc4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6570,7 +6570,6 @@ "version": "14.2.13", "resolved": "https://registry.npmjs.org/next/-/next-14.2.13.tgz", "integrity": "sha512-BseY9YNw8QJSwLYD7hlZzl6QVDoSFHL/URN5K64kVEVpCsSOWeyjbIGK+dZUaRViHTaMQX8aqmnn0PHBbGZezg==", - "license": "MIT", "dependencies": { "@next/env": "14.2.13", "@swc/helpers": "0.5.5", diff --git a/src/app/layout.tsx b/src/app/layout.tsx index f3608f3..1acf1e1 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -33,7 +33,7 @@ export default function RootLayout({ >
- ), - cell: NumberInputCell, + cell: cell => ( + <> +

{cell.getValue()}

+ + + ), meta: { step: 10, formSchema: pubSchema diff --git a/src/app/publication/create.tsx b/src/app/publication/create.tsx index 0a90c1a..1946173 100644 --- a/src/app/publication/create.tsx +++ b/src/app/publication/create.tsx @@ -5,6 +5,7 @@ import { ComponentProps } from "react"; import { Genre } from "@prisma/client"; import { createPub } from "app/lib/create"; import PubForm from "app/ui/forms/pub"; +import { Plus } from "lucide-react"; export default function CreatePubDialog({ genres }: ComponentProps<"div"> & { genres: Genre[] }) { @@ -12,7 +13,10 @@ export default function CreatePubDialog({ genres }: ComponentProps<"div"> & { ge - + diff --git a/src/app/publication/page.tsx b/src/app/publication/page.tsx index 38d50e7..2b6c301 100644 --- a/src/app/publication/page.tsx +++ b/src/app/publication/page.tsx @@ -12,7 +12,7 @@ export default async function Page() { const genres = await getGenres() const pubs = await getPubsWithGenres() return ( -
+
diff --git a/src/app/story/columns.tsx b/src/app/story/columns.tsx index b57f436..78c14f5 100644 --- a/src/app/story/columns.tsx +++ b/src/app/story/columns.tsx @@ -29,9 +29,13 @@ export const columns: ColumnDef[] = [ ) }, - cell: TextInputCell, + cell: cell => ( + <> +

{cell.getValue()}

+ + + ), meta: { formSchema: storySchema } - }, { accessorKey: "word_count", @@ -53,7 +57,12 @@ export const columns: ColumnDef[] = [ ) }, enableColumnFilter: false, - cell: NumberInputCell, + cell: cell => ( + <> +

{cell.getValue()}

+ + + ), meta: { step: 50, formSchema: storySchema diff --git a/src/app/story/page.tsx b/src/app/story/page.tsx index f5b81c6..5a2ca84 100644 --- a/src/app/story/page.tsx +++ b/src/app/story/page.tsx @@ -19,7 +19,7 @@ export default async function Page() { return ( -
+
diff --git a/src/app/tailwind.css b/src/app/tailwind.css index 8b5fc12..1bc491b 100644 --- a/src/app/tailwind.css +++ b/src/app/tailwind.css @@ -753,6 +753,10 @@ body { margin-left: auto; } +.mr-4 { + margin-right: 1rem; +} + .mt-2 { margin-top: 0.5rem; } @@ -769,14 +773,6 @@ body { margin-top: 1.5rem; } -.mt-auto { - margin-top: auto; -} - -.mr-4 { - margin-right: 1rem; -} - .block { display: block; } @@ -846,10 +842,6 @@ body { height: 1.25rem; } -.h-5\/6 { - height: 83.333333%; -} - .h-7 { height: 1.75rem; } @@ -927,10 +919,6 @@ body { width: 10rem; } -.w-5\/6 { - width: 83.333333%; -} - .w-7 { width: 1.75rem; } @@ -972,10 +960,6 @@ body { width: 100vw; } -.w-11\/12 { - width: 91.666667%; -} - .min-w-\[8rem\] { min-width: 8rem; } @@ -1089,14 +1073,6 @@ body { flex-wrap: wrap; } -.content-center { - align-content: center; -} - -.content-between { - align-content: space-between; -} - .items-start { align-items: flex-start; } @@ -1109,10 +1085,6 @@ body { align-items: baseline; } -.justify-start { - justify-content: flex-start; -} - .justify-end { justify-content: flex-end; } @@ -1125,14 +1097,6 @@ body { justify-content: space-between; } -.justify-around { - justify-content: space-around; -} - -.justify-evenly { - justify-content: space-evenly; -} - .gap-1 { gap: 0.25rem; } @@ -1230,10 +1194,6 @@ body { overflow: hidden; } -.overflow-clip { - overflow: clip; -} - .whitespace-nowrap { white-space: nowrap; } @@ -1353,11 +1313,6 @@ body { background-color: transparent; } -.bg-red-800 { - --tw-bg-opacity: 1; - background-color: rgb(153 27 27 / var(--tw-bg-opacity)); -} - .fill-current { fill: currentColor; } @@ -1390,6 +1345,11 @@ body { padding: 1.5rem; } +.px-1 { + padding-left: 0.25rem; + padding-right: 0.25rem; +} + .px-2 { padding-left: 0.5rem; padding-right: 0.5rem; @@ -1445,16 +1405,6 @@ body { padding-bottom: 1rem; } -.px-1 { - padding-left: 0.25rem; - padding-right: 0.25rem; -} - -.px-0 { - padding-left: 0px; - padding-right: 0px; -} - .pl-3 { padding-left: 0.75rem; } @@ -1745,10 +1695,6 @@ body { animation-duration: 200ms; } -.direction-reverse { - animation-direction: reverse; -} - /**/ /* @layer base { */ @@ -2464,6 +2410,11 @@ body { padding-top: 1rem; padding-bottom: 1rem; } + + .md\:text-sm { + font-size: 0.875rem; + line-height: 1.25rem; + } } .\[\&\:has\(\[aria-selected\]\)\]\:bg-accent:has([aria-selected]) { diff --git a/src/app/ui/tables/inputs/genrePickerInput.tsx b/src/app/ui/tables/inputs/genrePickerInput.tsx index a7dac0a..1b4d075 100644 --- a/src/app/ui/tables/inputs/genrePickerInput.tsx +++ b/src/app/ui/tables/inputs/genrePickerInput.tsx @@ -78,7 +78,7 @@ export default function GenrePickerInputCell(props: CellContext) { render={({ field }) => ( - {value.length > 0 ? : + {value.length > 0 ? : } diff --git a/src/app/ui/tables/inputs/numberInput.tsx b/src/app/ui/tables/inputs/numberInput.tsx index 9602ee3..d4571ef 100644 --- a/src/app/ui/tables/inputs/numberInput.tsx +++ b/src/app/ui/tables/inputs/numberInput.tsx @@ -9,20 +9,20 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { toast } from "@/components/ui/use-toast"; import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form"; -export default function NumberInputCell(props: CellContext) { +export default function NumberInputCell({ cellContext, className }: { cellContext: CellContext, className: string }) { const [isActive, setIsActive] = useState(false) - const table = props.table.options.meta.tableName - const id = props.row.original.id - const column = props.column.id - const pathname = props.table.options.meta.pathname - const value = props.cell.getValue() - const formSchema = props.column.columnDef.meta.formSchema.pick({ [column]: true }) + const table = cellContext.table.options.meta.tableName + const id = cellContext.row.original.id + const column = cellContext.column.id + const pathname = cellContext.table.options.meta.pathname + const value = cellContext.cell.getValue() + const formSchema = cellContext.column.columnDef.meta.formSchema.pick({ [column]: true }) const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { - [column]: props.cell.getValue() + [column]: cellContext.cell.getValue() }, }) @@ -55,7 +55,7 @@ export default function NumberInputCell(props: CellContext) { return (
setIsActive(true)} - className="w-full h-fit flex items-center justify-center" + className={className + " w-full h-fit flex items-center justify-center"} tabIndex={0} onKeyDown={e => { if (e.code === "Enter" && !isActive) { @@ -81,7 +81,7 @@ export default function NumberInputCell(props: CellContext) { className="md:w-24" type="number" autoFocus={true} - step={props.column.columnDef.meta?.step} + step={cellContext.column.columnDef.meta?.step} {...field} /> @@ -92,7 +92,7 @@ export default function NumberInputCell(props: CellContext) { - :

{props.cell.getValue()}

+ :

{cellContext.cell.getValue()}

}
) diff --git a/src/app/ui/tables/inputs/textInput.tsx b/src/app/ui/tables/inputs/textInput.tsx index c06b1d3..6aee8e8 100644 --- a/src/app/ui/tables/inputs/textInput.tsx +++ b/src/app/ui/tables/inputs/textInput.tsx @@ -10,20 +10,23 @@ import { toast } from "@/components/ui/use-toast"; import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form"; import TitleContainer from "app/ui/titleContainer"; -export function TextInputCell(props: CellContext) { +export function TextInputCell({ cellContext, className }: { className: string, cellContext: CellContext }) { const [isActive, setIsActive] = useState(false) - - const table = props.table.options.meta.tableName - const id = props.row.original.id - const column = props.column.id - const pathname = props.table.options.meta.pathname - const value = props.cell.getValue() - const formSchema = props.column.columnDef.meta.formSchema.pick({ [column]: true }) + if (cellContext === undefined) { + console.error("CELL CONTEXT UNDEFINED!") + return false + } + const table = cellContext.table.options.meta.tableName + const id = cellContext.row.original.id + const column = cellContext.column.id + const pathname = cellContext.table.options.meta.pathname + const value = cellContext.cell.getValue() + const formSchema = cellContext.column.columnDef.meta.formSchema.pick({ [column]: true }) const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { - [column]: props.cell.getValue() + [column]: cellContext.cell.getValue() }, }) @@ -60,7 +63,7 @@ export function TextInputCell(props: CellContext) { return (
setIsActive(prev => !prev)} - className="w-full h-fit flex items-center justify-left" + className={className + " w-full h-fit flex items-center justify-left"} tabIndex={0} onKeyDown={e => { if (e.code === "Enter" && !isActive) { @@ -96,7 +99,7 @@ export function TextInputCell(props: CellContext) { - : {props.cell.getValue()} + : {cellContext.cell.getValue()} }
)