Files
archived-linsa/web/components/routes/link/form/manage.tsx
Aslam 2d270706a5 fix: link (#115)
* start

* .

* seeding connections

* .

* wip

* wip: learning state

* wip: notes section

* wip: many

* topics

* chore: update schema

* update package

* update sidebar

* update page section

* feat: profile

* fix: remove z index

* fix: wrong type

* add avatar

* add avatar

* wip

* .

* store page section key

* remove atom page section

* fix rerender

* fix rerender

* fix rerender

* fix rerender

* fix link

* search light/dark mode

* bubble menu ui

* .

* fix: remove unecessary code

* chore: mark as old for old schema

* chore: adapt new schema

* fix: add topic schema but null for now

* fix: add icon on personal link

* fix: list item

* fix: set url fetched when editing

* fix: remove image

* feat: add icon to link

* feat: custom url zod validation

* fix: metadata test

* chore: update utils

* fix: link

* fix: url fetcher

* .

* .

* fix: add link, section

* chore: seeder

* .

* .

* .

* .

* fix: change checkbox to learning state

* fix: click outside editing form

* feat: constant

* chore: move to master folder

* chore: adapt new schema

* chore: cli for new schema

* fix: new schema for dev seed

* fix: seeding

* update package

* chore: forcegraph seed

* bottombar

* if isEdit delete icon

* showCreate X button

* .

* options

* chore: implement topic from public global group

* chore: update learning state

* fix: change implementation for outside click

* chore: implement new form param

* chore: update env example

* feat: link form refs exception

* new page button layout, link topic search fixed

* chore: enable topic

* chore: update seed

* profile

* chore: move framer motion package from root to web and add nuqs

* chore: add LearningStateValue

* chore: implement active state

* profile

* chore: use fancy switch and update const

* feat: filter implementation

* dropdown menu

* .

* sidebar topics

* topic selected color

* feat: topic detail

* fix: collapsible page

* pages - sorted by, layout, visible mode

* .

* .

* .

* topic status sidebar

* topic button and count

* fix: topic

* page delete/topic buttons

* search ui

* selected topic for page

* selected topic status sidebar

* removed footer

* update package

* .

---------

Co-authored-by: Nikita <github@nikiv.dev>
Co-authored-by: marshennikovaolga <marshennikova@gmail.com>
Co-authored-by: Kisuyo <ig.intr3st@gmail.com>
2024-08-26 15:35:00 +03:00

101 lines
3.0 KiB
TypeScript

"use client"
import { Button } from "@/components/ui/button"
import { linkEditIdAtom, linkShowCreateAtom } from "@/store/link"
import { useAtom } from "jotai"
import React, { useEffect, useRef, useState } from "react"
import { useKey } from "react-use"
import { globalLinkFormExceptionRefsAtom, LinkForm } from "./link-form"
import { LaIcon } from "@/components/custom/la-icon"
import LinkOptions from "@/components/LinkOptions"
// import { FloatingButton } from "./partial/floating-button"
const LinkManage: React.FC = () => {
const [showCreate, setShowCreate] = useAtom(linkShowCreateAtom)
const [editId, setEditId] = useAtom(linkEditIdAtom)
const [, setGlobalExceptionRefs] = useAtom(globalLinkFormExceptionRefsAtom)
const [showOptions, setShowOptions] = useState(false)
const optionsRef = useRef<HTMLDivElement>(null)
const buttonRef = useRef<HTMLButtonElement>(null)
const toggleForm = (event: React.MouseEvent) => {
event.stopPropagation()
if (showCreate) return
setShowCreate(prev => !prev)
}
const clickOptionsButton = (e: React.MouseEvent) => {
e.preventDefault()
setShowOptions(prev => !prev)
}
const handleFormClose = () => {
setShowCreate(false)
}
const handleFormFail = () => {}
// wipes the data from the form when the form is closed
React.useEffect(() => {
if (!showCreate) {
setEditId(null)
}
}, [showCreate, setEditId])
useKey("Escape", handleFormClose)
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (optionsRef.current && !optionsRef.current.contains(event.target as Node)) {
setShowOptions(false)
}
}
if (showOptions) {
document.addEventListener("mousedown", handleClickOutside)
}
return () => {
document.removeEventListener("mousedown", handleClickOutside)
}
}, [showOptions])
/*
* This code means that when link form is opened, these refs will be added as an exception to the click outside handler
*/
React.useEffect(() => {
setGlobalExceptionRefs([optionsRef, buttonRef])
}, [setGlobalExceptionRefs])
return (
<>
{showCreate && <LinkForm onClose={handleFormClose} onSuccess={handleFormClose} onFail={handleFormFail} />}
<div className="absolute bottom-0 m-0 flex w-full list-none bg-inherit p-2.5 text-center align-middle font-semibold leading-[13px] no-underline">
<div className="mx-auto flex flex-row items-center justify-center gap-2">
<Button
variant="ghost"
onClick={toggleForm}
className={editId || showCreate ? "text-red-500 hover:bg-red-500/50 hover:text-white" : ""}
>
<LaIcon name={showCreate ? "X" : editId ? "Trash" : "Plus"} />
</Button>
<div className="relative" ref={optionsRef}>
{showOptions && <LinkOptions />}
<Button ref={buttonRef} variant="ghost" onClick={clickOptionsButton}>
<LaIcon name="Ellipsis" />
</Button>
</div>
</div>
</div>
</>
)
}
LinkManage.displayName = "LinkManage"
export { LinkManage }
/* <FloatingButton ref={buttonRef} onClick={toggleForm} isOpen={showCreate} /> */