Links: renames

This commit is contained in:
Enrico Ros
2024-01-22 17:09:59 -08:00
parent 15cfef0f8b
commit 9dc8aaa9aa
7 changed files with 75 additions and 73 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import * as React from 'react';
import { AppChatLink } from '../../../src/apps/link/AppChatLink';
import { AppLinkChat } from '../../../src/apps/link/AppLinkChat';
import { useRouterQuery } from '~/common/app.routes';
import { withLayout } from '~/common/layout/withLayout';
@@ -11,5 +11,5 @@ export default function ChatLinkPage() {
// external state
const { chatLinkId } = useRouterQuery<{ chatLinkId: string | undefined }>();
return withLayout({ type: 'optima', suspendAutoModelsSetup: true }, <AppChatLink chatLinkId={chatLinkId || null} />);
return withLayout({ type: 'optima', suspendAutoModelsSetup: true }, <AppLinkChat chatLinkId={chatLinkId || null} />);
}
+1 -1
View File
@@ -30,7 +30,7 @@ import SettingsIcon from '@mui/icons-material/Settings';
import { Brand } from '~/common/app.config';
import { hasNoChatLinkItems } from '~/modules/trade/chatlink/store-chatlink';
import { hasNoChatLinkItems } from '~/modules/trade/link/store-link';
// enable to show all items, for layout development
+1 -1
View File
@@ -8,7 +8,7 @@ import { backendCaps } from '~/modules/backend/state-backend';
import { DConversationId, getConversation } from '~/common/state/store-chats';
import { ChatLinkExport } from './chatlink/ChatLinkExport';
import { ChatLinkExport } from './link/ChatLinkExport';
import { PublishExport } from './publish/PublishExport';
import { downloadAllConversationsJson, downloadConversationJson } from './trade.client';
@@ -1,67 +0,0 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import { shallow } from 'zustand/shallow';
interface ChatLinkItem {
chatTitle?: string;
objectId: string;
createdAt: string;
expiresAt: string | null;
deletionKey: string;
}
interface ModuleTradeStore {
// exported items
chatLinkItems: ChatLinkItem[];
rememberChatLinkItem: (chatTitle: string | undefined, objectId: string, createdAt: Date, expiresAt: Date | null, deletionKey: string) => void;
forgetChatLinkItem: (objectId: string) => void;
updateChatLinkDeletionKey: (objectId: string, deletionKey: string) => void;
// ID assigned by the server upon first PUT
linkStorageOwnerId: string | undefined;
setLinkStorageOwnerId: (linkStorageOwnerId: string) => void;
}
const useTradeStore = create<ModuleTradeStore>()(
persist(
(set) => ({
chatLinkItems: [],
rememberChatLinkItem: (chatTitle: string | undefined, objectId: string, createdAt: Date, expiresAt: Date | null, deletionKey: string) => set(state => ({
chatLinkItems: [...state.chatLinkItems, { chatTitle, objectId, createdAt: createdAt.toISOString(), expiresAt: expiresAt?.toISOString() ?? null, deletionKey }],
})),
forgetChatLinkItem: (objectId: string) => set(state => ({
chatLinkItems: state.chatLinkItems.filter(item => item.objectId !== objectId),
})),
updateChatLinkDeletionKey: (objectId: string, deletionKey: string) => set(state => ({
chatLinkItems: state.chatLinkItems.map(item => item.objectId === objectId ? { ...item, deletionKey } : item),
})),
linkStorageOwnerId: undefined,
setLinkStorageOwnerId: (linkStorageOwnerId: string) => set({ linkStorageOwnerId }),
}),
{
name: 'app-sharing',
},
),
);
// by AppChatLink
export const useChatLinkItems = () => useTradeStore(state => state.chatLinkItems, shallow);
export const useHasChatLinkItems = () => useTradeStore(state => state.chatLinkItems.length > 0);
// by ChatLinkExport
export const useLinkStorageOwnerId = () =>
useTradeStore(state => ({
linkStorageOwnerId: state.linkStorageOwnerId,
setLinkStorageOwnerId: state.setLinkStorageOwnerId,
}), shallow);
export const rememberChatLinkItem = useTradeStore.getState().rememberChatLinkItem;
export const forgetChatLinkItem = useTradeStore.getState().forgetChatLinkItem;
export const updateChatLinkDeletionKey = useTradeStore.getState().updateChatLinkDeletionKey;
export const hasNoChatLinkItems = () => !useTradeStore.getState().chatLinkItems.length;
@@ -23,7 +23,7 @@ import { getOriginUrl } from '~/common/util/urlUtils';
import { webShare, webSharePresent } from '~/common/util/pwaUtils';
import type { StorageDeleteSchema, StoragePutSchema } from '../server/link';
import { forgetChatLinkItem } from './store-chatlink';
import { forgetChatLinkItem } from './store-link';
export function ChatLinkDetails(props: {
@@ -15,7 +15,7 @@ import { useUICounter } from '~/common/state/store-ui';
import type { StoragePutSchema, StorageUpdateDeletionKeySchema } from '../server/link';
import { ChatLinkDetails } from './ChatLinkDetails';
import { conversationToJsonV1 } from '../trade.client';
import { rememberChatLinkItem, updateChatLinkDeletionKey, useLinkStorageOwnerId } from './store-chatlink';
import { rememberChatLinkItem, updateChatLinkDeletionKey, useLinkStorageOwnerId } from './store-link';
export function ChatLinkExport(props: {
+69
View File
@@ -0,0 +1,69 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import { shallow } from 'zustand/shallow';
export interface SharedChatLinkItem {
chatTitle?: string;
objectId: string;
createdAt: string;
expiresAt: string | null;
deletionKey: string;
}
interface LinkStore {
// exported items
chatLinkItems: SharedChatLinkItem[];
chatLinkItemAdd: (chatTitle: string | undefined, objectId: string, createdAt: Date, expiresAt: Date | null, deletionKey: string) => void;
chatLinkItemRemove: (objectId: string) => void;
chatLinkItemChangeDeletionKey: (objectId: string, deletionKey: string) => void;
// ID assigned by the server upon first PUT
linkStorageOwnerId: string | undefined;
setLinkStorageOwnerId: (linkStorageOwnerId: string) => void;
}
const useLinkStore = create<LinkStore>()(
persist(
(set) => ({
chatLinkItems: [],
chatLinkItemAdd: (chatTitle: string | undefined, objectId: string, createdAt: Date, expiresAt: Date | null, deletionKey: string) => set(state => ({
chatLinkItems: [...state.chatLinkItems, { chatTitle, objectId, createdAt: createdAt.toISOString(), expiresAt: expiresAt?.toISOString() ?? null, deletionKey }],
})),
chatLinkItemRemove: (objectId: string) => set(state => ({
chatLinkItems: state.chatLinkItems.filter(item => item.objectId !== objectId),
})),
chatLinkItemChangeDeletionKey: (objectId: string, deletionKey: string) => set(state => ({
chatLinkItems: state.chatLinkItems.map(item => item.objectId === objectId ? { ...item, deletionKey } : item),
})),
linkStorageOwnerId: undefined,
setLinkStorageOwnerId: (linkStorageOwnerId: string) => set({ linkStorageOwnerId }),
}),
{
name: 'app-sharing',
},
),
);
// by AppChatLink
export const useSharedChatLinkItems = () => useLinkStore(state => state.chatLinkItems, shallow);
// by ChatLinkExport/ChatLinkDetails
export const rememberChatLinkItem = useLinkStore.getState().chatLinkItemAdd;
export const updateChatLinkDeletionKey = useLinkStore.getState().chatLinkItemChangeDeletionKey;
export const forgetChatLinkItem = useLinkStore.getState().chatLinkItemRemove;
export const useLinkStorageOwnerId = () => useLinkStore(state => ({
linkStorageOwnerId: state.linkStorageOwnerId,
setLinkStorageOwnerId: state.setLinkStorageOwnerId,
}), shallow);
// by Nav
export function hasNoChatLinkItems() {
return !useLinkStore.getState().chatLinkItems.length;
}