parent
de87639fce
commit
9a1fff74fd
@ -248,9 +248,7 @@ const OutLink = (props: Props) => {
|
|||||||
<Flex
|
<Flex
|
||||||
h={'full'}
|
h={'full'}
|
||||||
gap={4}
|
gap={4}
|
||||||
{...(isEmbed
|
{...(isEmbed ? { p: '0 !important', borderRadius: '0', boxShadow: 'none' } : { p: [0, 5] })}
|
||||||
? { p: '0 !important', insertProps: { borderRadius: '0', boxShadow: 'none' } }
|
|
||||||
: { p: [0, 5] })}
|
|
||||||
>
|
>
|
||||||
{(!quoteData || isPc) && (
|
{(!quoteData || isPc) && (
|
||||||
<PageContainer flex={'1 0 0'} w={0} isLoading={loading} p={'0 !important'}>
|
<PageContainer flex={'1 0 0'} w={0} isLoading={loading} p={'0 !important'}>
|
||||||
@ -316,12 +314,12 @@ const OutLink = (props: Props) => {
|
|||||||
|
|
||||||
const Render = (props: Props) => {
|
const Render = (props: Props) => {
|
||||||
const { shareId, authToken, customUid, appId } = props;
|
const { shareId, authToken, customUid, appId } = props;
|
||||||
const { localUId } = useShareChatStore();
|
const { localUId, setLocalUId, loaded } = useShareChatStore();
|
||||||
const { source, chatId, setSource, setAppId, setOutLinkAuthData } = useChatStore();
|
const { source, chatId, setSource, setAppId, setOutLinkAuthData } = useChatStore();
|
||||||
const { setUserDefaultLng } = useI18nLng();
|
const { setUserDefaultLng } = useI18nLng();
|
||||||
|
|
||||||
const chatHistoryProviderParams = useMemo(() => {
|
const chatHistoryProviderParams = useMemo(() => {
|
||||||
return { shareId, outLinkUid: authToken || customUid || localUId };
|
return { shareId, outLinkUid: authToken || customUid || localUId || '' };
|
||||||
}, [authToken, customUid, localUId, shareId]);
|
}, [authToken, customUid, localUId, shareId]);
|
||||||
const chatRecordProviderParams = useMemo(() => {
|
const chatRecordProviderParams = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
@ -338,20 +336,32 @@ const Render = (props: Props) => {
|
|||||||
setUserDefaultLng(true);
|
setUserDefaultLng(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set outLinkAuthData
|
// Set default localUId
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOutLinkAuthData({
|
if (loaded) {
|
||||||
shareId,
|
if (!localUId) {
|
||||||
outLinkUid: chatHistoryProviderParams.outLinkUid
|
setLocalUId(`shareChat-${Date.now()}-${getNanoid(24)}`);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
}, [loaded, localUId, setLocalUId]);
|
||||||
|
|
||||||
|
// Init outLinkAuthData
|
||||||
|
useEffect(() => {
|
||||||
|
if (chatHistoryProviderParams.outLinkUid) {
|
||||||
|
setOutLinkAuthData({
|
||||||
|
shareId,
|
||||||
|
outLinkUid: chatHistoryProviderParams.outLinkUid
|
||||||
|
});
|
||||||
|
}
|
||||||
return () => {
|
return () => {
|
||||||
setOutLinkAuthData({});
|
setOutLinkAuthData({});
|
||||||
};
|
};
|
||||||
}, [chatHistoryProviderParams.outLinkUid, shareId]);
|
}, [chatHistoryProviderParams.outLinkUid, setOutLinkAuthData, shareId]);
|
||||||
|
|
||||||
// Watch appId
|
// Watch appId
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAppId(appId);
|
setAppId(appId);
|
||||||
}, [appId]);
|
}, [appId, setAppId]);
|
||||||
|
|
||||||
return source === ChatSourceEnum.share ? (
|
return source === ChatSourceEnum.share ? (
|
||||||
<ChatContextProvider params={chatHistoryProviderParams}>
|
<ChatContextProvider params={chatHistoryProviderParams}>
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { devtools, persist } from 'zustand/middleware';
|
import { devtools, persist } from 'zustand/middleware';
|
||||||
import { immer } from 'zustand/middleware/immer';
|
import { immer } from 'zustand/middleware/immer';
|
||||||
import { customAlphabet } from 'nanoid';
|
|
||||||
const nanoid = customAlphabet(
|
|
||||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWSYZ1234567890_',
|
|
||||||
24
|
|
||||||
);
|
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
localUId: string;
|
localUId?: string;
|
||||||
|
setLocalUId: (localUId: string) => void;
|
||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -16,7 +12,10 @@ export const useShareChatStore = create<State>()(
|
|||||||
devtools(
|
devtools(
|
||||||
persist(
|
persist(
|
||||||
immer((set, get) => ({
|
immer((set, get) => ({
|
||||||
localUId: `shareChat-${Date.now()}-${nanoid()}`,
|
localUId: undefined,
|
||||||
|
setLocalUId(localUId: string) {
|
||||||
|
set({ localUId });
|
||||||
|
},
|
||||||
loaded: false
|
loaded: false
|
||||||
})),
|
})),
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user