From 36d51d96f89a0182fd59cd48ff175ea5e8009f2e Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 19 Sep 2024 15:06:45 +0800 Subject: [PATCH] feat: use user.handle default to share profile url Signed-off-by: Innei --- .../modules/profile/user-profile-modal.tsx | 4 +- .../(with-layout)/feed/[id]/index.tsx | 4 +- .../(with-layout)/feed/[id]/layout.tsx | 5 - .../pages/(external)/(with-layout)/layout.tsx | 2 +- .../(with-layout)/profile/[id]/index.tsx | 162 +++++++++--------- .../(with-layout)/profile/[id]/layout.tsx | 14 -- packages/shared/src/hono.ts | 77 ++++++--- 7 files changed, 145 insertions(+), 123 deletions(-) delete mode 100644 apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/layout.tsx delete mode 100644 apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/layout.tsx diff --git a/apps/renderer/src/modules/profile/user-profile-modal.tsx b/apps/renderer/src/modules/profile/user-profile-modal.tsx index 500c15507..876c01f73 100644 --- a/apps/renderer/src/modules/profile/user-profile-modal.tsx +++ b/apps/renderer/src/modules/profile/user-profile-modal.tsx @@ -217,7 +217,9 @@ export const UserProfileModalContent: FC<{ { - window.open(`${env.VITE_WEB_URL}/profile/${user.data?.id}`) + window.open( + `${env.VITE_WEB_URL}/profile/${user.data?.handle ? `@${user.data.handle}` : user.data?.id}`, + ) }} > diff --git a/apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx b/apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx index e9d99c847..a3a6ab47f 100644 --- a/apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx +++ b/apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/index.tsx @@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next" import { useParams, useSearchParams } from "react-router-dom" import { toast } from "sonner" +import { PoweredByFooter } from "~/components/common/PoweredByFooter" import { FeedIcon } from "~/components/feed-icon" import { FollowIcon } from "~/components/icons/follow" import { Button } from "~/components/ui/button" @@ -66,7 +67,7 @@ export function Component() { return ( <> {feed.isLoading ? ( - + ) : ( feed.data?.feed && (
@@ -151,6 +152,7 @@ export function Component() { ))}
+ ) )} diff --git a/apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/layout.tsx b/apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/layout.tsx deleted file mode 100644 index 79fdeaac4..000000000 --- a/apps/renderer/src/pages/(external)/(with-layout)/feed/[id]/layout.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { Outlet } from "react-router-dom" - -export function Component() { - return -} diff --git a/apps/renderer/src/pages/(external)/(with-layout)/layout.tsx b/apps/renderer/src/pages/(external)/(with-layout)/layout.tsx index fe38e43b6..6256712b7 100644 --- a/apps/renderer/src/pages/(external)/(with-layout)/layout.tsx +++ b/apps/renderer/src/pages/(external)/(with-layout)/layout.tsx @@ -6,7 +6,7 @@ export function Component() { return ( <>
-
+
diff --git a/apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx b/apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx index 409d6b843..498edaaf3 100644 --- a/apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx +++ b/apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx @@ -1,3 +1,4 @@ +import { Fragment } from "react/jsx-runtime" import { useParams } from "react-router-dom" import { useWhoami } from "~/atoms/user" @@ -18,10 +19,14 @@ export function Component() { const t = useI18n() const { id } = useParams() + const isHandle = id?.startsWith("@") const user = useAuthQuery( defineQuery(["profiles", id], async () => { const res = await apiClient.profiles.$get({ - query: { id: id! }, + query: { + handle: isHandle ? id?.slice(1) : undefined, + id: isHandle ? undefined : id, + }, }) return res.data }), @@ -36,84 +41,87 @@ export function Component() { const isMe = user.data?.id === me?.id const presentFeedFormModal = usePresentFeedFormModal() - return user.isLoading ? ( - - ) : ( -
- - - {user.data?.name?.slice(0, 2)} - -
-
-

{user.data?.name}

-
-
{user.data?.handle}
-
-
- {subscriptions.isLoading ? ( - - ) : ( - Object.keys(subscriptions.data || {}).map((category) => ( -
-
-

{category}

-
-
- {subscriptions.data?.[category].map((subscription) => ( -
- - -
-
- {subscription.feeds?.title} -
- {subscription.feeds?.description && ( -
- {subscription.feeds.description} -
- )} -
-
- - - -
- ))} -
+ return ( +
+ {user.isLoading ? ( + + ) : ( + + + + {user.data?.name?.slice(0, 2)} + +
+
+

{user.data?.name}

- )) - )} -
+
{user.data?.handle}
+
+
+ {subscriptions.isLoading ? ( + + ) : ( + Object.keys(subscriptions.data || {}).map((category) => ( +
+
+

{category}

+
+
+ {subscriptions.data?.[category].map((subscription) => ( +
+ + +
+
+ {subscription.feeds?.title} +
+ {subscription.feeds?.description && ( +
+ {subscription.feeds.description} +
+ )} +
+
+ + + +
+ ))} +
+
+ )) + )} +
+ + + )}
) } diff --git a/apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/layout.tsx b/apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/layout.tsx deleted file mode 100644 index bbc78787c..000000000 --- a/apps/renderer/src/pages/(external)/(with-layout)/profile/[id]/layout.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { Outlet } from "react-router-dom" - -export function Component() { - return ( - {}, - setActiveList: null, - }} - /> - ) -} diff --git a/packages/shared/src/hono.ts b/packages/shared/src/hono.ts index cfbacc604..ef708be2a 100644 --- a/packages/shared/src/hono.ts +++ b/packages/shared/src/hono.ts @@ -1,10 +1,10 @@ -import type { HttpBindings } from '@hono/node-server'; -import type * as drizzle_orm from 'drizzle-orm'; -import type { InferInsertModel } from 'drizzle-orm'; -import type * as drizzle_orm_pg_core from 'drizzle-orm/pg-core'; -import type * as hono_hono_base from 'hono/hono-base'; -import type * as zod from 'zod'; -import type { z } from 'zod'; +import * as hono_hono_base from 'hono/hono-base'; +import { HttpBindings } from '@hono/node-server'; +import * as drizzle_orm from 'drizzle-orm'; +import { InferInsertModel } from 'drizzle-orm'; +import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core'; +import * as zod from 'zod'; +import { z } from 'zod'; type Env = { Bindings: HttpBindings; @@ -189,7 +189,11 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{ }>; declare const actionsOpenAPISchema: z.ZodObject | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null, z.ZodTypeDef, string | number | boolean | Record | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null>>; + rules: z.ZodNullable>; }, "rules">, { rules: z.ZodNullable; insertedAt: z.ZodString; publishedAt: z.ZodString; - media: z.ZodNullable | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null, z.ZodTypeDef, string | number | boolean | Record | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null>>; + media: z.ZodNullable>; categories: z.ZodNullable>; - attachments: z.ZodNullable | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null, z.ZodTypeDef, string | number | boolean | Record | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null>>; + attachments: z.ZodNullable>; }, "media" | "attachments">, { attachments: z.ZodNullable; - updated: Record; + settings: { + [x: string]: any; + }; + updated: { + [x: string]: string; + }; }; outputFormat: "json" | "text"; status: 200; @@ -2913,7 +2929,9 @@ declare const _routes: hono_hono_base.HonoBase; + data: { + [x: string]: number; + }; }; outputFormat: "json" | "text"; status: 200; @@ -2955,7 +2973,8 @@ declare const _routes: hono_hono_base.HonoBase; + }; + }; entryReadHistories: { userIds: string[]; readCount: number; @@ -3370,12 +3391,14 @@ declare const _routes: hono_hono_base.HonoBase; + }; + }; entryReadHistories: { userIds: string[]; readCount: number; @@ -3509,13 +3532,17 @@ declare const _routes: hono_hono_base.HonoBase; + parameters: { + [x: string]: string; + }; path: string; example: string; name: string; @@ -3523,8 +3550,10 @@ declare const _routes: hono_hono_base.HonoBase; - }>; + }; + }; + }; + }; }; outputFormat: "json" | "text"; status: 200; @@ -3769,4 +3798,4 @@ declare const _routes: hono_hono_base.HonoBase; type AppType = typeof _routes; -export { accounts, actions, actionsItemOpenAPISchema, type ActionsModel, actionsOpenAPISchema, actionsRelations, type AppType, type AttachmentsModel, collections, collectionsOpenAPISchema, collectionsRelations, entries, type EntriesModel, entriesOpenAPISchema, entriesRelations, entryReadHistories, type EntryReadHistoriesModel, entryReadHistoriesOpenAPISchema, entryReadHistoriesRelations, type FeedModel, feedPowerTokens, feedPowerTokensOpenAPISchema, feedPowerTokensRelations, feeds, feedsInputSchema, feedsOpenAPISchema, feedsRelations, invitations, invitationsOpenAPISchema, invitationsRelations, languageSchema, type MediaModel, sessions, settings, type SettingsModel, subscriptions, subscriptionsOpenAPISchema, subscriptionsRelations, timeline, timelineOpenAPISchema, timelineRelations, transactions, transactionsOpenAPISchema, transactionsRelations, transactionType, users, usersOpenApiSchema, usersRelations, verificationTokens, wallets, walletsOpenAPISchema, walletsRelations }; +export { type ActionsModel, type AppType, type AttachmentsModel, type EntriesModel, type EntryReadHistoriesModel, type FeedModel, type MediaModel, type SettingsModel, accounts, actions, actionsItemOpenAPISchema, actionsOpenAPISchema, actionsRelations, collections, collectionsOpenAPISchema, collectionsRelations, entries, entriesOpenAPISchema, entriesRelations, entryReadHistories, entryReadHistoriesOpenAPISchema, entryReadHistoriesRelations, feedPowerTokens, feedPowerTokensOpenAPISchema, feedPowerTokensRelations, feeds, feedsInputSchema, feedsOpenAPISchema, feedsRelations, invitations, invitationsOpenAPISchema, invitationsRelations, languageSchema, sessions, settings, subscriptions, subscriptionsOpenAPISchema, subscriptionsRelations, timeline, timelineOpenAPISchema, timelineRelations, transactionType, transactions, transactionsOpenAPISchema, transactionsRelations, users, usersOpenApiSchema, usersRelations, verificationTokens, wallets, walletsOpenAPISchema, walletsRelations };