feat(web): connect quick share flow

Signed-off-by: JustMe <mr.toing@outlook.com>
This commit is contained in:
justme committed 2026-10-02 00:59:37 +08:00
1 parent 53768a195d
commit e02e024605
138 files changed
+10614

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
import { create } from 'zustand';
import { api } from '@/core-bridge/instance';
import type { ChannelInfo, CreateOptions } from '@/core-bridge/types';
import type { ParsedChannelLink } from '@/lib/channelLink';
interface ChannelsState {
/** 我的频道(原型:只在内存里,刷新即清空;真实实现存 IndexedDB,architecture §6) */
list: ChannelInfo[];
/** 从链接进来、还没确认加入的频道;含密钥,只放内存 */
pendingLink: ParsedChannelLink | null;
/** 刚创建的频道:进入时直接展示分享面板与二维码 */
justCreatedId: string | null;
create: (opts: CreateOptions) => Promise<ChannelInfo>;
join: (link: ParsedChannelLink) => Promise<ChannelInfo>;
forget: (id: string) => void;
loadDemo: () => void;
setPendingLink: (link: ParsedChannelLink | null) => void;
clearJustCreated: () => void;
}
const upsert = (list: ChannelInfo[], c: ChannelInfo) => [c, ...list.filter((x) => x.id !== c.id)];
export const useChannels = create<ChannelsState>()((set) => ({
list: [],
pendingLink: null,
justCreatedId: null,
create: async (opts) => {
const c = await api.createChannel(opts);
set((s) => ({ list: upsert(s.list, c), justCreatedId: c.id }));
return c;
},
join: async (link) => {
const c = await api.joinChannel(link);
set((s) => ({ list: upsert(s.list, c), pendingLink: null }));
return c;
},
forget: (id) => set((s) => ({ list: s.list.filter((c) => c.id !== id) })),
loadDemo: () => {
const demo = api.loadDemo?.() ?? [];
set((s) => ({ list: demo.reduce(upsert, s.list) }));
},
setPendingLink: (link) => set({ pendingLink: link }),
clearJustCreated: () => set({ justCreatedId: null }),
}));