remove more ternaries

This commit is contained in:
Isaac Wise 2024-07-27 16:17:38 -05:00
parent fa051c0d4d
commit ff31732ba3
No known key found for this signature in database
GPG Key ID: A02A33A7E2427136
17 changed files with 80 additions and 70 deletions

View File

@ -148,13 +148,13 @@ export default function CollectionCard({ collection, className }: Props) {
); );
}) })
.slice(0, 3)} .slice(0, 3)}
{collection.members.length - 3 > 0 ? ( {collection.members.length - 3 > 0 && (
<div className={`avatar drop-shadow-md placeholder -ml-3`}> <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"> <div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
<span>+{collection.members.length - 3}</span> <span>+{collection.members.length - 3}</span>
</div> </div>
</div> </div>
) : null} )}
</div> </div>
<Link <Link
href={`/collections/${collection.id}`} href={`/collections/${collection.id}`}

View File

@ -4,15 +4,15 @@ import ClickAwayHandler from "./ClickAwayHandler";
type MenuItem = type MenuItem =
| { | {
name: string; name: string;
onClick: MouseEventHandler; onClick: MouseEventHandler;
href?: string; href?: string;
} }
| { | {
name: string; name: string;
onClick?: MouseEventHandler; onClick?: MouseEventHandler;
href: string; href: string;
} }
| undefined; | undefined;
type Props = { type Props = {
@ -60,7 +60,7 @@ export default function Dropdown({
} }
}, [points, dropdownHeight]); }, [points, dropdownHeight]);
return !points || pos ? ( return !points || pos && (
<ClickAwayHandler <ClickAwayHandler
onMount={(e) => { onMount={(e) => {
setDropdownHeight(e.height); setDropdownHeight(e.height);
@ -69,16 +69,15 @@ export default function Dropdown({
style={ style={
points points
? { ? {
position: "fixed", position: "fixed",
top: `${pos?.y}px`, top: `${pos?.y}px`,
left: `${pos?.x}px`, left: `${pos?.x}px`,
} }
: undefined : undefined
} }
onClickOutside={onClickOutside} onClickOutside={onClickOutside}
className={`${ className={`${className || ""
className || "" } py-1 shadow-md border border-neutral-content bg-base-200 rounded-md flex flex-col z-20`}
} py-1 shadow-md border border-neutral-content bg-base-200 rounded-md flex flex-col z-20`}
> >
{items.map((e, i) => { {items.map((e, i) => {
const inner = e && ( const inner = e && (
@ -102,5 +101,5 @@ export default function Dropdown({
); );
})} })}
</ClickAwayHandler> </ClickAwayHandler>
) : null; );
} }

View File

@ -6,6 +6,16 @@ import { Options } from "./types";
import CreatableSelect from "react-select/creatable"; import CreatableSelect from "react-select/creatable";
import Select, { ActionMeta } from "react-select"; import Select, { ActionMeta } from "react-select";
interface Option {
label: string;
value: number;
ownerId: number;
count?: {
links: number;
};
parentId?: number;
}
type Props = { type Props = {
onChange: (newValue: unknown, actionMeta: ActionMeta<unknown>) => void; onChange: (newValue: unknown, actionMeta: ActionMeta<unknown>) => void;
showDefaultValue?: boolean; showDefaultValue?: boolean;

View File

@ -98,7 +98,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
<div className="grid sm:grid-cols-2 gap-3"> <div className="grid sm:grid-cols-2 gap-3">
<div> <div>
<p className="mb-2">{t("collection")}</p> <p className="mb-2">{t("collection")}</p>
{link.collection.name ? ( {link.collection.name && (
<CollectionSelection <CollectionSelection
onChange={setCollection} onChange={setCollection}
defaultValue={ defaultValue={
@ -108,7 +108,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
} }
creatable={false} creatable={false}
/> />
) : null} )}
</div> </div>
<div> <div>

View File

@ -116,7 +116,7 @@ export default function NewLinkModal({ onClose }: Props) {
</div> </div>
<div className="sm:col-span-2 col-span-5"> <div className="sm:col-span-2 col-span-5">
<p className="mb-2">{t("collection")}</p> <p className="mb-2">{t("collection")}</p>
{link.collection.name ? ( {link.collection.name && (
<CollectionSelection <CollectionSelection
onChange={setCollection} onChange={setCollection}
defaultValue={{ defaultValue={{
@ -124,7 +124,7 @@ export default function NewLinkModal({ onClose }: Props) {
value: link.collection.id, value: link.collection.id,
}} }}
/> />
) : null} )}
</div> </div>
</div> </div>
<div className={"mt-2"}> <div className={"mt-2"}>

View File

@ -111,7 +111,7 @@ export default function Navbar() {
<MobileNavigation /> <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"> <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}> <ClickAwayHandler className="h-full" onClickOutside={toggleSidebar}>
<div className="slide-right h-full shadow-lg"> <div className="slide-right h-full shadow-lg">
@ -119,7 +119,7 @@ export default function Navbar() {
</div> </div>
</ClickAwayHandler> </ClickAwayHandler>
</div> </div>
) : null} )}
{newLinkModal && ( {newLinkModal && (
<NewLinkModal onClose={() => setNewLinkModal(false)} /> <NewLinkModal onClose={() => setNewLinkModal(false)} />
)} )}

View File

@ -32,9 +32,8 @@ export default function ProfileDropdown() {
/> />
</div> </div>
<ul <ul
className={`dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box ${ className={`dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box ${isAdmin ? "w-48" : "w-40"
isAdmin ? "w-48" : "w-40" } mt-1`}
} mt-1`}
> >
<li> <li>
<Link <Link
@ -60,7 +59,7 @@ export default function ProfileDropdown() {
})} })}
</div> </div>
</li> </li>
{isAdmin ? ( {isAdmin && (
<li> <li>
<Link <Link
href="/admin" href="/admin"
@ -71,7 +70,7 @@ export default function ProfileDropdown() {
{t("server_administration")} {t("server_administration")}
</Link> </Link>
</li> </li>
) : null} )}
<li> <li>
<div <div
onClick={() => { onClick={() => {

View File

@ -1,5 +1,5 @@
import useLocalSettingsStore from "@/store/localSettings"; import useLocalSettingsStore from "@/store/localSettings";
import { useEffect, useState } from "react"; import { useEffect, useState, ChangeEvent } from "react";
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
type Props = { type Props = {
@ -10,15 +10,18 @@ export default function ToggleDarkMode({ className }: Props) {
const { t } = useTranslation(); const { t } = useTranslation();
const { settings, updateSettings } = useLocalSettingsStore(); 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"); setTheme(e.target.checked ? "dark" : "light");
}; };
useEffect(() => { useEffect(() => {
updateSettings({ theme: theme as string }); if (theme) {
}, [theme]); updateSettings({ theme });
localStorage.setItem("theme", theme);
}
}, [theme, updateSettings]);
return ( return (
<div <div
@ -34,7 +37,7 @@ export default function ToggleDarkMode({ className }: Props) {
type="checkbox" type="checkbox"
onChange={handleToggle} onChange={handleToggle}
className="theme-controller" 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-sun-fill text-xl swap-on"></i>
<i className="bi-moon-fill text-xl swap-off"></i> <i className="bi-moon-fill text-xl swap-off"></i>

View File

@ -74,12 +74,12 @@ const UserListing = (
</tbody> </tbody>
</table> </table>
{deleteUserModal.isOpen && deleteUserModal.userId ? ( {deleteUserModal.isOpen && deleteUserModal.userId && (
<DeleteUserModal <DeleteUserModal
onClose={() => setDeleteUserModal({ isOpen: false, userId: null })} onClose={() => setDeleteUserModal({ isOpen: false, userId: null })}
userId={deleteUserModal.userId} userId={deleteUserModal.userId}
/> />
) : null} )}
</div> </div>
); );
}; };

View File

@ -54,7 +54,7 @@ export default function SettingsLayout({ children }: Props) {
{children} {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"> <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">
<ClickAwayHandler <ClickAwayHandler
className="h-full" className="h-full"
@ -65,7 +65,7 @@ export default function SettingsLayout({ children }: Props) {
</div> </div>
</ClickAwayHandler> </ClickAwayHandler>
</div> </div>
) : null} )}
</div> </div>
</div> </div>
</> </>

View File

@ -1,5 +1,4 @@
import { prisma } from "@/lib/api/db"; import { prisma } from "@/lib/api/db";
import { Backup } from "@/types/global";
import createFolder from "@/lib/api/storage/createFolder"; import createFolder from "@/lib/api/storage/createFolder";
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000; const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
@ -85,23 +84,23 @@ export default async function importFromWallabag(
tags: tags:
link.tags && link.tags[0] link.tags && link.tags[0]
? { ? {
connectOrCreate: link.tags.map((tag) => ({ connectOrCreate: link.tags.map((tag) => ({
where: { where: {
name_ownerId: { name_ownerId: {
name: tag.trim(),
ownerId: userId,
},
},
create: {
name: tag.trim(), name: tag.trim(),
owner: { ownerId: userId,
connect: { },
id: userId, },
}, create: {
name: tag.trim(),
owner: {
connect: {
id: userId,
}, },
}, },
})), },
} })),
}
: undefined, : undefined,
}, },
}); });

View File

@ -14,7 +14,7 @@ export default async function moveFile(from: string, to: string) {
}; };
try { try {
s3Client.copyObject(copyParams, async (err: any) => { s3Client.copyObject(copyParams, async (err: unknown) => {
if (err) { if (err) {
console.error("Error copying the object:", err); console.error("Error copying the object:", err);
} else { } else {

View File

@ -28,10 +28,10 @@ export default async function readFile(filePath: string) {
try { try {
let returnObject: let returnObject:
| { | {
file: Buffer | string; file: Buffer | string;
contentType: ReturnContentTypes; contentType: ReturnContentTypes;
status: number; status: number;
} }
| undefined; | undefined;
const headObjectAsync = util.promisify( const headObjectAsync = util.promisify(

View File

@ -104,9 +104,9 @@ export default function Admin() {
<p>{t("no_users_found")}</p> <p>{t("no_users_found")}</p>
)} )}
{newUserModal ? ( {newUserModal && (
<NewUserModal onClose={() => setNewUserModal(false)} /> <NewUserModal onClose={() => setNewUserModal(false)} />
) : null} )}
</div> </div>
); );
} }

View File

@ -229,13 +229,13 @@ export default function Index() {
); );
}) })
.slice(0, 3)} .slice(0, 3)}
{activeCollection.members.length - 3 > 0 ? ( {activeCollection.members.length - 3 > 0 && (
<div className={`avatar drop-shadow-md placeholder -ml-3`}> <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"> <div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
<span>+{activeCollection.members.length - 3}</span> <span>+{activeCollection.members.length - 3}</span>
</div> </div>
</div> </div>
) : null} )}
</div> </div>
<p className="text-neutral text-sm"> <p className="text-neutral text-sm">

View File

@ -60,11 +60,11 @@ export default function Dashboard() {
handleNumberOfLinksToShow(); handleNumberOfLinksToShow();
}, [width]); }, [width]);
const importBookmarks = async (e: any, format: MigrationFormat) => { const importBookmarks = async (e: React.ChangeEvent<HTMLInputElement>, format: MigrationFormat) => {
const file: File = e.target.files[0]; const file: File | null = e.target.files && e.target.files[0];
if (file) { if (file) {
var reader = new FileReader(); const reader = new FileReader();
reader.readAsText(file, "UTF-8"); reader.readAsText(file, "UTF-8");
reader.onload = async function (e) { reader.onload = async function (e) {
const load = toast.loading("Importing..."); const load = toast.loading("Importing...");
@ -81,7 +81,7 @@ export default function Dashboard() {
body: JSON.stringify(body), body: JSON.stringify(body),
}); });
const data = await response.json(); await response.json();
toast.dismiss(load); toast.dismiss(load);

View File

@ -171,13 +171,13 @@ export default function PublicCollections() {
); );
}) })
.slice(0, 3)} .slice(0, 3)}
{collection.members.length - 3 > 0 ? ( {collection.members.length - 3 > 0 && (
<div className={`avatar drop-shadow-md placeholder -ml-3`}> <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"> <div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
<span>+{collection.members.length - 3}</span> <span>+{collection.members.length - 3}</span>
</div> </div>
</div> </div>
) : null} )}
</div> </div>
<p className="text-neutral text-sm"> <p className="text-neutral text-sm">