Fix more types and use logical ANDs
This commit is contained in:
parent
ff31732ba3
commit
4faf389a2b
|
@ -1,5 +1,5 @@
|
|||
import Link from "next/link";
|
||||
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||
import { AccountSettings, CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import ProfilePhoto from "./ProfilePhoto";
|
||||
import usePermissions from "@/hooks/usePermissions";
|
||||
|
@ -33,15 +33,7 @@ export default function CollectionCard({ collection, className }: Props) {
|
|||
|
||||
const permissions = usePermissions(collection.id as number);
|
||||
|
||||
const [collectionOwner, setCollectionOwner] = useState({
|
||||
id: null as unknown as number,
|
||||
name: "",
|
||||
username: "",
|
||||
image: "",
|
||||
archiveAsScreenshot: undefined as unknown as boolean,
|
||||
archiveAsMonolith: undefined as unknown as boolean,
|
||||
archiveAsPDF: undefined as unknown as boolean,
|
||||
});
|
||||
const [collectionOwner, setCollectionOwner] = useState<Partial<AccountSettings>>({});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchOwner = async () => {
|
||||
|
|
|
@ -6,16 +6,6 @@ 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;
|
||||
|
@ -113,7 +103,7 @@ export default function CollectionSelection({
|
|||
onChange={onChange}
|
||||
options={options}
|
||||
styles={styles}
|
||||
defaultValue={showDefaultValue ? defaultValue : null}
|
||||
defaultValue={showDefaultValue && defaultValue}
|
||||
components={{
|
||||
Option: customOption,
|
||||
}}
|
||||
|
@ -129,7 +119,7 @@ export default function CollectionSelection({
|
|||
onChange={onChange}
|
||||
options={options}
|
||||
styles={styles}
|
||||
defaultValue={showDefaultValue ? defaultValue : null}
|
||||
defaultValue={showDefaultValue && defaultValue}
|
||||
components={{
|
||||
Option: customOption,
|
||||
}}
|
||||
|
|
|
@ -35,7 +35,6 @@ export default function TagSelection({ onChange, defaultValue }: Props) {
|
|||
options={options}
|
||||
styles={styles}
|
||||
defaultValue={defaultValue}
|
||||
// menuPosition="fixed"
|
||||
isMulti
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
|
|||
import TextInput from "@/components/TextInput";
|
||||
import useCollectionStore from "@/store/collections";
|
||||
import toast from "react-hot-toast";
|
||||
import { CollectionIncludingMembersAndLinkCount, Member } from "@/types/global";
|
||||
import { AccountSettings, CollectionIncludingMembersAndLinkCount, Member } from "@/types/global";
|
||||
import getPublicUserData from "@/lib/client/getPublicUserData";
|
||||
import useAccountStore from "@/store/account";
|
||||
import usePermissions from "@/hooks/usePermissions";
|
||||
|
@ -62,15 +62,7 @@ export default function EditCollectionSharingModal({
|
|||
|
||||
const [memberUsername, setMemberUsername] = useState("");
|
||||
|
||||
const [collectionOwner, setCollectionOwner] = useState({
|
||||
id: null as unknown as number,
|
||||
name: "",
|
||||
username: "",
|
||||
image: "",
|
||||
archiveAsScreenshot: undefined as unknown as boolean,
|
||||
archiveAsMonolith: undefined as unknown as boolean,
|
||||
archiveAsPDF: undefined as unknown as boolean,
|
||||
});
|
||||
const [collectionOwner, setCollectionOwner] = useState<Partial<AccountSettings>>({});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchOwner = async () => {
|
||||
|
@ -130,7 +122,7 @@ export default function EditCollectionSharingModal({
|
|||
</div>
|
||||
)}
|
||||
|
||||
{collection.isPublic ? (
|
||||
{collection.isPublic && (
|
||||
<div className={permissions === true ? "pl-5" : ""}>
|
||||
<p className="mb-2">{t("sharable_link_guide")}</p>
|
||||
<div
|
||||
|
@ -148,7 +140,7 @@ export default function EditCollectionSharingModal({
|
|||
{publicCollectionURL}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
)}
|
||||
|
||||
{permissions === true && <div className="divider my-3"></div>}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import useLinkStore from "@/store/links";
|
|||
import {
|
||||
LinkIncludingShortenedCollectionAndTags,
|
||||
ArchivedFormat,
|
||||
AccountSettings,
|
||||
} from "@/types/global";
|
||||
import toast from "react-hot-toast";
|
||||
import Link from "next/link";
|
||||
|
@ -37,15 +38,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
|||
|
||||
let isPublic = router.pathname.startsWith("/public") ? true : undefined;
|
||||
|
||||
const [collectionOwner, setCollectionOwner] = useState({
|
||||
id: null as unknown as number,
|
||||
name: "",
|
||||
username: "",
|
||||
image: "",
|
||||
archiveAsScreenshot: undefined as unknown as boolean,
|
||||
archiveAsMonolith: undefined as unknown as boolean,
|
||||
archiveAsPDF: undefined as unknown as boolean,
|
||||
});
|
||||
const [collectionOwner, setCollectionOwner] = useState<Partial<AccountSettings>>({});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchOwner = async () => {
|
||||
|
|
|
@ -71,7 +71,7 @@ export default async function getDashboardData(
|
|||
});
|
||||
|
||||
const links = [...recentlyAddedLinks, ...pinnedLinks].sort(
|
||||
(a, b) => (new Date(b.id) as any) - (new Date(a.id) as any)
|
||||
(a, b) => new Date(b.id).getTime() - new Date(a.id).getTime()
|
||||
);
|
||||
|
||||
return { response: links, status: 200 };
|
||||
|
|
|
@ -105,9 +105,8 @@ export default async function getDashboardData(
|
|||
});
|
||||
|
||||
const links = [...recentlyAddedLinks, ...pinnedLinks].sort(
|
||||
(a, b) => (new Date(b.id) as any) - (new Date(a.id) as any)
|
||||
(a, b) => new Date(b.id).getTime() - new Date(a.id).getTime()
|
||||
);
|
||||
|
||||
return {
|
||||
data: {
|
||||
links,
|
||||
|
|
|
@ -29,7 +29,7 @@ export default async function createSession(
|
|||
secret: process.env.NEXTAUTH_SECRET as string,
|
||||
});
|
||||
|
||||
const createToken = await prisma.accessToken.create({
|
||||
await prisma.accessToken.create({
|
||||
data: {
|
||||
name: sessionName || "Unknown Device",
|
||||
userId,
|
||||
|
|
|
@ -26,7 +26,7 @@ export default async function deleteUserById(
|
|||
if (user.password) {
|
||||
const isPasswordValid = bcrypt.compareSync(
|
||||
body.password,
|
||||
user.password as string
|
||||
user.password
|
||||
);
|
||||
|
||||
if (!isPasswordValid && !isServerAdmin) {
|
||||
|
|
|
@ -9,7 +9,7 @@ export const resizeImage = (file: File): Promise<Blob> =>
|
|||
"JPEG", // output format
|
||||
100, // quality
|
||||
0, // rotation
|
||||
(uri: any) => {
|
||||
(uri) => {
|
||||
resolve(uri as Blob);
|
||||
},
|
||||
"blob" // output type
|
||||
|
|
|
@ -166,8 +166,12 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
|||
where: { id: linkId },
|
||||
});
|
||||
|
||||
if (linkStillExists && files.file[0].mimetype?.includes("image")) {
|
||||
const collectionId = collectionPermissions.id as number;
|
||||
const { mimetype } = files.file[0];
|
||||
const isPDF = mimetype?.includes("pdf");
|
||||
const isImage = mimetype?.includes("image");
|
||||
|
||||
if (linkStillExists && isImage) {
|
||||
const collectionId = collectionPermissions.id;
|
||||
createFolder({
|
||||
filePath: `archives/preview/${collectionId}`,
|
||||
});
|
||||
|
@ -184,15 +188,9 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
|||
await prisma.link.update({
|
||||
where: { id: linkId },
|
||||
data: {
|
||||
preview: files.file[0].mimetype?.includes("pdf")
|
||||
? "unavailable"
|
||||
: undefined,
|
||||
image: files.file[0].mimetype?.includes("image")
|
||||
? `archives/${collectionPermissions.id}/${linkId + suffix}`
|
||||
: null,
|
||||
pdf: files.file[0].mimetype?.includes("pdf")
|
||||
? `archives/${collectionPermissions.id}/${linkId + suffix}`
|
||||
: null,
|
||||
preview: isPDF ? "unavailable" : undefined,
|
||||
image: isImage ? `archives/${collectionPermissions.id}/${linkId + suffix}` : null,
|
||||
pdf: isPDF ? `archives/${collectionPermissions.id}/${linkId + suffix}` : null,
|
||||
lastPreserved: new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import useCollectionStore from "@/store/collections";
|
||||
import useLinkStore from "@/store/links";
|
||||
import {
|
||||
AccountSettings,
|
||||
CollectionIncludingMembersAndLinkCount,
|
||||
Sort,
|
||||
ViewMode,
|
||||
|
@ -53,15 +54,7 @@ export default function Index() {
|
|||
|
||||
const { account } = useAccountStore();
|
||||
|
||||
const [collectionOwner, setCollectionOwner] = useState({
|
||||
id: null as unknown as number,
|
||||
name: "",
|
||||
username: "",
|
||||
image: "",
|
||||
archiveAsScreenshot: undefined as unknown as boolean,
|
||||
archiveAsMonolith: undefined as unknown as boolean,
|
||||
archiveAsPDF: undefined as unknown as boolean,
|
||||
});
|
||||
const [collectionOwner, setCollectionOwner] = useState<Partial<AccountSettings>>({});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchOwner = async () => {
|
||||
|
@ -217,7 +210,7 @@ export default function Index() {
|
|||
/>
|
||||
)}
|
||||
{activeCollection.members
|
||||
.sort((a, b) => (a.userId as number) - (b.userId as number))
|
||||
.sort((a, b) => (a.userId) - (b.userId))
|
||||
.map((e, i) => {
|
||||
return (
|
||||
<ProfilePhoto
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"use client";
|
||||
import getPublicCollectionData from "@/lib/client/getPublicCollectionData";
|
||||
import {
|
||||
AccountSettings,
|
||||
CollectionIncludingMembersAndLinkCount,
|
||||
Sort,
|
||||
ViewMode,
|
||||
|
@ -36,15 +37,7 @@ export default function PublicCollections() {
|
|||
|
||||
const router = useRouter();
|
||||
|
||||
const [collectionOwner, setCollectionOwner] = useState({
|
||||
id: null as unknown as number,
|
||||
name: "",
|
||||
username: "",
|
||||
image: "",
|
||||
archiveAsScreenshot: undefined as unknown as boolean,
|
||||
archiveAsMonolith: undefined as unknown as boolean,
|
||||
archiveAsPDF: undefined as unknown as boolean,
|
||||
});
|
||||
const [collectionOwner, setCollectionOwner] = useState<Partial<AccountSettings>>({});
|
||||
|
||||
const [searchFilter, setSearchFilter] = useState({
|
||||
name: true,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, ChangeEvent } from "react";
|
||||
import useAccountStore from "@/store/account";
|
||||
import { AccountSettings } from "@/types/global";
|
||||
import { toast } from "react-hot-toast";
|
||||
|
@ -54,8 +54,10 @@ export default function Account() {
|
|||
if (!objectIsEmpty(account)) setUser({ ...account });
|
||||
}, [account]);
|
||||
|
||||
const handleImageUpload = async (e: any) => {
|
||||
const file: File = e.target.files[0];
|
||||
const handleImageUpload = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return toast.error(t("image_upload_no_file_error"));
|
||||
|
||||
const fileExtension = file.name.split(".").pop()?.toLowerCase();
|
||||
const allowedExtensions = ["png", "jpeg", "jpg"];
|
||||
if (allowedExtensions.includes(fileExtension as string)) {
|
||||
|
@ -100,9 +102,10 @@ export default function Account() {
|
|||
setSubmitLoader(false);
|
||||
};
|
||||
|
||||
const importBookmarks = async (e: any, format: MigrationFormat) => {
|
||||
const importBookmarks = async (e: ChangeEvent<HTMLInputElement>, format: MigrationFormat) => {
|
||||
setSubmitLoader(true);
|
||||
const file: File = e.target.files[0];
|
||||
const file = e.target.files?.[0];
|
||||
|
||||
if (file) {
|
||||
var reader = new FileReader();
|
||||
reader.readAsText(file, "UTF-8");
|
||||
|
|
|
@ -117,6 +117,7 @@
|
|||
"applying_settings": "Applying settings...",
|
||||
"settings_applied": "Settings Applied!",
|
||||
"email_change_request": "Email change request sent. Please verify the new email address.",
|
||||
"image_upload_no_file_error": "No file selected. Please choose an image to upload.",
|
||||
"image_upload_size_error": "Please select a PNG or JPEG file that's less than 1MB.",
|
||||
"image_upload_format_error": "Invalid file format.",
|
||||
"importing_bookmarks": "Importing bookmarks...",
|
||||
|
|
|
@ -117,6 +117,7 @@
|
|||
"applying_settings": "Applicazione delle impostazioni in corso...",
|
||||
"settings_applied": "Impostazioni Applicate!",
|
||||
"email_change_request": "Richiesta di cambio email inviata. Per favore verifica il nuovo indirizzo email.",
|
||||
"image_upload_no_file_error": "Nessun file selezionato. Scegli un'immagine da caricare.",
|
||||
"image_upload_size_error": "Per favore seleziona un file PNG o JPEG di dimensioni inferiori a 1MB.",
|
||||
"image_upload_format_error": "Formato file non valido.",
|
||||
"importing_bookmarks": "Importazione dei segnalibri in corso...",
|
||||
|
@ -367,4 +368,4 @@
|
|||
"server_administration": "Amministrazione Server",
|
||||
"all_collections": "Tutte le Collezioni",
|
||||
"dashboard": "Dashboard"
|
||||
}
|
||||
}
|
Ŝarĝante…
Reference in New Issue