Merge branch 'feat/handle-files' into dev

This commit is contained in:
Daniel
2023-12-02 21:58:23 +03:30
committed by GitHub
19 changed files with 179 additions and 29 deletions
+5 -4
View File
@@ -16,7 +16,7 @@ import useAccountStore from "@/store/account";
import { faCalendarDays } from "@fortawesome/free-regular-svg-icons";
import usePermissions from "@/hooks/usePermissions";
import { toast } from "react-hot-toast";
import isValidUrl from "@/lib/client/isValidUrl";
import isValidUrl from "@/lib/shared/isValidUrl";
import Link from "next/link";
import unescapeString from "@/lib/client/unescapeString";
import { useRouter } from "next/router";
@@ -43,7 +43,7 @@ export default function LinkCard({ link, count, className }: Props) {
let shortendURL;
try {
shortendURL = new URL(link.url).host.toLowerCase();
shortendURL = new URL(link.url || "").host.toLowerCase();
} catch (error) {
console.log(error);
}
@@ -108,7 +108,8 @@ export default function LinkCard({ link, count, className }: Props) {
response.ok && toast.success(`Link Deleted.`);
};
const url = isValidUrl(link.url) ? new URL(link.url) : undefined;
const url =
isValidUrl(link.url || "") && link.url ? new URL(link.url) : undefined;
const formattedDate = new Date(link.createdAt as string).toLocaleString(
"en-US",
@@ -272,7 +273,7 @@ export default function LinkCard({ link, count, className }: Props) {
) : undefined} */}
<Link
href={link.url}
href={link.url || ""}
target="_blank"
onClick={(e) => {
e.stopPropagation();
+1 -1
View File
@@ -2,7 +2,7 @@ import { faFolder, faLink } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import Image from "next/image";
import { faCalendarDays } from "@fortawesome/free-regular-svg-icons";
import isValidUrl from "@/lib/client/isValidUrl";
import isValidUrl from "@/lib/shared/isValidUrl";
import A from "next/link";
import unescapeString from "@/lib/client/unescapeString";
import { Link } from "@prisma/client";
+4 -3
View File
@@ -44,6 +44,7 @@ export default function AddOrEditLink({
activeLink || {
name: "",
url: "",
type: "",
description: "",
tags: [],
screenshotPath: "",
@@ -139,10 +140,10 @@ export default function AddOrEditLink({
{method === "UPDATE" ? (
<div
className="text-neutral break-all w-full flex gap-2"
title={link.url}
title={link.url || ""}
>
<FontAwesomeIcon icon={faLink} className="w-6 h-6" />
<Link href={link.url} target="_blank" className="w-full">
<Link href={link.url || ""} target="_blank" className="w-full">
{link.url}
</Link>
</div>
@@ -153,7 +154,7 @@ export default function AddOrEditLink({
<div className="sm:col-span-3 col-span-5">
<p className="mb-2">Address (URL)</p>
<TextInput
value={link.url}
value={link.url || ""}
onChange={(e) => setLink({ ...link, url: e.target.value })}
placeholder="e.g. http://example.com/"
className="bg-base-200"
+7 -4
View File
@@ -76,8 +76,7 @@ export default function PreservedFormats() {
// Create a temporary link and click it to trigger the download
const link = document.createElement("a");
link.href = path;
link.download =
format === ArchivedFormat.screenshot ? "Screenshot" : "PDF";
link.download = format === ArchivedFormat.png ? "Screenshot" : "PDF";
link.click();
} else {
console.error("Failed to download file");
@@ -102,7 +101,7 @@ export default function PreservedFormats() {
<div className="flex gap-1">
<div
onClick={() => handleDownload(ArchivedFormat.screenshot)}
onClick={() => handleDownload(ArchivedFormat.png)}
className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"
>
<FontAwesomeIcon
@@ -112,7 +111,11 @@ export default function PreservedFormats() {
</div>
<Link
href={`/api/v1/archives/${link?.id}?format=${ArchivedFormat.screenshot}`}
href={`/api/v1/archives/${link?.id}?format=${
link.screenshotPath.endsWith("png")
? ArchivedFormat.png
: ArchivedFormat.jpeg
}`}
target="_blank"
className="cursor-pointer hover:opacity-60 duration-100 p-2 rounded-md"
>
+4 -4
View File
@@ -2,7 +2,7 @@ import { faChevronRight } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import Image from "next/image";
import { Link as LinkType, Tag } from "@prisma/client";
import isValidUrl from "@/lib/client/isValidUrl";
import isValidUrl from "@/lib/shared/isValidUrl";
import unescapeString from "@/lib/client/unescapeString";
import { TagIncludingLinkCount } from "@/types/global";
import Link from "next/link";
@@ -17,7 +17,7 @@ type Props = {
};
export default function LinkCard({ link, count }: Props) {
const url = isValidUrl(link.url) ? new URL(link.url) : undefined;
const url = link.url && isValidUrl(link.url) ? new URL(link.url) : undefined;
const formattedDate = new Date(
link.createdAt as unknown as string
@@ -68,10 +68,10 @@ export default function LinkCard({ link, count }: Props) {
<p>{formattedDate}</p>
<p>·</p>
<Link
href={url ? url.href : link.url}
href={url ? url.href : link.url || ""}
target="_blank"
className="hover:opacity-50 duration-100 truncate w-52 sm:w-fit"
title={url ? url.href : link.url}
title={url ? url.href : link.url || ""}
>
{url ? url.host : link.url}
</Link>