Compare commits
No commits in common. "29ab837aca3297415ab21540115257d7b9001511" and "2294d0c0b0edc63cc4368e827b1c41895f4640ec" have entirely different histories.
29ab837aca
...
2294d0c0b0
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
@ -17,12 +17,10 @@ import Link from "next/link"
|
||||||
import { PubsWithGenres } from "./page"
|
import { PubsWithGenres } from "./page"
|
||||||
import { DialogClose } from "@radix-ui/react-dialog"
|
import { DialogClose } from "@radix-ui/react-dialog"
|
||||||
import { actions } from "app/ui/tables/actions"
|
import { actions } from "app/ui/tables/actions"
|
||||||
import { TextInputCell } from "app/ui/tables/inputs/textInput"
|
|
||||||
import { selectCol } from "app/ui/tables/selectColumn"
|
import { selectCol } from "app/ui/tables/selectColumn"
|
||||||
import NumberInputCell from "app/ui/tables/inputs/numberInput"
|
import InputCell from "app/ui/tables/inputs/input"
|
||||||
import { formSchema } from "app/ui/forms/pub"
|
import { formSchema } from "app/ui/forms/pub"
|
||||||
|
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<PubsWithGenres>()
|
const columnHelper = createColumnHelper<PubsWithGenres>()
|
||||||
|
|
||||||
export const columns: ColumnDef<PubsWithGenres>[] = [
|
export const columns: ColumnDef<PubsWithGenres>[] = [
|
||||||
|
@ -40,14 +38,15 @@ export const columns: ColumnDef<PubsWithGenres>[] = [
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
cell: TextInputCell,
|
cell: InputCell,
|
||||||
meta: { formSchema }
|
meta: { formSchema }
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "link",
|
accessorKey: "link",
|
||||||
header: "Link",
|
header: "Link",
|
||||||
cell: TextInputCell,
|
cell: InputCell,
|
||||||
meta: { formSchema }
|
meta: { formSchema }
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -64,12 +63,12 @@ export const columns: ColumnDef<PubsWithGenres>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "query_after_days",
|
accessorKey: "query_after_days",
|
||||||
header: "Query After (days)",
|
header: "Query After (days)",
|
||||||
cell: NumberInputCell,
|
|
||||||
meta: {
|
meta: {
|
||||||
step: 10,
|
step: 10
|
||||||
formSchema
|
},
|
||||||
|
cell: InputCell
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import GenreBadges from "app/ui/genreBadges"
|
||||||
import { actions } from "app/ui/tables/actions"
|
import { actions } from "app/ui/tables/actions"
|
||||||
import { TextInputCell } from "app/ui/tables/inputs/textInput"
|
import { TextInputCell } from "app/ui/tables/inputs/textInput"
|
||||||
import { selectCol } from "app/ui/tables/selectColumn"
|
import { selectCol } from "app/ui/tables/selectColumn"
|
||||||
import NumberInputCell from "app/ui/tables/inputs/numberInput"
|
import InputCell from "app/ui/tables/inputs/input"
|
||||||
import { formSchema } from "app/ui/forms/story"
|
import { formSchema } from "app/ui/forms/story"
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<StoryWithGenres>()
|
const columnHelper = createColumnHelper<StoryWithGenres>()
|
||||||
|
@ -27,7 +27,7 @@ export const columns: ColumnDef<StoryWithGenres>[] = [
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
cell: TextInputCell,
|
cell: InputCell,
|
||||||
meta: { formSchema }
|
meta: { formSchema }
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -45,7 +45,7 @@ export const columns: ColumnDef<StoryWithGenres>[] = [
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
cell: NumberInputCell,
|
cell: InputCell,
|
||||||
meta: {
|
meta: {
|
||||||
step: 50,
|
step: 50,
|
||||||
formSchema
|
formSchema
|
||||||
|
|
|
@ -9,14 +9,13 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { toast } from "@/components/ui/use-toast";
|
import { toast } from "@/components/ui/use-toast";
|
||||||
import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form";
|
import { Form, FormControl, FormField, FormItem, FormMessage } from "@/components/ui/form";
|
||||||
|
|
||||||
export function TextInputCell(props: CellContext<any, any>) {
|
export default function InputCell(props: CellContext<any, any>) {
|
||||||
const [isActive, setIsActive] = useState(false)
|
const [isActive, setIsActive] = useState(false)
|
||||||
|
|
||||||
const table = props.table.options.meta.tableName
|
const table = props.table.options.meta.tableName
|
||||||
const id = props.row.original.id
|
const id = props.row.original.id
|
||||||
const column = props.column.id
|
const column = props.column.id
|
||||||
const pathname = props.table.options.meta.pathname
|
const pathname = props.table.options.meta.pathname
|
||||||
const value = props.cell.getValue()
|
|
||||||
const formSchema = props.column.columnDef.meta.formSchema.pick({ [column]: true })
|
const formSchema = props.column.columnDef.meta.formSchema.pick({ [column]: true })
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof formSchema>>({
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
@ -26,6 +25,10 @@ export function TextInputCell(props: CellContext<any, any>) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const type = typeof props.cell.getValue()
|
||||||
|
console.log(type)
|
||||||
|
|
||||||
|
|
||||||
function onSubmit(value: z.infer<typeof formSchema>) {
|
function onSubmit(value: z.infer<typeof formSchema>) {
|
||||||
toast({
|
toast({
|
||||||
title: "You submitted the following values:",
|
title: "You submitted the following values:",
|
||||||
|
@ -38,11 +41,10 @@ export function TextInputCell(props: CellContext<any, any>) {
|
||||||
updateField({
|
updateField({
|
||||||
id,
|
id,
|
||||||
table,
|
table,
|
||||||
string: value[column],
|
[type]: value[column],
|
||||||
column,
|
column,
|
||||||
pathname
|
pathname
|
||||||
})
|
})
|
||||||
setIsActive(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onErrors(errors) {
|
function onErrors(errors) {
|
||||||
|
@ -63,7 +65,6 @@ export function TextInputCell(props: CellContext<any, any>) {
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
onKeyDown={e => {
|
onKeyDown={e => {
|
||||||
if (e.code === "Space" && !isActive) {
|
if (e.code === "Space" && !isActive) {
|
||||||
e.preventDefault()
|
|
||||||
setIsActive(true)
|
setIsActive(true)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -82,8 +83,9 @@ export function TextInputCell(props: CellContext<any, any>) {
|
||||||
<FormControl
|
<FormControl
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type={type}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
|
step={props.column.columnDef.meta.step}
|
||||||
{...field}
|
{...field}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
@ -91,7 +93,6 @@ export function TextInputCell(props: CellContext<any, any>) {
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
: <p>{props.cell.getValue()}</p>
|
: <p>{props.cell.getValue()}</p>
|
|
@ -1,20 +0,0 @@
|
||||||
"use client"
|
|
||||||
|
|
||||||
import { ComponentProps, Dispatch, SetStateAction } from "react"
|
|
||||||
|
|
||||||
export function TableInputContainer({ isActive, setIsActive, children }: ComponentProps<"div"> & { isActive: boolean, setIsActive: Dispatch<SetStateAction<boolean>> }) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onDoubleClick={() => setIsActive(prev => !prev)}
|
|
||||||
className="w-full h-fit flex items-center justify-center"
|
|
||||||
tabIndex={0}
|
|
||||||
onKeyDown={e => {
|
|
||||||
if (e.code === "Enter" && !isActive) {
|
|
||||||
setIsActive(true)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
"use client"
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { CellContext } from "@tanstack/react-table";
|
|
||||||
import { updateField } from "app/lib/update";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { useForm } from "react-hook-form";
|
|
||||||
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<any, any>) {
|
|
||||||
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()
|
|
||||||
console.log(`|${value}|`)
|
|
||||||
const formSchema = props.column.columnDef.meta.formSchema.pick({ [column]: true })
|
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof formSchema>>({
|
|
||||||
resolver: zodResolver(formSchema),
|
|
||||||
defaultValues: {
|
|
||||||
[column]: props.cell.getValue()
|
|
||||||
},
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
function onSubmit(value: z.infer<typeof formSchema>) {
|
|
||||||
toast({
|
|
||||||
title: "You submitted the following values:",
|
|
||||||
description: (
|
|
||||||
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
|
|
||||||
<code className="text-white">{JSON.stringify(value, null, 2)}</code>
|
|
||||||
</pre>
|
|
||||||
),
|
|
||||||
})
|
|
||||||
updateField({
|
|
||||||
id,
|
|
||||||
table,
|
|
||||||
number: value[column],
|
|
||||||
column,
|
|
||||||
pathname
|
|
||||||
})
|
|
||||||
setIsActive(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onErrors(errors) {
|
|
||||||
toast({
|
|
||||||
title: "You have errors",
|
|
||||||
description: (
|
|
||||||
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
|
|
||||||
<code className="text-white">{JSON.stringify(errors, null, 2)}</code>
|
|
||||||
</pre>
|
|
||||||
),
|
|
||||||
})
|
|
||||||
console.log(JSON.stringify(errors))
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onDoubleClick={() => setIsActive(prev => !prev)}
|
|
||||||
className="w-full h-fit flex items-center justify-center"
|
|
||||||
tabIndex={0}
|
|
||||||
onKeyDown={e => {
|
|
||||||
if (e.code === "Space" && !isActive) {
|
|
||||||
e.preventDefault()
|
|
||||||
setIsActive(true)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{isActive ?
|
|
||||||
<Form {...form}>
|
|
||||||
<form onSubmit={form.handleSubmit(onSubmit, onErrors)}
|
|
||||||
>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name={column}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem
|
|
||||||
onBlur={() => setIsActive(false)}
|
|
||||||
>
|
|
||||||
<FormControl
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
type="number"
|
|
||||||
autoFocus={true}
|
|
||||||
step={props.column.columnDef.meta?.step}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
: <p>{props.cell.getValue()}</p>
|
|
||||||
}
|
|
||||||
</div >
|
|
||||||
)
|
|
||||||
}
|
|
Loading…
Reference in New Issue