From b098c70e955a402572028a734bb5ff457ea2b515 Mon Sep 17 00:00:00 2001 From: AnnatarHe Date: Sat, 21 Mar 2026 23:57:55 +0800 Subject: [PATCH] refactor(ui): polish code quality across components Remove dead code (unused MetaMask comments, sign-in-with-apple), clean up console.log/error statements, replace TypeScript `any` with proper types, improve accessibility by using semantic {isOpen && ( (() => { - // if (!bg) { - // return undefined - // } - // return { - // // backgroundImage: `url(https://picsum.photos/${width}/${height}/?blur=10)` - // backgroundImage: `url(${bg})`, - // } - // }, []) - // TODO: 预处理 - // https://lokeshdhakar.com/projects/color-thief/#getting-started - // + dark theme or light theme return (
(null) - - // useEffect(() => { - // import('emoji-mart').then((EmojiMart) => { - // new EmojiMart.Picker({ - // ...props, - // // data: data as any, - // // ref - // }) - // }) - // }, []) - - // return
- return + return {}} /> } export default EmojiPicker diff --git a/src/components/input.tsx b/src/components/input.tsx index 3593418f..fe4ab644 100644 --- a/src/components/input.tsx +++ b/src/components/input.tsx @@ -38,7 +38,7 @@ function FieldInput(props: FieldInputProps) { (() => { try { return JSON.parse(props.data.metadata) - } catch (e) { - console.error(e) + } catch { return null } }, [props.data.metadata]) @@ -58,8 +57,9 @@ function NFTGallaryItem(props: NFTGallaryItemProps) { return
} return ( -
{ if (props.onClick) { props.onClick(props.data, realImageUrl) @@ -69,9 +69,6 @@ function NFTGallaryItem(props: NFTGallaryItemProps) {
{props.data.name} @@ -80,7 +77,7 @@ function NFTGallaryItem(props: NFTGallaryItemProps) { {metadata?.name ?? ''}
-
+ ) } diff --git a/src/components/nfts/nft-gallary.tsx b/src/components/nfts/nft-gallary.tsx index dc6c45fb..6f779a98 100644 --- a/src/components/nfts/nft-gallary.tsx +++ b/src/components/nfts/nft-gallary.tsx @@ -23,7 +23,19 @@ function NFTGallary(props: NFTGallaryProps) { }, [data?.me.nfts.edges]) if (loading) { - return loading NFTs... + return ( +
+ {Array.from({ length: 4 }).map((_, i) => ( +
+
+
+
+
+
+
+ ))} +
+ ) } if (!loading && nftList.length === 0) { diff --git a/src/components/preview/preview4.tsx b/src/components/preview/preview4.tsx index f63a6577..b84a20f9 100644 --- a/src/components/preview/preview4.tsx +++ b/src/components/preview/preview4.tsx @@ -54,8 +54,7 @@ function Preview(props: PreviewProps) { toast.success(t('app.clipping.preview.success')) }, - onError: (err: any) => { - console.log(err) + onError: (err: Error) => { toast.error(err.toString()) }, }) diff --git a/src/components/sign-in-with-apple/sign-in-with-apple.tsx b/src/components/sign-in-with-apple/sign-in-with-apple.tsx deleted file mode 100644 index 7c57a27c..00000000 --- a/src/components/sign-in-with-apple/sign-in-with-apple.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import { useCallback, useEffect } from 'react' - -import { SignInWithAppleOptions } from '../../constants/config' - -const scriptURL = - 'https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js' - -const scriptDomId = 'sign-in-with-app-script' -function SignInWithApple() { - useEffect(() => { - const has = document.querySelector(`#${scriptDomId}`) - if (has) { - return - } - const dom = document.createElement('script') - dom.src = scriptURL - document.body.appendChild(dom) - - function onScriptLoad() { - if (!window.AppleID) { - return - } - window.AppleID.auth.init(SignInWithAppleOptions) - } - - function onAppleSignInSuccess(data: any) { - console.log(data) - } - - function onAppleSignInFail(err: any) { - console.log(err) - } - - dom.addEventListener('load', onScriptLoad) - - //Listen for authorization success - document.addEventListener('AppleIDSignInOnSuccess', onAppleSignInSuccess) - //Listen for authorization failures - document.addEventListener('AppleIDSignInOnFailure', onAppleSignInFail) - - return () => { - document.removeEventListener( - 'AppleIDSignInOnSuccess', - onAppleSignInSuccess - ) - document.removeEventListener('AppleIDSignInOnFailure', onAppleSignInFail) - document.removeChild(dom) - } - }, []) - - const onSignin = useCallback(async () => { - const response = await window.AppleID?.auth.signIn() - return response - }, []) - - return ( -
- -
- ) -} - -export default SignInWithApple diff --git a/src/hooks/my-file.tsx b/src/hooks/my-file.tsx index ff575359..607c7709 100644 --- a/src/hooks/my-file.tsx +++ b/src/hooks/my-file.tsx @@ -56,10 +56,9 @@ export function useUploadData(_: boolean, willSyncServer: boolean) { try { send({ type: 'Next' }) str = await extraFile(file) - } catch (e: any) { - console.error(e, e.toString()) + } catch (e: unknown) { send({ type: 'Error' }) - setMessages((m) => m.concat(e.toString())) + setMessages((m) => m.concat(e instanceof Error ? e.message : String(e))) return } @@ -83,8 +82,8 @@ export function useUploadData(_: boolean, willSyncServer: boolean) { try { const v = JSON.parse(uploadedClippingValue) as string[] uploadedClippings = new Set(v) - } catch (e) { - console.error(e) + } catch { + // ignore invalid cached data } } const allDigests = await Promise.all( @@ -131,8 +130,8 @@ export function useUploadData(_: boolean, willSyncServer: boolean) { if (resp.count > 0) { i.bookId = resp.books[0].doubanId.toString() } - } catch (e: any) { - setMessages((m) => m.concat(e.toString())) + } catch (e: unknown) { + setMessages((m) => m.concat(e instanceof Error ? e.message : String(e))) } finally { wenquSearchResult.current.set(i.title, i.bookId ? ~~i.bookId : 0) } @@ -199,9 +198,9 @@ export function useUploadData(_: boolean, willSyncServer: boolean) { setAt(chunkedData.length) toast.success(t('app.upload.tips.done')) send({ type: 'Next' }) - } catch (e: any) { + } catch (e: unknown) { send({ type: 'Error' }) - setMessages((m) => m.concat(e.toString())) + setMessages((m) => m.concat(e instanceof Error ? e.message : String(e))) } finally { client.resetStore() }