⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
remove more ternaries
Isaac Wiseff31732ba378
diff --git a/components/CollectionCard.tsx b/components/CollectionCard.tsxindex cd7d80eb..7ac8371b 100644--- a/components/CollectionCard.tsx+++ b/components/CollectionCard.tsx@@ -148,13 +148,13 @@ export default function CollectionCard({ collection, className }: Props) {);}).slice(0, 3)}- {collection.members.length - 3 > 0 ? (+ {collection.members.length - 3 > 0 && (<div className={`avatar drop-shadow-md placeholder -ml-3`}><div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content"><span>+{collection.members.length - 3}</span></div></div>- ) : null}+ )}</div><Linkhref={`/collections/${collection.id}`}diff --git a/components/Dropdown.tsx b/components/Dropdown.tsxindex 4a48ab76..0089bc85 100644--- a/components/Dropdown.tsx+++ b/components/Dropdown.tsx@@ -4,15 +4,15 @@ import ClickAwayHandler from "./ClickAwayHandler";type MenuItem =| {- name: string;- onClick: MouseEventHandler;- href?: string;- }+ name: string;+ onClick: MouseEventHandler;+ href?: string;+ }| {- name: string;- onClick?: MouseEventHandler;- href: string;- }+ name: string;+ onClick?: MouseEventHandler;+ href: string;+ }| undefined;type Props = {@@ -60,7 +60,7 @@ export default function Dropdown({}}, [points, dropdownHeight]);- return !points || pos ? (+ return !points || pos && (<ClickAwayHandleronMount={(e) => {setDropdownHeight(e.height);@@ -69,16 +69,15 @@ export default function Dropdown({style={points? {- position: "fixed",- top: `${pos?.y}px`,- left: `${pos?.x}px`,- }+ position: "fixed",+ top: `${pos?.y}px`,+ left: `${pos?.x}px`,+ }: undefined}onClickOutside={onClickOutside}- className={`${- className || ""- } py-1 shadow-md border border-neutral-content bg-base-200 rounded-md flex flex-col z-20`}+ className={`${className || ""+ } py-1 shadow-md border border-neutral-content bg-base-200 rounded-md flex flex-col z-20`}>{items.map((e, i) => {const inner = e && (@@ -102,5 +101,5 @@ export default function Dropdown({);})}</ClickAwayHandler>- ) : null;+ );}diff --git a/components/InputSelect/CollectionSelection.tsx b/components/InputSelect/CollectionSelection.tsxindex 37899ee3..6354f7e8 100644--- a/components/InputSelect/CollectionSelection.tsx+++ b/components/InputSelect/CollectionSelection.tsx@@ -6,6 +6,16 @@ import { Options } from "./types";import CreatableSelect from "react-select/creatable";import Select, { ActionMeta } from "react-select";+interface Option {+ label: string;+ value: number;+ ownerId: number;+ count?: {+ links: number;+ };+ parentId?: number;+}+type Props = {onChange: (newValue: unknown, actionMeta: ActionMeta<unknown>) => void;showDefaultValue?: boolean;diff --git a/components/ModalContent/EditLinkModal.tsx b/components/ModalContent/EditLinkModal.tsxindex b509aa81..91b9aad4 100644--- a/components/ModalContent/EditLinkModal.tsx+++ b/components/ModalContent/EditLinkModal.tsx@@ -98,7 +98,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {<div className="grid sm:grid-cols-2 gap-3"><div><p className="mb-2">{t("collection")}</p>- {link.collection.name ? (+ {link.collection.name && (<CollectionSelectiononChange={setCollection}defaultValue={@@ -108,7 +108,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {}creatable={false}/>- ) : null}+ )}</div><div>diff --git a/components/ModalContent/NewLinkModal.tsx b/components/ModalContent/NewLinkModal.tsxindex 680f9efe..26471a31 100644--- a/components/ModalContent/NewLinkModal.tsx+++ b/components/ModalContent/NewLinkModal.tsx@@ -116,7 +116,7 @@ export default function NewLinkModal({ onClose }: Props) {</div><div className="sm:col-span-2 col-span-5"><p className="mb-2">{t("collection")}</p>- {link.collection.name ? (+ {link.collection.name && (<CollectionSelectiononChange={setCollection}defaultValue={{@@ -124,7 +124,7 @@ export default function NewLinkModal({ onClose }: Props) {value: link.collection.id,}}/>- ) : null}+ )}</div></div><div className={"mt-2"}>diff --git a/components/Navbar.tsx b/components/Navbar.tsxindex 888c56b6..d4907ac2 100644--- a/components/Navbar.tsx+++ b/components/Navbar.tsx@@ -111,7 +111,7 @@ export default function Navbar() {<MobileNavigation />- {sidebar ? (+ {sidebar && (<div className="fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex items-center fade-in z-40"><ClickAwayHandler className="h-full" onClickOutside={toggleSidebar}><div className="slide-right h-full shadow-lg">@@ -119,7 +119,7 @@ export default function Navbar() {</div></ClickAwayHandler></div>- ) : null}+ )}{newLinkModal && (<NewLinkModal onClose={() => setNewLinkModal(false)} />)}diff --git a/components/ProfileDropdown.tsx b/components/ProfileDropdown.tsxindex 21ce54e7..400969bf 100644--- a/components/ProfileDropdown.tsx+++ b/components/ProfileDropdown.tsx@@ -32,9 +32,8 @@ export default function ProfileDropdown() {/></div><ul- className={`dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box ${- isAdmin ? "w-48" : "w-40"- } mt-1`}+ className={`dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box ${isAdmin ? "w-48" : "w-40"+ } mt-1`}><li><Link@@ -60,7 +59,7 @@ export default function ProfileDropdown() {})}</div></li>- {isAdmin ? (+ {isAdmin && (<li><Linkhref="/admin"@@ -71,7 +70,7 @@ export default function ProfileDropdown() {{t("server_administration")}</Link></li>- ) : null}+ )}<li><divonClick={() => {diff --git a/components/ToggleDarkMode.tsx b/components/ToggleDarkMode.tsxindex 2b9e457e..fe12cb39 100644--- a/components/ToggleDarkMode.tsx+++ b/components/ToggleDarkMode.tsx@@ -1,5 +1,5 @@import useLocalSettingsStore from "@/store/localSettings";-import { useEffect, useState } from "react";+import { useEffect, useState, ChangeEvent } from "react";import { useTranslation } from "next-i18next";type Props = {@@ -10,15 +10,18 @@ export default function ToggleDarkMode({ className }: Props) {const { t } = useTranslation();const { settings, updateSettings } = useLocalSettingsStore();- const [theme, setTheme] = useState(localStorage.getItem("theme"));+ const [theme, setTheme] = useState<string | null>(localStorage.getItem("theme"));- const handleToggle = (e: any) => {+ const handleToggle = (e: ChangeEvent<HTMLInputElement>) => {setTheme(e.target.checked ? "dark" : "light");};useEffect(() => {- updateSettings({ theme: theme as string });- }, [theme]);+ if (theme) {+ updateSettings({ theme });+ localStorage.setItem("theme", theme);+ }+ }, [theme, updateSettings]);return (<div@@ -34,7 +37,7 @@ export default function ToggleDarkMode({ className }: Props) {type="checkbox"onChange={handleToggle}className="theme-controller"- checked={localStorage.getItem("theme") === "light" ? false : true}+ checked={theme === "dark"}/><i className="bi-sun-fill text-xl swap-on"></i><i className="bi-moon-fill text-xl swap-off"></i>diff --git a/components/UserListing.tsx b/components/UserListing.tsxindex 378ad985..46c6e75b 100644--- a/components/UserListing.tsx+++ b/components/UserListing.tsx@@ -74,12 +74,12 @@ const UserListing = (</tbody></table>- {deleteUserModal.isOpen && deleteUserModal.userId ? (+ {deleteUserModal.isOpen && deleteUserModal.userId && (<DeleteUserModalonClose={() => setDeleteUserModal({ isOpen: false, userId: null })}userId={deleteUserModal.userId}/>- ) : null}+ )}</div>);};diff --git a/layouts/SettingsLayout.tsx b/layouts/SettingsLayout.tsxindex cae35340..5a037b5e 100644--- a/layouts/SettingsLayout.tsx+++ b/layouts/SettingsLayout.tsx@@ -54,7 +54,7 @@ export default function SettingsLayout({ children }: Props) {{children}- {sidebar ? (+ {sidebar && (<div className="fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex items-center fade-in z-30"><ClickAwayHandlerclassName="h-full"@@ -65,7 +65,7 @@ export default function SettingsLayout({ children }: Props) {</div></ClickAwayHandler></div>- ) : null}+ )}</div></div></>diff --git a/lib/api/controllers/migration/importFromWallabag.ts b/lib/api/controllers/migration/importFromWallabag.tsindex 568952a4..f482f398 100644--- a/lib/api/controllers/migration/importFromWallabag.ts+++ b/lib/api/controllers/migration/importFromWallabag.ts@@ -1,5 +1,4 @@import { prisma } from "@/lib/api/db";-import { Backup } from "@/types/global";import createFolder from "@/lib/api/storage/createFolder";const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;@@ -85,23 +84,23 @@ export default async function importFromWallabag(tags:link.tags && link.tags[0]? {- connectOrCreate: link.tags.map((tag) => ({- where: {- name_ownerId: {- name: tag.trim(),- ownerId: userId,- },- },- create: {+ connectOrCreate: link.tags.map((tag) => ({+ where: {+ name_ownerId: {name: tag.trim(),- owner: {- connect: {- id: userId,- },+ ownerId: userId,+ },+ },+ create: {+ name: tag.trim(),+ owner: {+ connect: {+ id: userId,},},- })),- }+ },+ })),+ }: undefined,},});diff --git a/lib/api/storage/moveFile.ts b/lib/api/storage/moveFile.tsindex c86728fd..c5aedb65 100644--- a/lib/api/storage/moveFile.ts+++ b/lib/api/storage/moveFile.ts@@ -14,7 +14,7 @@ export default async function moveFile(from: string, to: string) {};try {- s3Client.copyObject(copyParams, async (err: any) => {+ s3Client.copyObject(copyParams, async (err: unknown) => {if (err) {console.error("Error copying the object:", err);} else {diff --git a/lib/api/storage/readFile.ts b/lib/api/storage/readFile.tsindex fc9d2e75..a8eee587 100644--- a/lib/api/storage/readFile.ts+++ b/lib/api/storage/readFile.ts@@ -28,10 +28,10 @@ export default async function readFile(filePath: string) {try {let returnObject:| {- file: Buffer | string;- contentType: ReturnContentTypes;- status: number;- }+ file: Buffer | string;+ contentType: ReturnContentTypes;+ status: number;+ }| undefined;const headObjectAsync = util.promisify(diff --git a/pages/admin.tsx b/pages/admin.tsxindex 7211e08b..4f603e69 100644--- a/pages/admin.tsx+++ b/pages/admin.tsx@@ -104,9 +104,9 @@ export default function Admin() {<p>{t("no_users_found")}</p>)}- {newUserModal ? (+ {newUserModal && (<NewUserModal onClose={() => setNewUserModal(false)} />- ) : null}+ )}</div>);}diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsxindex b50d6df1..c014aeb7 100644--- a/pages/collections/[id].tsx+++ b/pages/collections/[id].tsx@@ -229,13 +229,13 @@ export default function Index() {);}).slice(0, 3)}- {activeCollection.members.length - 3 > 0 ? (+ {activeCollection.members.length - 3 > 0 && (<div className={`avatar drop-shadow-md placeholder -ml-3`}><div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content"><span>+{activeCollection.members.length - 3}</span></div></div>- ) : null}+ )}</div><p className="text-neutral text-sm">diff --git a/pages/dashboard.tsx b/pages/dashboard.tsxindex 78239dea..01735ac7 100644--- a/pages/dashboard.tsx+++ b/pages/dashboard.tsx@@ -60,11 +60,11 @@ export default function Dashboard() {handleNumberOfLinksToShow();}, [width]);- const importBookmarks = async (e: any, format: MigrationFormat) => {- const file: File = e.target.files[0];+ const importBookmarks = async (e: React.ChangeEvent<HTMLInputElement>, format: MigrationFormat) => {+ const file: File | null = e.target.files && e.target.files[0];if (file) {- var reader = new FileReader();+ const reader = new FileReader();reader.readAsText(file, "UTF-8");reader.onload = async function (e) {const load = toast.loading("Importing...");@@ -81,7 +81,7 @@ export default function Dashboard() {body: JSON.stringify(body),});- const data = await response.json();+ await response.json();toast.dismiss(load);diff --git a/pages/public/collections/[id].tsx b/pages/public/collections/[id].tsxindex 454a9570..b7bdce73 100644--- a/pages/public/collections/[id].tsx+++ b/pages/public/collections/[id].tsx@@ -171,13 +171,13 @@ export default function PublicCollections() {);}).slice(0, 3)}- {collection.members.length - 3 > 0 ? (+ {collection.members.length - 3 > 0 && (<div className={`avatar drop-shadow-md placeholder -ml-3`}><div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content"><span>+{collection.members.length - 3}</span></div></div>- ) : null}+ )}</div><p className="text-neutral text-sm">