From 85b30f770cf24f425b126210280e37f455e25a97 Mon Sep 17 00:00:00 2001
From: Ren Amamiya <123083837+reyamir@users.noreply.github.com>
Date: Sat, 24 Jun 2023 18:31:40 +0700
Subject: [PATCH] wip
---
.eslintrc | 18 --
global.d.ts | 7 -
index.html | 11 +
package.json | 10 +-
pnpm-lock.yaml | 268 +++++++++---------
postcss.config.js | 8 +-
src-tauri/tauri.conf.json | 2 +-
src/app.tsx | 91 ++++++
src/app/auth/_default.page.tsx | 1 -
src/app/auth/components/user.tsx | 60 ++--
src/app/auth/create/index.tsx | 9 +
src/app/auth/create/step-1.tsx | 105 +++++++
src/app/auth/create/step-2.tsx | 112 ++++++++
src/app/auth/create/step-3.tsx | 95 +++++++
.../index.page.tsx => create/step-4.tsx} | 137 ++++-----
src/app/auth/import/index.tsx | 9 +
src/app/auth/import/step-1.tsx | 111 ++++++++
src/app/auth/import/step-2.tsx | 81 ++++++
src/app/auth/layout.tsx | 65 -----
.../index.page.tsx => auth/onboarding.tsx} | 30 +-
src/app/auth/pages/create/index.page.tsx | 90 ------
.../auth/pages/create/step-2/index.page.tsx | 120 --------
.../auth/pages/create/step-3/index.page.tsx | 102 -------
src/app/auth/pages/import/index.page.tsx | 99 -------
.../auth/pages/import/step-2/index.page.tsx | 78 -----
.../{pages/index.page.tsx => welcome.tsx} | 15 +-
src/app/channel/_default.page.tsx | 1 -
src/app/channel/components/createModal.tsx | 36 ++-
src/app/channel/components/item.tsx | 33 +--
src/app/channel/components/list.tsx | 45 ++-
src/app/channel/components/members.tsx | 14 +-
src/app/channel/components/messages/form.tsx | 5 +-
src/app/channel/hooks/useChannelProfile.tsx | 24 +-
.../{pages/index.page.tsx => index.tsx} | 67 +++--
src/app/chat/_default.page.tsx | 1 -
src/app/chat/components/item.tsx | 30 +-
src/app/chat/components/list.tsx | 65 +++--
src/app/chat/components/messageList.tsx | 85 ------
src/app/chat/components/modal.tsx | 18 +-
src/app/chat/components/self.tsx | 27 +-
src/app/chat/components/sidebar.tsx | 5 +-
src/app/chat/index.tsx | 110 +++++++
src/app/chat/pages/index.page.tsx | 85 ------
src/app/error.tsx | 17 ++
src/app/index/_default.page.route.tsx | 1 -
src/app/index/pages/index.page.tsx | 29 --
src/app/onboarding/_default.page.tsx | 1 -
.../onboarding/pages/step-1/index.page.tsx | 11 -
.../pages/index.page.tsx => root.tsx} | 29 +-
src/app/space/_default.page.tsx | 1 -
src/app/space/components/blocks/feed.tsx | 86 +++---
src/app/space/components/blocks/following.tsx | 112 ++++----
src/app/space/components/blocks/thread.tsx | 17 +-
.../space/{pages/index.page.tsx => index.tsx} | 13 +-
src/app/trending/_default.page.tsx | 1 -
src/app/trending/components/profile.tsx | 21 +-
src/app/trending/components/trendingNotes.tsx | 16 +-
.../trending/components/trendingProfiles.tsx | 16 +-
.../{pages/index.page.tsx => index.tsx} | 2 +-
src/app/user/_default.page.tsx | 1 -
.../user/{pages/index.page.tsx => index.tsx} | 25 +-
src/{renderer => }/index.css | 0
src/libs/storage.tsx | 40 ++-
src/main.tsx | 6 +
src/renderer/_default.page.client.tsx | 40 ---
src/renderer/_default.page.server.tsx | 42 ---
src/renderer/_error.page.tsx | 17 --
src/renderer/layoutDefault.tsx | 7 -
src/renderer/shell.tsx | 41 ---
src/renderer/types.ts | 35 ---
src/shared/accounts/active.tsx | 35 +--
src/shared/activeLink.tsx | 27 --
src/shared/appHeader.tsx | 7 +-
src/shared/appLayout.tsx | 16 ++
.../layout.tsx => shared/authLayout.tsx} | 24 +-
src/shared/composer/modal.tsx | 3 +-
src/shared/layout.tsx | 23 --
src/shared/link.tsx | 18 --
src/shared/multiAccounts.tsx | 44 +--
src/shared/navigation.tsx | 33 ++-
src/shared/notes/mentions/note.tsx | 11 +-
src/shared/notes/mentions/user.tsx | 4 +-
src/shared/notes/metadata.tsx | 103 +++----
src/shared/notes/parent.tsx | 11 +-
src/shared/notes/preview/link.tsx | 39 ++-
src/shared/notes/preview/video.tsx | 10 +-
src/shared/notes/replies/form.tsx | 63 ++--
src/shared/notes/replies/list.tsx | 8 +-
src/shared/notes/repost.tsx | 11 +-
src/shared/protected.tsx | 13 +
src/shared/relayProvider.tsx | 5 +-
src/shared/user.tsx | 6 +-
src/stores/constants.tsx | 1 -
src/stores/onboarding.tsx | 17 ++
src/utils/hooks/useAccount.tsx | 11 +
src/utils/hooks/useEvent.tsx | 55 ++--
src/utils/hooks/useOpenGraph.tsx | 59 ++--
src/utils/hooks/useProfile.tsx | 64 ++---
src/utils/parser.tsx | 38 ++-
tailwind.config.js | 59 +---
tsconfig.json | 2 +-
vite.config.ts | 26 +-
102 files changed, 1844 insertions(+), 2014 deletions(-)
delete mode 100644 .eslintrc
delete mode 100644 global.d.ts
create mode 100644 index.html
create mode 100644 src/app.tsx
delete mode 100644 src/app/auth/_default.page.tsx
create mode 100644 src/app/auth/create/index.tsx
create mode 100644 src/app/auth/create/step-1.tsx
create mode 100644 src/app/auth/create/step-2.tsx
create mode 100644 src/app/auth/create/step-3.tsx
rename src/app/auth/{pages/create/step-4/index.page.tsx => create/step-4.tsx} (62%)
create mode 100644 src/app/auth/import/index.tsx
create mode 100644 src/app/auth/import/step-1.tsx
create mode 100644 src/app/auth/import/step-2.tsx
delete mode 100644 src/app/auth/layout.tsx
rename src/app/{onboarding/pages/index.page.tsx => auth/onboarding.tsx} (82%)
delete mode 100644 src/app/auth/pages/create/index.page.tsx
delete mode 100644 src/app/auth/pages/create/step-2/index.page.tsx
delete mode 100644 src/app/auth/pages/create/step-3/index.page.tsx
delete mode 100644 src/app/auth/pages/import/index.page.tsx
delete mode 100644 src/app/auth/pages/import/step-2/index.page.tsx
rename src/app/auth/{pages/index.page.tsx => welcome.tsx} (91%)
delete mode 100644 src/app/channel/_default.page.tsx
rename src/app/channel/{pages/index.page.tsx => index.tsx} (78%)
delete mode 100644 src/app/chat/_default.page.tsx
delete mode 100644 src/app/chat/components/messageList.tsx
create mode 100644 src/app/chat/index.tsx
delete mode 100644 src/app/chat/pages/index.page.tsx
create mode 100644 src/app/error.tsx
delete mode 100644 src/app/index/_default.page.route.tsx
delete mode 100644 src/app/index/pages/index.page.tsx
delete mode 100644 src/app/onboarding/_default.page.tsx
delete mode 100644 src/app/onboarding/pages/step-1/index.page.tsx
rename src/app/{prefetch/pages/index.page.tsx => root.tsx} (91%)
delete mode 100644 src/app/space/_default.page.tsx
rename src/app/space/{pages/index.page.tsx => index.tsx} (75%)
delete mode 100644 src/app/trending/_default.page.tsx
rename src/app/trending/{pages/index.page.tsx => index.tsx} (90%)
delete mode 100644 src/app/user/_default.page.tsx
rename src/app/user/{pages/index.page.tsx => index.tsx} (93%)
rename src/{renderer => }/index.css (100%)
create mode 100644 src/main.tsx
delete mode 100644 src/renderer/_default.page.client.tsx
delete mode 100644 src/renderer/_default.page.server.tsx
delete mode 100644 src/renderer/_error.page.tsx
delete mode 100644 src/renderer/layoutDefault.tsx
delete mode 100644 src/renderer/shell.tsx
delete mode 100644 src/renderer/types.ts
delete mode 100644 src/shared/activeLink.tsx
create mode 100644 src/shared/appLayout.tsx
rename src/{app/onboarding/layout.tsx => shared/authLayout.tsx} (69%)
delete mode 100644 src/shared/layout.tsx
delete mode 100644 src/shared/link.tsx
create mode 100644 src/shared/protected.tsx
create mode 100644 src/stores/onboarding.tsx
create mode 100644 src/utils/hooks/useAccount.tsx
diff --git a/.eslintrc b/.eslintrc
deleted file mode 100644
index 0ada66f1..00000000
--- a/.eslintrc
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "parser": "@typescript-eslint/parser",
- "plugins": ["@typescript-eslint", "react-refresh"],
- "extends": [
- "plugin:react/recommended",
- "plugin:react/jsx-runtime",
- "plugin:react-hooks/recommended",
- "plugin:@typescript-eslint/recommended",
- "prettier"
- ],
- "rules": {
- "@typescript-eslint/no-unused-vars": "error",
- "@typescript-eslint/no-explicit-any": "warn",
- "react-refresh/only-export-components": "error",
- "react/no-unknown-property": ["error", { "ignore": ["fetchpriority"] }]
- },
- "ignorePatterns": ["dist", "**/*.js", "**/*.json", "node_modules"]
-}
diff --git a/global.d.ts b/global.d.ts
deleted file mode 100644
index 94a6189c..00000000
--- a/global.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { AriaAttributes, DOMAttributes } from 'react';
-
-declare module 'react' {
- interface HTMLAttributes
Loading...
} - {!data ? ( + {status === "loading" || isFetching ? (Loading...
) : ( data.map((member: { pubkey: string }) => ( diff --git a/src/app/channel/components/messages/form.tsx b/src/app/channel/components/messages/form.tsx index 00ffeacc..b6a3edae 100644 --- a/src/app/channel/components/messages/form.tsx +++ b/src/app/channel/components/messages/form.tsx @@ -3,14 +3,13 @@ import { NDKEvent, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk"; import { CancelIcon, EnterIcon } from "@shared/icons"; import { MediaUploader } from "@shared/mediaUploader"; import { RelayContext } from "@shared/relayProvider"; -import { useActiveAccount } from "@stores/accounts"; import { useChannelMessages } from "@stores/channels"; import { dateToUnix } from "@utils/date"; +import { useAccount } from "@utils/hooks/useAccount"; import { useContext, useState } from "react"; export function ChannelMessageForm({ channelID }: { channelID: string }) { const ndk = useContext(RelayContext); - const account = useActiveAccount((state: any) => state.account); const [value, setValue] = useState(""); const [replyTo, closeReply] = useChannelMessages((state: any) => [ @@ -18,6 +17,8 @@ export function ChannelMessageForm({ channelID }: { channelID: string }) { state.closeReply, ]); + const { account } = useAccount(); + const submit = () => { let tags: string[][]; diff --git a/src/app/channel/hooks/useChannelProfile.tsx b/src/app/channel/hooks/useChannelProfile.tsx index 084077bf..3aab45d8 100644 --- a/src/app/channel/hooks/useChannelProfile.tsx +++ b/src/app/channel/hooks/useChannelProfile.tsx @@ -1,23 +1,15 @@ import { getChannel, updateChannelMetadata } from "@libs/storage"; import { RelayContext } from "@shared/relayProvider"; -import { useContext } from "react"; -import useSWR from "swr"; -import useSWRSubscription from "swr/subscription"; - -const fetcher = async ([, id]) => { - const result = await getChannel(id); - if (result) { - return result; - } else { - return null; - } -}; +import { useQuery } from "@tanstack/react-query"; +import { useContext, useEffect } from "react"; export function useChannelProfile(id: string) { const ndk = useContext(RelayContext); - const { data, mutate } = useSWR(["channel-metadata", id], fetcher); + const { data } = useQuery(["channel-metadata", id], async () => { + return await getChannel(id); + }); - useSWRSubscription(data ? ["channel-metadata", id] : null, () => { + useEffect(() => { // subscribe to channel const sub = ndk.subscribe( { @@ -32,14 +24,12 @@ export function useChannelProfile(id: string) { sub.addListener("event", (event: { content: string }) => { // update in local database updateChannelMetadata(id, event.content); - // revaildate - mutate(); }); return () => { sub.stop(); }; - }); + }, []); return data; } diff --git a/src/app/channel/pages/index.page.tsx b/src/app/channel/index.tsx similarity index 78% rename from src/app/channel/pages/index.page.tsx rename to src/app/channel/index.tsx index b4247f1f..e2e6699f 100644 --- a/src/app/channel/pages/index.page.tsx +++ b/src/app/channel/index.tsx @@ -1,15 +1,20 @@ -import { ChannelMessageItem } from "../components/messages/item"; +import { ChannelMessageItem } from "./components/messages/item"; import { ChannelMembers } from "@app/channel/components/members"; import { ChannelMessageForm } from "@app/channel/components/messages/form"; import { ChannelMetadata } from "@app/channel/components/metadata"; import { RelayContext } from "@shared/relayProvider"; import { useChannelMessages } from "@stores/channels"; import { dateToUnix, getHourAgo } from "@utils/date"; -import { usePageContext } from "@utils/hooks/usePageContext"; import { LumeEvent } from "@utils/types"; -import { useCallback, useContext, useEffect, useRef } from "react"; +import { + useCallback, + useContext, + useEffect, + useLayoutEffect, + useRef, +} from "react"; +import { useParams } from "react-router-dom"; import { Virtuoso } from "react-virtuoso"; -import useSWRSubscription from "swr/subscription"; const now = new Date(); @@ -42,13 +47,11 @@ const Empty = (- You two didn't talk yet, let's send first message -
-Loading...
} - {!data ? ( + {status === "loading" || isFetching ? (Loading...
) : ( data.map((pleb) => ( diff --git a/src/app/chat/components/self.tsx b/src/app/chat/components/self.tsx index b90bb8f1..2aff0685 100644 --- a/src/app/chat/components/self.tsx +++ b/src/app/chat/components/self.tsx @@ -1,21 +1,16 @@ import { Image } from "@shared/image"; -import { Link } from "@shared/link"; import { DEFAULT_AVATAR } from "@stores/constants"; -import { usePageContext } from "@utils/hooks/usePageContext"; import { useProfile } from "@utils/hooks/useProfile"; import { shortenKey } from "@utils/shortenKey"; +import { NavLink } from "react-router-dom"; import { twMerge } from "tailwind-merge"; export function ChatsListSelfItem({ data }: { data: any }) { - const pageContext = usePageContext(); - const searchParams: any = pageContext.urlParsed.search; - const pagePubkey = searchParams.pubkey; - - const { user, isLoading } = useProfile(data.pubkey); + const { status, user, isFetching } = useProfile(data.pubkey); return ( <> - {isLoading && !user ? ( + {status === "loading" && isFetching ? (Loading...
+ ) : ( ++ You two didn't talk yet, let's send first message +
+Sorry, an unexpected error has occurred.
++ {error.statusText || error.message} +
+Failed to fetch user stats
} - {!userStats ? ( + {status === "loading" || isFetching ? (Loading...
) : (Failed to load...
} - {!data ? ( + {status === "loading" || isFetching ? (Failed to load...
} - {!data ? ( + {status === "loading" || isFetching ? (This page could not be found.
- > - ); - } else { - return ( - <> -Something went wrong.
- > - ); - } -} diff --git a/src/renderer/layoutDefault.tsx b/src/renderer/layoutDefault.tsx deleted file mode 100644 index 4c33ab8b..00000000 --- a/src/renderer/layoutDefault.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export function LayoutDefault({ children }: { children: React.ReactNode }) { - return ( -failed to load
} - {isLoading || !data ? ( + {isFetching || status === "loading" ? (+ Can't fetch open graph, click to open website directly +
+ + {domain.hostname} + + ) : ( - {data["og:image"] && ( + {isValidURL(data["og:image"]) ? (Loading...
++ Reply as +
++ {user?.nip05 || user?.name} +
+- Reply as -
-- {user?.nip05 || user?.name} -
+