import { Tab } from "@headlessui/react"; import React, { useEffect, useState } from "react"; import TextInput from "../TextInput"; import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import { useRouter } from "next/router"; import useCollectionStore from "@/store/collections"; import useLinkStore from "@/store/links"; import { useSession } from "next-auth/react"; import CollectionSelection from "../InputSelect/CollectionSelection"; export default function New() { const { data } = useSession(); const [link, setLink] = useState({ name: "", url: "", description: "", tags: [], screenshotPath: "", pdfPath: "", readabilityPath: "", textContent: "", collection: { name: "", ownerId: data?.user.id as number, }, }); const { updateLink, addLink } = useLinkStore(); const router = useRouter(); const { collections } = useCollectionStore(); const setCollection = (e: any) => { if (e?.__isNew__) e.value = null; setLink({ ...link, collection: { id: e?.value, name: e?.label, ownerId: e?.ownerId }, }); }; useEffect(() => { if (router.query.id) { const currentCollection = collections.find( (e) => e.id == Number(router.query.id) ); if ( currentCollection && currentCollection.ownerId && router.asPath.startsWith("/collections/") ) setLink({ ...link, collection: { id: currentCollection.id, name: currentCollection.name, ownerId: currentCollection.ownerId, }, }); } else setLink({ ...link, collection: { // id: , name: "Unorganized", ownerId: data?.user.id as number, }, }); }, []); return (
`${ selected ? "btn-primary" : "btn-ghost" } outline-none rounded-md btn btn-sm` } > Link {/* `${ selected ? "btn-primary" : "btn-ghost" } outline-none rounded-md btn btn-sm` } > File */} `${ selected ? "btn-primary" : "btn-ghost" } outline-none rounded-md btn btn-sm` } > Collection

Address (URL)

setLink({ ...link, url: e.target.value })} placeholder="e.g. http://example.com/" className="bg-base-200" />

Collection

{link.collection.name ? ( ) : null}
{/* Content 2 */} Content 3
); }