From fa1080b6e68879ec5862deb0e35909c45ca39c42 Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Thu, 14 Nov 2024 10:29:49 -0800 Subject: [PATCH 1/4] Move language detection to client side --- src/app/api/language-detection/route.ts | 14 -------------- src/lib/hooks/bsky/feed/usePublishPost.tsx | 4 ++-- src/lib/utils/text.ts | 19 +++++++------------ 3 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 src/app/api/language-detection/route.ts diff --git a/src/app/api/language-detection/route.ts b/src/app/api/language-detection/route.ts deleted file mode 100644 index ce658f3e..00000000 --- a/src/app/api/language-detection/route.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { detect } from "tinyld"; - -export async function POST(request: Request) { - const text = await request.text(); - - const detectLanguage = async (text = "") => { - const detected = await detect(text); - return detected; - }; - - return Response.json(await detectLanguage(text), { - status: 200, - }); -} diff --git a/src/lib/hooks/bsky/feed/usePublishPost.tsx b/src/lib/hooks/bsky/feed/usePublishPost.tsx index e362a477..43bf29e0 100644 --- a/src/lib/hooks/bsky/feed/usePublishPost.tsx +++ b/src/lib/hooks/bsky/feed/usePublishPost.tsx @@ -74,8 +74,8 @@ export default function usePublishPost(props: Props) { if (languages.length > 0) { lang = languages; } else { - const detectedLanguage = await detectLanguage(richText.text); - lang = detectedLanguage ?? []; + const detectedLanguage = detectLanguage(richText.text); + lang = detectedLanguage ? [detectedLanguage] : []; } let selfLabels: ComAtprotoLabelDefs.SelfLabels | undefined; diff --git a/src/lib/utils/text.ts b/src/lib/utils/text.ts index 51a58bb1..a441f875 100644 --- a/src/lib/utils/text.ts +++ b/src/lib/utils/text.ts @@ -1,7 +1,8 @@ import { JSONContent } from "@tiptap/react"; import { ThreadgateSetting } from "../../../types/feed"; import { PostView } from "@atproto/api/dist/client/types/app/bsky/feed/defs"; -import { AppBskyFeedPost, Facet, UnicodeString } from "@atproto/api"; +import { AppBskyFeedPost } from "@atproto/api"; +import { detect } from "tinyld"; export function getHandle(mention: string) { return mention.slice(1); @@ -86,24 +87,18 @@ export function jsonToText(json: JSONContent) { return text; } -export async function detectLanguage(text: string) { +export function detectLanguage(text: string) { if (text === "") return; - const res = await fetch(`/api/language-detection`, { - method: "post", - body: JSON.stringify({ - text: text, - }), - }); + const language = detect(text); - const detectedLanguage: string = await res.json(); - return [detectedLanguage.trim()]; + return language; } // TODO: add language prefs to localStorage to use for lang // the default is English for now export function getTranslateLink(text: string, lang: string = "en"): string { return `https://translate.google.com/?sl=auto&tl=${lang}&text=${encodeURIComponent( - text + text, )}`; } @@ -124,4 +119,4 @@ export const replyIncludes = (reply: PostView["record"], term: string) => { const text = AppBskyFeedPost.isRecord(reply) && reply.text; if (!text || !text.toLowerCase().includes(term.toLowerCase())) return false; return true; -}; \ No newline at end of file +}; From 9357a29d9fac349c82926699d918553abf18ce53 Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Tue, 19 Nov 2024 19:32:36 -0800 Subject: [PATCH 2/4] Remove extra bottom padding from composer --- src/components/inputs/editor/BottomEditorBar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/inputs/editor/BottomEditorBar.tsx b/src/components/inputs/editor/BottomEditorBar.tsx index a83780c8..c6fa7f13 100644 --- a/src/components/inputs/editor/BottomEditorBar.tsx +++ b/src/components/inputs/editor/BottomEditorBar.tsx @@ -77,7 +77,7 @@ export default function BottomEditorBar(props: Props) {
-
+
From c4c745d6246c1c61882f20835641cd44701ff562 Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Tue, 19 Nov 2024 19:38:16 -0800 Subject: [PATCH 3/4] Adjust aspect ratio for external embed images --- src/components/dataDisplay/postEmbed/ExternalEmbed.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/dataDisplay/postEmbed/ExternalEmbed.tsx b/src/components/dataDisplay/postEmbed/ExternalEmbed.tsx index 9d84a19b..351d36fe 100644 --- a/src/components/dataDisplay/postEmbed/ExternalEmbed.tsx +++ b/src/components/dataDisplay/postEmbed/ExternalEmbed.tsx @@ -29,7 +29,7 @@ export default function ExternalEmbed(props: Props) { width={900} height={500} priority - className="border-b-skin-base rounded-t-lg border-b aspect-auto max-h-96 object-cover group-hover:brightness-95" + className="border-b-skin-base rounded-t-lg border-b aspect-video max-h-96 object-cover group-hover:brightness-95" /> )}
From bf2f1a5fc8d8ad7ff15cb259ff827a7673d9a019 Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Tue, 19 Nov 2024 20:16:49 -0800 Subject: [PATCH 4/4] Increase visibility of alt text dialog --- .../dataDisplay/gallery/Gallery.tsx | 2 +- src/components/feedback/altTag/AltTag.tsx | 21 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/components/dataDisplay/gallery/Gallery.tsx b/src/components/dataDisplay/gallery/Gallery.tsx index 119423ef..fc34dc6b 100644 --- a/src/components/dataDisplay/gallery/Gallery.tsx +++ b/src/components/dataDisplay/gallery/Gallery.tsx @@ -43,7 +43,7 @@ export default function Gallery(props: Props) { break; } }, - [handleBackward, handleForward] + [handleBackward, handleForward], ); useEffect(() => { diff --git a/src/components/feedback/altTag/AltTag.tsx b/src/components/feedback/altTag/AltTag.tsx index cb73d837..9b630225 100644 --- a/src/components/feedback/altTag/AltTag.tsx +++ b/src/components/feedback/altTag/AltTag.tsx @@ -3,7 +3,6 @@ import { useState } from "react"; import * as Dialog from "@radix-ui/react-dialog"; import { CgClose } from "react-icons/cg"; import { useClipboard } from "use-clipboard-copy"; -import toast from "react-hot-toast"; import { BiSolidCopy } from "react-icons/bi"; interface Props { @@ -13,12 +12,7 @@ interface Props { export default function AltTag(props: Props) { const { text } = props; const [showAlt, setShowAlt] = useState(false); - const clipboard = useClipboard({ copiedTimeout: 3500 }); - - const handleCopyAltText = () => { - clipboard.copy(text); - toast.success("Alt text copied to clipboard", { id: "Copy alt text" }); - }; + const { copy, copied } = useClipboard({ copiedTimeout: 3500 }); const handleShowAlt = () => { setShowAlt(!showAlt); @@ -62,19 +56,20 @@ export default function AltTag(props: Props) { -
-
- +
+
+ Alternative text
- + {text}