diff --git a/apps/electron/src/renderer/src/components/ExtensionApp/DetailApp.tsx b/apps/electron/src/renderer/src/components/ExtensionApp/DetailApp.tsx index 21f817e6..ffccf65b 100644 --- a/apps/electron/src/renderer/src/components/ExtensionApp/DetailApp.tsx +++ b/apps/electron/src/renderer/src/components/ExtensionApp/DetailApp.tsx @@ -2,6 +2,7 @@ import { PropsWithChildren, ReactNode, useEffect, useMemo } from 'react' import { tinykeys } from 'tinykeys' import { Kbd } from '@penx/components/Kbd' import { cn } from '@penx/utils' +import { useCurrentCommand } from '~/hooks/useCurrentCommand' import { ICommandItem } from '~/lib/types' import { ListItemIcon } from '../Panel/ListItemIcon' import { SearchInput } from '../Panel/SearchBar/SearchInput' @@ -24,13 +25,13 @@ interface IConfirm { interface Props { className?: string bodyClassName?: string - command: ICommandItem actions?: ReactNode confirm?: IConfirm hideHeader?: boolean hideFooter?: boolean headerBordered?: boolean title?: ReactNode + footerPostfix?: ReactNode showSearch?: boolean } @@ -38,20 +39,23 @@ export function DetailApp({ className, bodyClassName, children, - command, actions, confirm, hideHeader = false, hideFooter = false, headerBordered = true, showSearch = false, + footerPostfix, title, }: PropsWithChildren) { + const { currentCommand: command } = useCurrentCommand() const itemIcon = useMemo(() => { const assets = command?.data?.assets || {} - return assets[command.icon as string] || command.icon + return assets[command?.icon as string] || command?.icon }, [command]) + if (!command) return
Henel
+ return (
{!hideHeader && ( @@ -95,6 +99,7 @@ export function DetailApp({
{actions} {confirm && } + {footerPostfix} )} diff --git a/apps/electron/src/renderer/src/components/ExtensionApp/ListApp.tsx b/apps/electron/src/renderer/src/components/ExtensionApp/ListApp.tsx index cb5e7154..a3bb64f0 100644 --- a/apps/electron/src/renderer/src/components/ExtensionApp/ListApp.tsx +++ b/apps/electron/src/renderer/src/components/ExtensionApp/ListApp.tsx @@ -10,6 +10,7 @@ import { tinykeys } from 'tinykeys' import { Kbd } from '@penx/components/Kbd' import { Separator } from '@penx/uikit/ui/separator' import { cn } from '@penx/utils' +import { useCurrentCommand } from '~/hooks/useCurrentCommand' import { useValue } from '~/hooks/useValue' import { ICommandItem } from '~/lib/types' import { ListItemIcon } from '../Panel/ListItemIcon' @@ -35,7 +36,6 @@ interface IConfirm { interface Props { className?: string bodyClassName?: string - command: ICommandItem confirm?: IConfirm hideFooter?: boolean headerBordered?: boolean @@ -48,12 +48,13 @@ export function ListApp({ isLoading, bodyClassName, children, - command, confirm, hideFooter = false, headerBordered = true, isDetailVisible, }: PropsWithChildren) { + const { currentCommand: command } = useCurrentCommand() + const itemIcon = useMemo(() => { const assets = command?.data?.assets || {} return assets[command.icon as string] || command.icon diff --git a/apps/electron/src/renderer/src/components/Panel/CommandApp/DatabaseApp/ColumnList.tsx b/apps/electron/src/renderer/src/components/Panel/CommandApp/DatabaseApp/ColumnList.tsx index 986714d4..dc934b3a 100644 --- a/apps/electron/src/renderer/src/components/Panel/CommandApp/DatabaseApp/ColumnList.tsx +++ b/apps/electron/src/renderer/src/components/Panel/CommandApp/DatabaseApp/ColumnList.tsx @@ -157,8 +157,7 @@ export const ColumnList = ({ struct }: Props) => { /> )} , - // document.body, - document.querySelector('#command-palette')!, + document.body, )} diff --git a/apps/electron/src/renderer/src/components/Panel/CommandPalette.tsx b/apps/electron/src/renderer/src/components/Panel/CommandPalette.tsx index 2b64b2bf..5b25fc75 100644 --- a/apps/electron/src/renderer/src/components/Panel/CommandPalette.tsx +++ b/apps/electron/src/renderer/src/components/Panel/CommandPalette.tsx @@ -82,10 +82,6 @@ export const CommandPalette = () => { return } - if (current.path === '/edit-struct') { - return - } - if (current.path === '/configure-shortcut') { return } @@ -120,6 +116,10 @@ export const CommandPalette = () => { return } + if (current.path === '/edit-struct') { + return + } + return ( <> {header} @@ -148,7 +148,7 @@ export const CommandPalette = () => { { diff --git a/apps/electron/src/renderer/src/components/Panel/Panel.tsx b/apps/electron/src/renderer/src/components/Panel/Panel.tsx index 7320a44e..aaed4354 100644 --- a/apps/electron/src/renderer/src/components/Panel/Panel.tsx +++ b/apps/electron/src/renderer/src/components/Panel/Panel.tsx @@ -1,5 +1,6 @@ import { setConfig } from '@fower/react' import { DashboardProviders } from '@penx/components/DashboardProviders' +import { PublishStructDialog } from '@penx/components/PublishStructDialog/PublishStructDialog' import { ThemeProvider } from '@penx/components/ThemeProvider' import { LocaleProvider } from '@penx/locales' import { WatchEvent } from '../WatchEvent' @@ -25,6 +26,7 @@ export function Panel() { disableTransitionOnChange > + diff --git a/apps/electron/src/renderer/src/components/Panel/SearchBar/RootActions.tsx b/apps/electron/src/renderer/src/components/Panel/SearchBar/RootActions.tsx index 9aec5cd1..2d74070f 100644 --- a/apps/electron/src/renderer/src/components/Panel/SearchBar/RootActions.tsx +++ b/apps/electron/src/renderer/src/components/Panel/SearchBar/RootActions.tsx @@ -105,6 +105,7 @@ export function RootActions({ command, close }: RootActionsProps) { shortcut="" onSelect={() => { push({ path: '/edit-struct' }) + setCurrentCommand(currentItem!) setStruct(struct.raw) close() }} diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageAIChat/PageAIChat.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageAIChat/PageAIChat.tsx index 79ee9d85..e5a516ad 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageAIChat/PageAIChat.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageAIChat/PageAIChat.tsx @@ -23,7 +23,6 @@ export function PageAIChat() { hideHeader hideFooter headerBordered={false} - command={currentCommand} >
diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageAICommand.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageAICommand.tsx index b5997750..ff781baf 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageAICommand.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageAICommand.tsx @@ -37,7 +37,6 @@ export function PageAICommand() { title={creation.title} hideFooter headerBordered={false} - command={currentCommand} >
Configure shortcut} - command={currentCommand} // actions={ // // Create} /> diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageCreateQuicklink.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageCreateQuicklink.tsx index a3535256..ba8ee5fe 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageCreateQuicklink.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageCreateQuicklink.tsx @@ -12,7 +12,6 @@ export function PageQuickInput() { const { currentCommand } = useCurrentCommand() return ( // Create} /> diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageCreateStruct.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageCreateStruct.tsx index 305d37e7..272059e2 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageCreateStruct.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageCreateStruct.tsx @@ -10,7 +10,6 @@ export function PageCreateStruct() { const { currentCommand } = useCurrentCommand() return ( { - navigation.replace({ path: '/edit-struct' }) + navigation.replace({ path: '/edit-struct' }) setStruct(struct) appEmitter.emit('REFRESH_COMMANDS') }} diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageEditCreation.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageEditCreation.tsx index f4cb9bc1..9b5ba43a 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageEditCreation.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageEditCreation.tsx @@ -10,14 +10,9 @@ export function PageEditCreation() { const { creation } = useCurrentCreation() const { currentCommand } = useCurrentCommand() const creationId = useMemo(() => { - console.log('111111111111creation:', creation) - if (creation) return creation.id - console.log('222222222222222') if (currentCommand?.data?.creation) { - console.log('33333333333333333333') - return currentCommand.data.creation.id } }, [creation, currentCommand]) @@ -34,7 +29,6 @@ export function PageEditCreation() { return ( diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageEditStruct.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageEditStruct.tsx index 8db60eb2..6d10fe29 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageEditStruct.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageEditStruct.tsx @@ -1,7 +1,16 @@ +import { Trans } from '@lingui/react/macro' import { DatabaseProvider } from '@penx/components/DatabaseProvider' +import { usePublishStructDialog } from '@penx/components/PublishStructDialog/usePublishStructDialog' import { EditStructForm } from '@penx/components/StructDialog/EditStructForm' import { useStructs } from '@penx/hooks/useStructs' +import { useStructTemplates } from '@penx/hooks/useStructTemplates' +import { isBuiltinStruct } from '@penx/libs/isBuiltinStruct' +import { useSession } from '@penx/session' +import { Button } from '@penx/uikit/ui/button' +import { DetailApp } from '~/components/ExtensionApp/DetailApp' import { useCurrentStruct } from '~/hooks/useCurrentStruct' +import { navigation } from '~/hooks/useNavigation' +import { openCommand } from '~/lib/openCommand' import { StructInfo } from '../CommandApp/DatabaseApp/StructInfo' export function PageEditStruct() { @@ -11,16 +20,43 @@ export function PageEditStruct() { const { structs } = useStructs() const struct = structs.find((s) => s.id === id)! + const { setState } = usePublishStructDialog() + const { session } = useSession() + useStructTemplates() + + function publish() { + if (!session) { + openCommand({ + id: 'account', + }) + return + } + setState({ + isOpen: true, + struct, + }) + } + return ( - -
-
- + + Publish Struct + + ) + } + > + +
+
+ +
+
+ +
-
- -
-
- + + ) } diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageLogin.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageLogin.tsx index 00a77211..d69e3503 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageLogin.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageLogin.tsx @@ -14,7 +14,6 @@ export function PageLogin() { className="" hideFooter headerBordered={false} - command={currentCommand} // actions={ // // Create} /> diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageQuickInput.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageQuickInput.tsx index f8012324..40faec53 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageQuickInput.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageQuickInput.tsx @@ -12,7 +12,6 @@ export function PageQuickInput() { const { currentCommand } = useCurrentCommand() return ( diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageSettings.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageSettings.tsx index db740fc2..ef8f3a4d 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageSettings.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageSettings.tsx @@ -26,7 +26,6 @@ export function PageSettings() { hideHeader hideFooter headerBordered={false} - command={currentCommand} // actions={ // // Create} /> diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageStructMarketplace.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageStructMarketplace.tsx index b2ab15b5..11c00adc 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageStructMarketplace.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageStructMarketplace.tsx @@ -13,13 +13,7 @@ export function PageStructMarketplace() { const { data = [], isLoading } = useStructTemplates() return ( - + {data.map((item, index) => ( + ) diff --git a/apps/electron/src/renderer/src/components/Panel/pages/PageTranslate.tsx b/apps/electron/src/renderer/src/components/Panel/pages/PageTranslate.tsx index e10973b4..079290b5 100644 --- a/apps/electron/src/renderer/src/components/Panel/pages/PageTranslate.tsx +++ b/apps/electron/src/renderer/src/components/Panel/pages/PageTranslate.tsx @@ -91,7 +91,6 @@ export function PageTranslate() { return ( // Create} /> diff --git a/apps/electron/src/renderer/src/hooks/useItems.ts b/apps/electron/src/renderer/src/hooks/useItems.ts index 57560cb1..c69e1f91 100644 --- a/apps/electron/src/renderer/src/hooks/useItems.ts +++ b/apps/electron/src/renderer/src/hooks/useItems.ts @@ -114,6 +114,8 @@ export function useLoadCommands() { queryKey: ['commands'], queryFn: () => { const structs = store.structs.get() + console.log('=========structs:', structs) + const creations = store.creations.get() const structCommands = structs.map((item) => { diff --git a/lingui.config.ts b/lingui.config.ts index 3d5ae05b..22e6f7af 100644 --- a/lingui.config.ts +++ b/lingui.config.ts @@ -26,7 +26,7 @@ export default { '/apps/**/*.{ts,tsx}', '/packages/**/*.{ts,tsx}', ], - exclude: ['**/node_modules/**'], + exclude: ['**/node_modules/**', '**/*.d.ts'], }, ], } diff --git a/packages/components/src/AppProvider/AppService.ts b/packages/components/src/AppProvider/AppService.ts index 63b0f6dc..121960ec 100644 --- a/packages/components/src/AppProvider/AppService.ts +++ b/packages/components/src/AppProvider/AppService.ts @@ -191,52 +191,38 @@ export class AppService { } as IShortcutNode) } - const imageStruct = structs.find((s) => s.props.type === StructType.IMAGE) - if (!imageStruct) { - const newStruct = generateStructNode({ - type: StructType.IMAGE, - name: t`Image`, - spaceId: space.id, - userId: space.userId, - areaId: area.id, - }) - await localDB.addStruct(newStruct) - structs.push(newStruct) - } + // const imageStruct = structs.find((s) => s.props.type === StructType.IMAGE) + // if (!imageStruct) { + // const newStruct = generateStructNode({ + // type: StructType.IMAGE, + // name: t`Image`, + // spaceId: space.id, + // userId: space.userId, + // areaId: area.id, + // }) + // await localDB.addStruct(newStruct) + // structs.push(newStruct) + // } - const snippetStruct = structs.find( - (s) => s.props.type === StructType.SNIPPET, - ) - - if (!snippetStruct) { - const newStruct = generateStructNode({ - type: StructType.SNIPPET, - name: t`Snippet`, - spaceId: space.id, - userId: space.userId, - areaId: area.id, - }) - await localDB.addStruct(newStruct) - structs.push(newStruct) - } - - const promptStruct = structs.find((s) => s.props.type === StructType.PROMPT) - if (!promptStruct) { - const newStruct = generateStructNode({ - type: StructType.PROMPT, - name: t`Prompt`, - spaceId: space.id, - userId: space.userId, - areaId: area.id, - }) - await localDB.addStruct(newStruct) - structs.push(newStruct) - } + // const promptStruct = structs.find((s) => s.props.type === StructType.PROMPT) + // if (!promptStruct) { + // const newStruct = generateStructNode({ + // type: StructType.PROMPT, + // name: t`Prompt`, + // spaceId: space.id, + // userId: space.userId, + // areaId: area.id, + // }) + // await localDB.addStruct(newStruct) + // structs.push(newStruct) + // } { const aiCommandStruct = structs.find( (s) => s.props.type === StructType.AI_COMMAND, ) + console.log('========aiCommandStruct:', aiCommandStruct) + if (!aiCommandStruct) { const newStruct = generateStructNode({ type: StructType.AI_COMMAND, @@ -245,25 +231,26 @@ export class AppService { userId: space.userId, areaId: area.id, }) + await localDB.addStruct(newStruct) structs.push(newStruct) } } - const quicklinkStruct = structs.find( - (s) => s.props.type === StructType.QUICK_LINK, - ) - if (!quicklinkStruct) { - const newStruct = generateStructNode({ - type: StructType.QUICK_LINK, - name: t`Quicklink`, - spaceId: space.id, - userId: space.userId, - areaId: area.id, - }) - await localDB.addStruct(newStruct) - structs.push(newStruct) - } + // const quicklinkStruct = structs.find( + // (s) => s.props.type === StructType.QUICK_LINK, + // ) + // if (!quicklinkStruct) { + // const newStruct = generateStructNode({ + // type: StructType.QUICK_LINK, + // name: t`Quicklink`, + // spaceId: space.id, + // userId: space.userId, + // areaId: area.id, + // }) + // await localDB.addStruct(newStruct) + // structs.push(newStruct) + // } structs = await fixTaskStruct(area.id, structs) structs = await fixBookmarkStruct(area.id, structs) diff --git a/packages/components/src/PublishStructDialog/PublishStructContent.tsx b/packages/components/src/PublishStructDialog/PublishStructContent.tsx index 2e3c7782..47c36699 100644 --- a/packages/components/src/PublishStructDialog/PublishStructContent.tsx +++ b/packages/components/src/PublishStructDialog/PublishStructContent.tsx @@ -1,6 +1,7 @@ 'use client' import { useState } from 'react' +import { t } from '@lingui/core/macro' import { useLingui } from '@lingui/react/macro' import { useMutation, useQuery } from '@tanstack/react-query' import { toast } from 'sonner' @@ -18,18 +19,27 @@ import { usePublishStructDialog } from './usePublishStructDialog' export function PublishStructContent() { const { isOpen, setIsOpen, struct } = usePublishStructDialog() const { isPending, mutateAsync } = useMutation({ - mutationKey: ['structTemplates'], + mutationKey: ['publishStruct'], mutationFn: api.publishStruct, }) const { i18n } = useLingui() const [type, setType] = useState(struct.type) - const { refetch } = useStructTemplates() + const { refetch, data: structTemplates, isLoading } = useStructTemplates() - if (!struct) return null + const publishedStruct = structTemplates?.find( + (item) => item.type === struct.type, + ) + + if (!struct || isLoading) + return ( +
+ +
+ ) return (
-
+ {/*
{struct.columns.map((column, index) => (
@@ -43,43 +53,47 @@ export function PublishStructContent() {
))} -
+
*/}
-
Unique code
+
Unique ID
setType( e.target.value - .toUpperCase() + .toLowerCase() .trim() - .replace(/[^(A-Z|0-9)]/g, ''), + .replace(/[^(a-z|0-9|\-)]/g, ''), ) } />