responsive sidenav + code refactoring

This commit is contained in:
Daniel
2023-05-01 00:24:40 +03:30
parent 57b2e36abd
commit c1d1d4a4a2
13 changed files with 279 additions and 173 deletions
+3 -3
View File
@@ -4,11 +4,11 @@
// 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 React from "react";
import MainLayout from "@/layouts/MainLayout";
import "@/styles/globals.css";
import { SessionProvider } from "next-auth/react";
import type { AppProps } from "next/app";
import Head from "next/head";
import AuthRedirect from "@/layouts/AuthRedirect";
export default function App({ Component, pageProps }: AppProps) {
return (
@@ -35,9 +35,9 @@ export default function App({ Component, pageProps }: AppProps) {
/>
<link rel="manifest" href="/site.webmanifest" />
</Head>
<MainLayout>
<AuthRedirect>
<Component {...pageProps} />
</MainLayout>
</AuthRedirect>
</SessionProvider>
);
}
-4
View File
@@ -32,16 +32,12 @@ export const authOptions: AuthOptions = {
},
});
console.log(findUser);
let passwordMatches: boolean = false;
if (findUser?.password) {
passwordMatches = bcrypt.compareSync(password, findUser.password);
}
console.log(passwordMatches);
if (passwordMatches) {
return {
id: findUser?.id,
+81 -79
View File
@@ -22,6 +22,7 @@ import {
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import Dashboard from "@/layouts/Dashboard";
export default function () {
const router = useRouter();
@@ -61,89 +62,90 @@ export default function () {
}, [links, router, collections]);
return (
// ml-80
<div className="p-5 flex flex-col gap-5 w-full">
<div className="flex gap-3 items-center">
<div className="flex gap-2 items-center">
<FontAwesomeIcon icon={faFolder} className="w-5 h-5 text-sky-300" />
<p className="text-lg text-sky-900">{activeCollection?.name}</p>
</div>
<div className="relative">
<div
onClick={() => setExpandDropdown(!expandDropdown)}
id="edit-dropdown"
className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
<FontAwesomeIcon
icon={faEllipsis}
id="edit-dropdown"
className="w-4 h-4 text-gray-500"
/>
<Dashboard>
<div className="p-5 flex flex-col gap-5 w-full">
<div className="flex gap-3 items-center">
<div className="flex gap-2 items-center">
<FontAwesomeIcon icon={faFolder} className="w-5 h-5 text-sky-300" />
<p className="text-lg text-sky-900">{activeCollection?.name}</p>
</div>
{expandDropdown ? (
<Dropdown
items={[
{
name: "Add Link Here",
icon: <FontAwesomeIcon icon={faAdd} />,
onClick: () => {
toggleLinkModal();
setExpandDropdown(false);
},
},
{
name: "Edit Collection",
icon: <FontAwesomeIcon icon={faPenToSquare} />,
onClick: () => {
toggleEditCollectionModal();
setExpandDropdown(false);
},
},
{
name: "Delete Collection",
icon: <FontAwesomeIcon icon={faTrashCan} />,
onClick: () => {
toggleDeleteCollectionModal();
setExpandDropdown(false);
},
},
]}
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "edit-dropdown") setExpandDropdown(false);
}}
className="absolute top-7 left-0 z-10 w-44"
/>
) : null}
{linkModal ? (
<Modal toggleModal={toggleLinkModal}>
<AddLink toggleLinkModal={toggleLinkModal} />
</Modal>
) : null}
{editCollectionModal && activeCollection ? (
<Modal toggleModal={toggleEditCollectionModal}>
<EditCollection
toggleCollectionModal={toggleEditCollectionModal}
collection={activeCollection}
<div className="relative">
<div
onClick={() => setExpandDropdown(!expandDropdown)}
id="edit-dropdown"
className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
<FontAwesomeIcon
icon={faEllipsis}
id="edit-dropdown"
className="w-4 h-4 text-gray-500"
/>
</Modal>
) : null}
{deleteCollectionModal && activeCollection ? (
<Modal toggleModal={toggleDeleteCollectionModal}>
<DeleteCollection
collection={activeCollection}
toggleCollectionModal={toggleDeleteCollectionModal}
</div>
{expandDropdown ? (
<Dropdown
items={[
{
name: "Add Link Here",
icon: <FontAwesomeIcon icon={faAdd} />,
onClick: () => {
toggleLinkModal();
setExpandDropdown(false);
},
},
{
name: "Edit Collection",
icon: <FontAwesomeIcon icon={faPenToSquare} />,
onClick: () => {
toggleEditCollectionModal();
setExpandDropdown(false);
},
},
{
name: "Delete Collection",
icon: <FontAwesomeIcon icon={faTrashCan} />,
onClick: () => {
toggleDeleteCollectionModal();
setExpandDropdown(false);
},
},
]}
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "edit-dropdown") setExpandDropdown(false);
}}
className="absolute top-7 left-0 z-10 w-44"
/>
</Modal>
) : null}
) : null}
{linkModal ? (
<Modal toggleModal={toggleLinkModal}>
<AddLink toggleLinkModal={toggleLinkModal} />
</Modal>
) : null}
{editCollectionModal && activeCollection ? (
<Modal toggleModal={toggleEditCollectionModal}>
<EditCollection
toggleCollectionModal={toggleEditCollectionModal}
collection={activeCollection}
/>
</Modal>
) : null}
{deleteCollectionModal && activeCollection ? (
<Modal toggleModal={toggleDeleteCollectionModal}>
<DeleteCollection
collection={activeCollection}
toggleCollectionModal={toggleDeleteCollectionModal}
/>
</Modal>
) : null}
</div>
</div>
{linksByCollection.map((e, i) => {
return <LinkList key={i} link={e} count={i} />;
})}
</div>
{linksByCollection.map((e, i) => {
return <LinkList key={i} link={e} count={i} />;
})}
</div>
</Dashboard>
);
}
+55 -52
View File
@@ -16,6 +16,7 @@ import Dropdown from "@/components/Dropdown";
import { useState } from "react";
import Modal from "@/components/Modal";
import AddCollection from "@/components/Modal/AddCollection";
import Dashboard from "@/layouts/Dashboard";
export default function () {
const { collections } = useCollectionStore();
@@ -29,64 +30,66 @@ export default function () {
return (
// ml-80
<div className="p-5">
<div className="flex gap-3 items-center mb-5">
<div className="flex gap-2 items-center">
<FontAwesomeIcon icon={faBox} className="w-5 h-5 text-sky-300" />
<p className="text-lg text-sky-900">All Collections</p>
</div>
<div className="relative">
<div
onClick={() => setExpandDropdown(!expandDropdown)}
id="edit-dropdown"
className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
<FontAwesomeIcon
icon={faEllipsis}
id="edit-dropdown"
className="w-4 h-4 text-gray-500"
/>
<Dashboard>
<div className="p-5">
<div className="flex gap-3 items-center mb-5">
<div className="flex gap-2 items-center">
<FontAwesomeIcon icon={faBox} className="w-5 h-5 text-sky-300" />
<p className="text-lg text-sky-900">All Collections</p>
</div>
{expandDropdown ? (
<Dropdown
items={[
{
name: "New",
icon: <FontAwesomeIcon icon={faAdd} />,
onClick: () => {
toggleCollectionModal();
setExpandDropdown(false);
<div className="relative">
<div
onClick={() => setExpandDropdown(!expandDropdown)}
id="edit-dropdown"
className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
<FontAwesomeIcon
icon={faEllipsis}
id="edit-dropdown"
className="w-4 h-4 text-gray-500"
/>
</div>
{expandDropdown ? (
<Dropdown
items={[
{
name: "New",
icon: <FontAwesomeIcon icon={faAdd} />,
onClick: () => {
toggleCollectionModal();
setExpandDropdown(false);
},
},
},
]}
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "edit-dropdown") setExpandDropdown(false);
}}
className="absolute top-7 left-0 w-36"
/>
]}
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "edit-dropdown") setExpandDropdown(false);
}}
className="absolute top-7 left-0 w-36"
/>
) : null}
</div>
{linkModal ? (
<Modal toggleModal={toggleCollectionModal}>
<AddCollection toggleCollectionModal={toggleCollectionModal} />
</Modal>
) : null}
</div>
<div className="flex flex-wrap gap-5">
{collections.map((e, i) => {
return <CollectionCard key={i} collection={e} />;
})}
{linkModal ? (
<Modal toggleModal={toggleCollectionModal}>
<AddCollection toggleCollectionModal={toggleCollectionModal} />
</Modal>
) : null}
</div>
<div className="flex flex-wrap gap-5">
{collections.map((e, i) => {
return <CollectionCard key={i} collection={e} />;
})}
<div
className="p-5 bg-gray-100 h-40 w-60 rounded-md border-sky-100 border-solid border flex flex-col gap-4 justify-center items-center cursor-pointer hover:bg-gray-50 duration-100"
onClick={toggleCollectionModal}
>
<p className="text-sky-900">New Collection</p>
<FontAwesomeIcon icon={faPlus} className="w-8 h-8 text-sky-500" />
<div
className="p-5 bg-gray-100 h-40 w-60 rounded-md border-sky-100 border-solid border flex flex-col gap-4 justify-center items-center cursor-pointer hover:bg-gray-50 duration-100"
onClick={toggleCollectionModal}
>
<p className="text-sky-900">New Collection</p>
<FontAwesomeIcon icon={faPlus} className="w-8 h-8 text-sky-500" />
</div>
</div>
</div>
</div>
</Dashboard>
);
}
+15 -9
View File
@@ -4,6 +4,7 @@
// 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 LinkList from "@/components/LinkList";
import Dashboard from "@/layouts/Dashboard";
import useLinkStore from "@/store/links";
import { faBookmark } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -12,16 +13,21 @@ export default function Links() {
const { links } = useLinkStore();
return (
<div className="p-5 flex flex-col gap-5 w-full">
<div className="flex gap-3 items-center">
<div className="flex gap-2 items-center">
<FontAwesomeIcon icon={faBookmark} className="w-5 h-5 text-sky-300" />
<p className="text-lg text-sky-900">All Links</p>
<Dashboard>
<div className="p-5 flex flex-col gap-5 w-full">
<div className="flex gap-3 items-center">
<div className="flex gap-2 items-center">
<FontAwesomeIcon
icon={faBookmark}
className="w-5 h-5 text-sky-300"
/>
<p className="text-lg text-sky-900">All Links</p>
</div>
</div>
{links.map((e, i) => {
return <LinkList key={i} link={e} count={i} />;
})}
</div>
{links.map((e, i) => {
return <LinkList key={i} link={e} count={i} />;
})}
</div>
</Dashboard>
);
}
+6 -7
View File
@@ -5,6 +5,7 @@
import { signIn } from "next-auth/react";
import Link from "next/link";
import { useRouter } from "next/router";
import { useState } from "react";
interface FormData {
@@ -13,6 +14,8 @@ interface FormData {
}
export default function () {
const router = useRouter();
const [form, setForm] = useState<FormData>({
email: "",
password: "",
@@ -24,16 +27,12 @@ export default function () {
const res = await signIn("credentials", {
email: form.email,
password: form.password,
redirect: false,
});
console.log(res?.status);
console.log(res);
if (res?.ok) {
setForm({
email: "",
password: "",
});
} else {
if (!res?.ok) {
console.log("User not found or password does not match.", res);
}
} else {
+6 -1
View File
@@ -3,6 +3,7 @@
// 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/>.
import Dashboard from "@/layouts/Dashboard";
import { useRouter } from "next/router";
export default function () {
@@ -10,5 +11,9 @@ export default function () {
const tagId = Number(router.query.id);
return <div>{"HI"}</div>;
return (
<Dashboard>
<div>{"HI"}</div>
</Dashboard>
);
}