Replace useless ternarys with logical ANDs

This commit is contained in:
Isaac Wise
2024-07-22 22:34:36 -05:00
parent 2264abd384
commit e79b98d3b0
25 changed files with 195 additions and 212 deletions
+21 -22
View File
@@ -115,9 +115,8 @@ export default function Index() {
<div
className="h-[60rem] p-5 flex gap-3 flex-col"
style={{
backgroundImage: `linear-gradient(${activeCollection?.color}20 10%, ${
settings.theme === "dark" ? "#262626" : "#f3f4f6"
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
backgroundImage: `linear-gradient(${activeCollection?.color}20 10%, ${settings.theme === "dark" ? "#262626" : "#f3f4f6"
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
}}
>
{activeCollection && (
@@ -211,12 +210,12 @@ export default function Index() {
className="flex items-center btn px-2 btn-ghost rounded-full w-fit"
onClick={() => setEditCollectionSharingModal(true)}
>
{collectionOwner.id ? (
{collectionOwner.id && (
<ProfilePhoto
src={collectionOwner.image || undefined}
name={collectionOwner.name}
/>
) : undefined}
)}
{activeCollection.members
.sort((a, b) => (a.userId as number) - (b.userId as number))
.map((e, i) => {
@@ -241,20 +240,20 @@ export default function Index() {
<p className="text-neutral text-sm">
{activeCollection.members.length > 0 &&
activeCollection.members.length === 1
activeCollection.members.length === 1
? t("by_author_and_other", {
author: collectionOwner.name,
count: activeCollection.members.length,
})
: activeCollection.members.length > 0 &&
activeCollection.members.length !== 1
? t("by_author_and_others", {
author: collectionOwner.name,
count: activeCollection.members.length,
})
: activeCollection.members.length > 0 &&
activeCollection.members.length !== 1
? t("by_author_and_others", {
author: collectionOwner.name,
count: activeCollection.members.length,
})
: t("by_author", {
author: collectionOwner.name,
})}
author: collectionOwner.name,
})}
</p>
</div>
</div>
@@ -299,15 +298,15 @@ export default function Index() {
setSortBy={setSortBy}
editMode={
permissions === true ||
permissions?.canUpdate ||
permissions?.canDelete
permissions?.canUpdate ||
permissions?.canDelete
? editMode
: undefined
}
setEditMode={
permissions === true ||
permissions?.canUpdate ||
permissions?.canDelete
permissions?.canUpdate ||
permissions?.canDelete
? setEditMode
: undefined
}
@@ -315,11 +314,11 @@ export default function Index() {
<p>
{activeCollection?._count?.links === 1
? t("showing_count_result", {
count: activeCollection?._count?.links,
})
count: activeCollection?._count?.links,
})
: t("showing_count_results", {
count: activeCollection?._count?.links,
})}
count: activeCollection?._count?.links,
})}
</p>
</LinkListOptions>
+4 -4
View File
@@ -58,7 +58,7 @@ export default function Collections() {
</div>
</div>
{sortedCollections.filter((e) => e.ownerId !== data?.user.id)[0] ? (
{sortedCollections.filter((e) => e.ownerId !== data?.user.id)[0] && (
<>
<PageHeader
icon={"bi-folder"}
@@ -74,11 +74,11 @@ export default function Collections() {
})}
</div>
</>
) : undefined}
)}
</div>
{newCollectionModal ? (
{newCollectionModal && (
<NewCollectionModal onClose={() => setNewCollectionModal(false)} />
) : undefined}
)}
</MainLayout>
);
}
+2 -2
View File
@@ -324,9 +324,9 @@ export default function Dashboard() {
)}
</div>
</div>
{newLinkModal ? (
{newLinkModal && (
<NewLinkModal onClose={() => setNewLinkModal(false)} />
) : undefined}
)}
</MainLayout>
);
}
+5 -5
View File
@@ -203,9 +203,9 @@ export default function Login({
{t("login")}
</Button>
{availableLogins.buttonAuths.length > 0 ? (
{availableLogins.buttonAuths.length > 0 && (
<div className="divider my-1">{t("or_continue_with")}</div>
) : undefined}
)}
</>
);
}
@@ -224,9 +224,9 @@ export default function Login({
loading={submitLoader}
>
{value.name.toLowerCase() === "google" ||
value.name.toLowerCase() === "apple" ? (
<i className={"bi-" + value.name.toLowerCase()}></i>
) : undefined}
value.name.toLowerCase() === "apple" && (
<i className={"bi-" + value.name.toLowerCase()}></i>
)}
{value.name}
</Button>
</React.Fragment>
+24 -25
View File
@@ -104,16 +104,17 @@ export default function PublicCollections() {
// @ts-ignore
const LinkComponent = linkView[viewMode];
return collection ? (
if (!collection) return null;
return (
<div
className="h-96"
style={{
backgroundImage: `linear-gradient(${collection?.color}30 10%, ${
settings.theme === "dark" ? "#262626" : "#f3f4f6"
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
backgroundImage: `linear-gradient(${collection?.color}30 10%, ${settings.theme === "dark" ? "#262626" : "#f3f4f6"
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
}}
>
{collection ? (
{collection && (
<Head>
<title>{collection.name} | Linkwarden</title>
<meta
@@ -122,7 +123,7 @@ export default function PublicCollections() {
key="title"
/>
</Head>
) : undefined}
)}
<div className="lg:w-3/4 w-full mx-auto p-5 bg">
<div className="flex items-center justify-between">
<p className="text-4xl font-thin mb-2 capitalize mt-10">
@@ -151,12 +152,12 @@ export default function PublicCollections() {
className="flex items-center btn px-2 btn-ghost rounded-full"
onClick={() => setEditCollectionSharingModal(true)}
>
{collectionOwner.id ? (
{collectionOwner.id && (
<ProfilePhoto
src={collectionOwner.image || undefined}
name={collectionOwner.name}
/>
) : undefined}
)}
{collection.members
.sort((a, b) => (a.userId as number) - (b.userId as number))
.map((e, i) => {
@@ -181,20 +182,20 @@ export default function PublicCollections() {
<p className="text-neutral text-sm">
{collection.members.length > 0 &&
collection.members.length === 1
collection.members.length === 1
? t("by_author_and_other", {
author: collectionOwner.name,
count: collection.members.length,
})
: collection.members.length > 0 &&
collection.members.length !== 1
? t("by_author_and_others", {
author: collectionOwner.name,
count: collection.members.length,
})
: collection.members.length > 0 &&
collection.members.length !== 1
? t("by_author_and_others", {
author: collectionOwner.name,
count: collection.members.length,
})
: t("by_author", {
author: collectionOwner.name,
})}
author: collectionOwner.name,
})}
</p>
</div>
</div>
@@ -218,11 +219,11 @@ export default function PublicCollections() {
placeholder={
collection._count?.links === 1
? t("search_count_link", {
count: collection._count?.links,
})
count: collection._count?.links,
})
: t("search_count_links", {
count: collection._count?.links,
})
count: collection._count?.links,
})
}
/>
</LinkListOptions>
@@ -248,15 +249,13 @@ export default function PublicCollections() {
</p> */}
</div>
</div>
{editCollectionSharingModal ? (
{editCollectionSharingModal && (
<EditCollectionSharingModal
onClose={() => setEditCollectionSharingModal(false)}
activeCollection={collection}
/>
) : undefined}
)}
</div>
) : (
<></>
);
}
+13 -13
View File
@@ -133,9 +133,9 @@ export default function Register({
loading={submitLoader}
>
{value.name.toLowerCase() === "google" ||
value.name.toLowerCase() === "apple" ? (
<i className={"bi-" + value.name.toLowerCase()}></i>
) : undefined}
value.name.toLowerCase() === "apple" && (
<i className={"bi-" + value.name.toLowerCase()}></i>
)}
{value.name}
</Button>
</React.Fragment>
@@ -149,8 +149,8 @@ export default function Register({
text={
process.env.NEXT_PUBLIC_STRIPE
? t("trial_offer_desc", {
count: Number(process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS || 14),
})
count: Number(process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS || 14),
})
: t("register_desc")
}
data-testid="registration-form"
@@ -201,7 +201,7 @@ export default function Register({
</div>
)}
{emailEnabled ? (
{emailEnabled && (
<div>
<p className="text-sm w-fit font-semibold mb-1">{t("email")}</p>
@@ -214,7 +214,7 @@ export default function Register({
onChange={(e) => setForm({ ...form, email: e.target.value })}
/>
</div>
) : undefined}
)}
<div className="w-full">
<p className="text-sm w-fit font-semibold mb-1">
@@ -248,7 +248,7 @@ export default function Register({
/>
</div>
{process.env.NEXT_PUBLIC_STRIPE ? (
{process.env.NEXT_PUBLIC_STRIPE && (
<div className="text-xs text-neutral mb-3">
<p>
<Trans
@@ -270,7 +270,7 @@ export default function Register({
/>
</p>
</div>
) : undefined}
)}
<Button
type="submit"
@@ -282,9 +282,9 @@ export default function Register({
{t("sign_up")}
</Button>
{availableLogins.buttonAuths.length > 0 ? (
{availableLogins.buttonAuths.length > 0 && (
<div className="divider my-1">{t("or_continue_with")}</div>
) : undefined}
)}
{displayLoginExternalButton()}
<div>
@@ -298,7 +298,7 @@ export default function Register({
{t("login")}
</Link>
</div>
{process.env.NEXT_PUBLIC_STRIPE ? (
{process.env.NEXT_PUBLIC_STRIPE && (
<div className="text-neutral text-center flex items-baseline gap-1 justify-center">
<p>{t("need_help")}</p>
<Link
@@ -309,7 +309,7 @@ export default function Register({
{t("get_in_touch")}
</Link>
</div>
) : undefined}
)}
</div>
</div>
</form>
+4 -4
View File
@@ -48,7 +48,7 @@ export default function AccessTokens() {
{t("new_token")}
</button>
{tokens.length > 0 ? (
{tokens.length > 0 && (
<table className="table mt-2 overflow-x-auto">
<thead>
<tr>
@@ -93,12 +93,12 @@ export default function AccessTokens() {
))}
</tbody>
</table>
) : undefined}
)}
</div>
{newTokenModal ? (
{newTokenModal && (
<NewTokenModal onClose={() => setNewTokenModal(false)} />
) : undefined}
)}
{revokeTokenModal && selectedToken && (
<RevokeTokenModal
onClose={() => {
+18 -20
View File
@@ -29,19 +29,19 @@ export default function Account() {
!objectIsEmpty(account)
? account
: ({
// @ts-ignore
id: null,
name: "",
username: "",
email: "",
emailVerified: null,
password: undefined,
image: "",
isPrivate: true,
// @ts-ignore
createdAt: null,
whitelistedUsers: [],
} as unknown as AccountSettings)
// @ts-ignore
id: null,
name: "",
username: "",
email: "",
emailVerified: null,
password: undefined,
image: "",
isPrivate: true,
// @ts-ignore
createdAt: null,
whitelistedUsers: [],
} as unknown as AccountSettings)
);
const { t } = useTranslation();
@@ -176,7 +176,7 @@ export default function Account() {
onChange={(e) => setUser({ ...user, username: e.target.value })}
/>
</div>
{emailEnabled ? (
{emailEnabled && (
<div>
<p className="mb-2">{t("email")}</p>
<TextInput
@@ -185,7 +185,7 @@ export default function Account() {
onChange={(e) => setUser({ ...user, email: e.target.value })}
/>
</div>
) : undefined}
)}
<div>
<p className="mb-2">{t("language")}</p>
<select
@@ -418,9 +418,7 @@ export default function Account() {
<p>
{t("delete_account_warning")}
{process.env.NEXT_PUBLIC_STRIPE
? " " + t("cancel_subscription_notice")
: undefined}
{process.env.NEXT_PUBLIC_STRIPE && " " + t("cancel_subscription_notice")}
</p>
</div>
@@ -429,14 +427,14 @@ export default function Account() {
</Link>
</div>
{emailChangeVerificationModal ? (
{emailChangeVerificationModal && (
<EmailChangeVerificationModal
onClose={() => setEmailChangeVerificationModal(false)}
onSubmit={submit}
oldEmail={account.email || ""}
newEmail={user.email || ""}
/>
) : undefined}
)}
</SettingsLayout>
);
}
+2 -2
View File
@@ -83,7 +83,7 @@ export default function Delete() {
/>
</div>
{process.env.NEXT_PUBLIC_STRIPE ? (
{process.env.NEXT_PUBLIC_STRIPE && (
<fieldset className="border rounded-md p-2 border-primary">
<legend className="px-3 py-1 text-sm sm:text-base border rounded-md border-primary">
<b>{t("optional")}</b> <i>{t("feedback_help")}</i>
@@ -123,7 +123,7 @@ export default function Delete() {
/>
</div>
</fieldset>
) : undefined}
)}
<Button
className="mx-auto"