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)}
{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>
<Link
href={`/collections/${collection.id}`}

View File

@ -60,7 +60,7 @@ export default function Dropdown({
}
}, [points, dropdownHeight]);
return !points || pos ? (
return !points || pos && (
<ClickAwayHandler
onMount={(e) => {
setDropdownHeight(e.height);
@ -76,8 +76,7 @@ export default function Dropdown({
: undefined
}
onClickOutside={onClickOutside}
className={`${
className || ""
className={`${className || ""
} py-1 shadow-md border border-neutral-content bg-base-200 rounded-md flex flex-col z-20`}
>
{items.map((e, i) => {
@ -102,5 +101,5 @@ export default function Dropdown({
);
})}
</ClickAwayHandler>
) : null;
);
}

View File

@ -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;

View File

@ -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 && (
<CollectionSelection
onChange={setCollection}
defaultValue={
@ -108,7 +108,7 @@ export default function EditLinkModal({ onClose, activeLink }: Props) {
}
creatable={false}
/>
) : null}
)}
</div>
<div>

View File

@ -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 && (
<CollectionSelection
onChange={setCollection}
defaultValue={{
@ -124,7 +124,7 @@ export default function NewLinkModal({ onClose }: Props) {
value: link.collection.id,
}}
/>
) : null}
)}
</div>
</div>
<div className={"mt-2"}>

View File

@ -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)} />
)}

View File

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

View File

@ -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>

View File

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

View File

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

View File

@ -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;

View File

@ -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 {

View File

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

View File

@ -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">

View File

@ -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);

View File

@ -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">