many changes across the app
This commit is contained in:
parent
c1d1d4a4a2
commit
0d0e53218f
|
@ -19,6 +19,7 @@ import Dropdown from "./Dropdown";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
import Modal from "./Modal";
|
import Modal from "./Modal";
|
||||||
import EditLink from "./Modal/EditLink";
|
import EditLink from "./Modal/EditLink";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
export default function ({
|
export default function ({
|
||||||
link,
|
link,
|
||||||
|
@ -57,7 +58,7 @@ export default function ({
|
||||||
width={32}
|
width={32}
|
||||||
height={32}
|
height={32}
|
||||||
alt=""
|
alt=""
|
||||||
className="select-none mt-3 z-10 rounded-md"
|
className="select-none mt-3 z-10 rounded-md shadow"
|
||||||
draggable="false"
|
draggable="false"
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
@ -84,18 +85,20 @@ export default function ({
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sky-400 text-sm font-medium">{link.title}</p>
|
<p className="text-sky-400 text-sm font-medium">{link.title}</p>
|
||||||
<div className="flex gap-3 items-center flex-wrap my-3">
|
<div className="flex gap-3 items-center flex-wrap my-3">
|
||||||
|
<Link href={`/collections/${link.collection.id}`}>
|
||||||
<div className="flex items-center gap-1 cursor-pointer hover:opacity-60 duration-100">
|
<div className="flex items-center gap-1 cursor-pointer hover:opacity-60 duration-100">
|
||||||
<FontAwesomeIcon icon={faFolder} className="w-4 text-sky-300" />
|
<FontAwesomeIcon icon={faFolder} className="w-4 text-sky-300" />
|
||||||
<p className="text-sky-900">{link.collection.name}</p>
|
<p className="text-sky-900">{link.collection.name}</p>
|
||||||
</div>
|
</div>
|
||||||
|
</Link>
|
||||||
|
|
||||||
<div className="flex gap-1 items-center flex-wrap">
|
<div className="flex gap-1 items-center flex-wrap">
|
||||||
{link.tags.map((e, i) => (
|
{link.tags.map((e, i) => (
|
||||||
<p
|
<Link key={i} href={`/tags/${e.id}`}>
|
||||||
key={i}
|
<p className="px-2 py-1 bg-sky-200 text-sky-700 text-xs rounded-3xl cursor-pointer hover:bg-sky-100 duration-100">
|
||||||
className="px-2 py-1 bg-sky-200 text-sky-700 text-xs rounded-3xl cursor-pointer hover:bg-sky-100 duration-100"
|
|
||||||
>
|
|
||||||
# {e.name}
|
# {e.name}
|
||||||
</p>
|
</p>
|
||||||
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default function AddCollection({
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 sm:w-[35rem] w-80">
|
<div className="flex flex-col gap-3 sm:w-[33rem] w-72">
|
||||||
<p className="font-bold text-sky-300 text-center">Delete Collection</p>
|
<p className="font-bold text-sky-300 text-center">Delete Collection</p>
|
||||||
|
|
||||||
<p className="text-sky-900 select-none text-center">
|
<p className="text-sky-900 select-none text-center">
|
||||||
|
|
|
@ -5,11 +5,17 @@
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faClose, faPenToSquare } from "@fortawesome/free-solid-svg-icons";
|
import {
|
||||||
|
faClose,
|
||||||
|
faPenToSquare,
|
||||||
|
faTrashCan,
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import useCollectionStore from "@/store/collections";
|
import useCollectionStore from "@/store/collections";
|
||||||
import { ExtendedCollection } from "@/types/global";
|
import { ExtendedCollection } from "@/types/global";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import getPublicUserDataByEmail from "@/lib/client/getPublicUserDataByEmail";
|
import getPublicUserDataByEmail from "@/lib/client/getPublicUserDataByEmail";
|
||||||
|
import Modal from "@/components/Modal";
|
||||||
|
import DeleteCollection from "@/components/Modal/DeleteCollection";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
toggleCollectionModal: Function;
|
toggleCollectionModal: Function;
|
||||||
|
@ -27,6 +33,12 @@ export default function EditCollection({
|
||||||
|
|
||||||
const { updateCollection } = useCollectionStore();
|
const { updateCollection } = useCollectionStore();
|
||||||
|
|
||||||
|
const [deleteCollectionModal, setDeleteCollectionModal] = useState(false);
|
||||||
|
|
||||||
|
const toggleDeleteCollectionModal = () => {
|
||||||
|
setDeleteCollectionModal(!deleteCollectionModal);
|
||||||
|
};
|
||||||
|
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
|
@ -250,13 +262,41 @@ export default function EditCollection({
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
<div className="flex flex-col justify-center items-center gap-2 mt-2">
|
||||||
<div
|
<div
|
||||||
className="mx-auto mt-2 bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
className="bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faPenToSquare} className="h-5" />
|
<FontAwesomeIcon icon={faPenToSquare} className="h-5" />
|
||||||
Edit Collection
|
Edit Collection
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-center gap-2">
|
||||||
|
<hr className="w-16 border" />
|
||||||
|
|
||||||
|
<p className="text-gray-400 font-bold">OR</p>
|
||||||
|
|
||||||
|
<hr className="w-16 border" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
onClick={() => {
|
||||||
|
toggleDeleteCollectionModal();
|
||||||
|
}}
|
||||||
|
className="w-fit inline-flex rounded-md cursor-pointer bg-red-500 hover:bg-red-400 duration-100 p-2"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faTrashCan} className="w-4 h-4 text-white" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{deleteCollectionModal ? (
|
||||||
|
<Modal toggleModal={toggleDeleteCollectionModal}>
|
||||||
|
<DeleteCollection
|
||||||
|
collection={activeCollection}
|
||||||
|
toggleCollectionModal={toggleDeleteCollectionModal}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { ExtendedLink } from "@/types/global";
|
import { ExtendedLink } from "@/types/global";
|
||||||
import { faPenToSquare } from "@fortawesome/free-regular-svg-icons";
|
import { faPenToSquare } from "@fortawesome/free-regular-svg-icons";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
|
import { faTrashCan } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
toggleLinkModal: Function;
|
toggleLinkModal: Function;
|
||||||
|
@ -19,7 +20,7 @@ type Props = {
|
||||||
export default function EditLink({ toggleLinkModal, link }: Props) {
|
export default function EditLink({ toggleLinkModal, link }: Props) {
|
||||||
const [currentLink, setCurrentLink] = useState<ExtendedLink>(link);
|
const [currentLink, setCurrentLink] = useState<ExtendedLink>(link);
|
||||||
|
|
||||||
const { updateLink } = useLinkStore();
|
const { updateLink, removeLink } = useLinkStore();
|
||||||
|
|
||||||
const shortendURL = new URL(link.url).host.toLowerCase();
|
const shortendURL = new URL(link.url).host.toLowerCase();
|
||||||
|
|
||||||
|
@ -85,13 +86,33 @@ export default function EditLink({ toggleLinkModal, link }: Props) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col justify-center items-center gap-2 mt-2">
|
||||||
<div
|
<div
|
||||||
className="mx-auto mt-2 bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
className="bg-sky-500 text-white flex items-center gap-2 py-2 px-5 rounded-md select-none font-bold cursor-pointer duration-100 hover:bg-sky-400"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faPenToSquare} className="h-5" />
|
<FontAwesomeIcon icon={faPenToSquare} className="h-5" />
|
||||||
Edit Link
|
Edit Link
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-center gap-2">
|
||||||
|
<hr className="w-16 border" />
|
||||||
|
|
||||||
|
<p className="text-gray-400 font-bold">OR</p>
|
||||||
|
|
||||||
|
<hr className="w-16 border" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
onClick={() => {
|
||||||
|
removeLink(link);
|
||||||
|
toggleLinkModal();
|
||||||
|
}}
|
||||||
|
className="w-fit inline-flex rounded-md cursor-pointer bg-red-500 hover:bg-red-400 duration-100 p-2"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faTrashCan} className="w-4 h-4 text-white" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import { ReactNode } from "react";
|
import { MouseEventHandler, ReactNode } from "react";
|
||||||
import ClickAwayHandler from "@/components/ClickAwayHandler";
|
import ClickAwayHandler from "@/components/ClickAwayHandler";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
toggleModal: Function;
|
toggleModal: Function;
|
||||||
|
@ -13,9 +15,18 @@ type Props = {
|
||||||
|
|
||||||
export default function ({ toggleModal, children }: Props) {
|
export default function ({ toggleModal, children }: Props) {
|
||||||
return (
|
return (
|
||||||
<div className="fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 flex items-center fade-in z-30">
|
<div className="overflow-y-auto py-2 fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 flex items-center fade-in z-30">
|
||||||
<ClickAwayHandler onClickOutside={toggleModal} className="w-fit mx-auto">
|
<ClickAwayHandler onClickOutside={toggleModal} className="w-fit m-auto">
|
||||||
<div className="slide-up border-sky-100 rounded-md border-solid border shadow-lg p-5 bg-white">
|
<div className="slide-up relative border-sky-100 rounded-md border-solid border shadow-lg p-5 bg-white">
|
||||||
|
<div
|
||||||
|
onClick={toggleModal as MouseEventHandler<HTMLDivElement>}
|
||||||
|
className="absolute top-5 left-5 inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faChevronLeft}
|
||||||
|
className="w-4 h-4 text-gray-500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</ClickAwayHandler>
|
</ClickAwayHandler>
|
||||||
|
|
|
@ -15,12 +15,13 @@ import {
|
||||||
faChevronDown,
|
faChevronDown,
|
||||||
faBars,
|
faBars,
|
||||||
} from "@fortawesome/free-solid-svg-icons";
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Dropdown from "@/components/Dropdown";
|
import Dropdown from "@/components/Dropdown";
|
||||||
import Modal from "./Modal";
|
import Modal from "./Modal";
|
||||||
import AddLink from "./Modal/AddLink";
|
import AddLink from "./Modal/AddLink";
|
||||||
import ClickAwayHandler from "./ClickAwayHandler";
|
import ClickAwayHandler from "./ClickAwayHandler";
|
||||||
import Sidebar from "./Sidebar";
|
import Sidebar from "./Sidebar";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
@ -32,8 +33,14 @@ export default function () {
|
||||||
const [linkModal, setLinkModal] = useState(false);
|
const [linkModal, setLinkModal] = useState(false);
|
||||||
const [sidebar, setSidebar] = useState(false);
|
const [sidebar, setSidebar] = useState(false);
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
window.addEventListener("resize", () => setSidebar(false));
|
window.addEventListener("resize", () => setSidebar(false));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSidebar(false);
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
const toggleSidebar = () => {
|
const toggleSidebar = () => {
|
||||||
setSidebar(!sidebar);
|
setSidebar(!sidebar);
|
||||||
};
|
};
|
||||||
|
@ -123,7 +130,7 @@ export default function () {
|
||||||
{sidebar ? (
|
{sidebar ? (
|
||||||
<div className="fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 flex items-center fade-in z-30">
|
<div className="fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 flex items-center fade-in z-30">
|
||||||
<ClickAwayHandler onClickOutside={toggleSidebar}>
|
<ClickAwayHandler onClickOutside={toggleSidebar}>
|
||||||
<div className="slide-right">
|
<div className="slide-right shadow-lg">
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
</div>
|
</div>
|
||||||
</ClickAwayHandler>
|
</ClickAwayHandler>
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import React, { ReactElement } from "react";
|
import React, { ReactElement, useEffect, useState } from "react";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
interface SidebarItemProps {
|
interface SidebarItemProps {
|
||||||
text: string;
|
text: string;
|
||||||
|
@ -13,13 +14,25 @@ interface SidebarItemProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ({ text, icon, path }: SidebarItemProps) {
|
export default function ({ text, icon, path }: SidebarItemProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [active, setActive] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (router.asPath === path) setActive(true);
|
||||||
|
else setActive(false);
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={path}>
|
<Link href={path}>
|
||||||
<div className="hover:bg-gray-50 hover:outline outline-sky-100 outline-1 duration-100 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2">
|
<div
|
||||||
|
className={`${
|
||||||
|
active ? "bg-sky-500" : "hover:bg-gray-50 hover:outline bg-gray-100"
|
||||||
|
} outline-sky-100 outline-1 duration-100 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2`}
|
||||||
|
>
|
||||||
{React.cloneElement(icon, {
|
{React.cloneElement(icon, {
|
||||||
className: "w-4 text-sky-300",
|
className: `w-4 ${active ? "text-white" : "text-sky-300"}`,
|
||||||
})}
|
})}
|
||||||
<p className="text-sky-900">{text}</p>
|
<p className={`${active ? "text-white" : "text-sky-900"}`}>{text}</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,12 +14,21 @@ import {
|
||||||
import SidebarItem from "./SidebarItem";
|
import SidebarItem from "./SidebarItem";
|
||||||
import useTagStore from "@/store/tags";
|
import useTagStore from "@/store/tags";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
|
|
||||||
const { tags } = useTagStore();
|
const { tags } = useTagStore();
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const [active, setActive] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setActive(router.asPath);
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-gray-100 h-screen w-64 xl:w-80 p-2 overflow-y-auto border-solid border-r-sky-100 border z-20">
|
<div className="bg-gray-100 h-screen w-64 xl:w-80 p-2 overflow-y-auto border-solid border-r-sky-100 border z-20">
|
||||||
<p className="p-2 text-sky-500 font-bold text-xl mb-5 leading-4">
|
<p className="p-2 text-sky-500 font-bold text-xl mb-5 leading-4">
|
||||||
|
@ -27,16 +36,48 @@ export default function () {
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<Link href="/links">
|
<Link href="/links">
|
||||||
<div className="hover:bg-gray-50 hover:outline outline-sky-100 outline-1 duration-100 text-sky-900 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2">
|
<div
|
||||||
<FontAwesomeIcon icon={faBookmark} className="w-4 text-sky-300" />
|
className={`${
|
||||||
<p>All Links</p>
|
active === "/links"
|
||||||
|
? "bg-sky-500"
|
||||||
|
: "hover:bg-gray-50 hover:outline bg-gray-100"
|
||||||
|
} outline-sky-100 outline-1 duration-100 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2`}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faBookmark}
|
||||||
|
className={`w-4 ${
|
||||||
|
active === "/links" ? "text-white" : "text-sky-300"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<p
|
||||||
|
className={`${active === "/links" ? "text-white" : "text-sky-900"}`}
|
||||||
|
>
|
||||||
|
All Links
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<Link href="/collections">
|
<Link href="/collections">
|
||||||
<div className="hover:bg-gray-50 hover:outline outline-sky-100 outline-1 duration-100 text-sky-900 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2">
|
<div
|
||||||
<FontAwesomeIcon icon={faBox} className="w-4 text-sky-300" />
|
className={`${
|
||||||
<p>All Collections</p>
|
active === "/collections"
|
||||||
|
? "bg-sky-500"
|
||||||
|
: "hover:bg-gray-50 hover:outline bg-gray-100"
|
||||||
|
} outline-sky-100 outline-1 duration-100 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2`}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faBox}
|
||||||
|
className={`w-4 ${
|
||||||
|
active === "/collections" ? "text-white" : "text-sky-300"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<p
|
||||||
|
className={`${
|
||||||
|
active === "/collections" ? "text-white" : "text-sky-900"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
All Collections
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
|
|
|
@ -41,5 +41,5 @@ export default function ({ children }: Props) {
|
||||||
}, [status]);
|
}, [status]);
|
||||||
|
|
||||||
if (status !== "loading" && !redirect) return <>{children}</>;
|
if (status !== "loading" && !redirect) return <>{children}</>;
|
||||||
else return <Loader />;
|
// else return <Loader />;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,5 +36,5 @@ export default function ({ children }: Props) {
|
||||||
);
|
);
|
||||||
else if ((status === "unauthenticated" && !redirect) || !routeExists)
|
else if ((status === "unauthenticated" && !redirect) || !routeExists)
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
else return <Loader />;
|
else return <></>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,13 @@ export default async function (collection: { id: number }, userId: number) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
fs.rmdirSync(`data/archives/${collection.id}`, { recursive: true });
|
fs.rmdirSync(`data/archives/${collection.id}`, { recursive: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(
|
||||||
|
"Collection's archive directory wasn't deleted most likely because it didn't exist..."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return await prisma.collection.delete({
|
return await prisma.collection.delete({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import { prisma } from "@/lib/api/db";
|
import { prisma } from "@/lib/api/db";
|
||||||
import { ExtendedLink } from "@/types/global";
|
import { ExtendedLink } from "@/types/global";
|
||||||
import { Link, UsersAndCollections } from "@prisma/client";
|
import { UsersAndCollections } from "@prisma/client";
|
||||||
import getPermission from "@/lib/api/getPermission";
|
import getPermission from "@/lib/api/getPermission";
|
||||||
|
|
||||||
export default async function (link: ExtendedLink, userId: number) {
|
export default async function (link: ExtendedLink, userId: number) {
|
||||||
|
@ -17,10 +17,23 @@ export default async function (link: ExtendedLink, userId: number) {
|
||||||
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
|
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (link.collection.ownerId) {
|
||||||
|
const collectionIsAccessible = await getPermission(
|
||||||
|
userId,
|
||||||
|
link.collection.id
|
||||||
|
);
|
||||||
|
|
||||||
|
const memberHasAccess = collectionIsAccessible?.members.some(
|
||||||
|
(e: UsersAndCollections) => e.userId === userId && e.canCreate
|
||||||
|
);
|
||||||
|
|
||||||
if (!(collectionIsAccessible?.ownerId === userId || memberHasAccess))
|
if (!(collectionIsAccessible?.ownerId === userId || memberHasAccess))
|
||||||
return { response: "Collection is not accessible.", status: 401 };
|
return { response: "Collection is not accessible.", status: 401 };
|
||||||
|
} else {
|
||||||
|
link.collection.ownerId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
const updatedLink: Link = await prisma.link.update({
|
const updatedLink: ExtendedLink = await prisma.link.update({
|
||||||
where: {
|
where: {
|
||||||
id: link.id,
|
id: link.id,
|
||||||
},
|
},
|
||||||
|
@ -60,6 +73,10 @@ export default async function (link: ExtendedLink, userId: number) {
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
include: {
|
||||||
|
tags: true,
|
||||||
|
collection: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return { response: updatedLink, status: 200 };
|
return { response: updatedLink, status: 200 };
|
||||||
|
|
|
@ -63,9 +63,12 @@ const useLinkStore = create<LinkStore>()((set) => ({
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
links: state.links.map((e) => (e.id === link.id ? link : e)),
|
links: state.links.map((e) =>
|
||||||
|
e.id === data.response.id ? data.response : e
|
||||||
|
),
|
||||||
}));
|
}));
|
||||||
useTagStore.getState().setTags();
|
useTagStore.getState().setTags();
|
||||||
|
useCollectionStore.getState().setCollections();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeLink: async (link) => {
|
removeLink: async (link) => {
|
||||||
|
|
|
@ -63,16 +63,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.slide-right {
|
.slide-right {
|
||||||
animation: slide-right-animation 100ms;
|
animation: slide-right-animation 200ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes slide-right-animation {
|
@keyframes slide-right-animation {
|
||||||
0% {
|
0% {
|
||||||
transform: translateX(-25%);
|
transform: translateX(-100%);
|
||||||
opacity: 0;
|
|
||||||
}
|
}
|
||||||
100% {
|
100% {
|
||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
opacity: 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue