diff --git a/frontend/apps/desktop/src/main.ts b/frontend/apps/desktop/src/main.ts index 790563fbf..fc014aa1a 100644 --- a/frontend/apps/desktop/src/main.ts +++ b/frontend/apps/desktop/src/main.ts @@ -176,7 +176,7 @@ ipcMain.on( const titleCounter: {[key: string]: number} = {} let success: {success: boolean; message: string} = { success: true, - message: `Successfully exported documents to: ${exportDir}.`, + message: exportDir, } for (const {title, markdown} of documents) { @@ -310,6 +310,9 @@ ipcMain.on( }, ) +ipcMain.on('open-directory', (_event, directory: string) => { + shell.openPath(directory) +}) ipcMain.on('open-external-link', (_event, linkUrl) => { shell.openExternal(linkUrl) }) diff --git a/frontend/apps/desktop/src/root.tsx b/frontend/apps/desktop/src/root.tsx index 4786df26d..843101ae7 100644 --- a/frontend/apps/desktop/src/root.tsx +++ b/frontend/apps/desktop/src/root.tsx @@ -231,6 +231,9 @@ function MainApp({ platform={appInfo.platform()} queryClient={queryClient} ipc={ipc} + openDirectory={async (directory: string) => { + ipc.send?.('open-directory', directory) + }} externalOpen={async (url: string) => { ipc.send?.('open-external-link', url) }} diff --git a/frontend/apps/desktop/src/save-markdown-file.tsx b/frontend/apps/desktop/src/save-markdown-file.tsx index d706e172c..047605e03 100644 --- a/frontend/apps/desktop/src/save-markdown-file.tsx +++ b/frontend/apps/desktop/src/save-markdown-file.tsx @@ -45,7 +45,7 @@ export async function saveMarkdownFile( let updatedMarkdownContent = markdownContent let success: {success: boolean; message: string} = { success: true, - message: `Successfully exported ${title} to: ${filePath}.`, + message: filePath, } const uploadMediaFile = ({ diff --git a/frontend/packages/app/app-context.tsx b/frontend/packages/app/app-context.tsx index 8c69c8ddb..db229102f 100644 --- a/frontend/packages/app/app-context.tsx +++ b/frontend/packages/app/app-context.tsx @@ -17,6 +17,7 @@ export type AppContext = { queryClient: AppQueryClient ipc: AppIPC externalOpen: (url: string) => Promise + openDirectory: (directory: string) => Promise windowUtils: WindowUtils saveCidAsFile: (cid: string, name: string) => Promise exportDocument: ( @@ -44,6 +45,7 @@ export function AppContextProvider({ queryClient, ipc, externalOpen, + openDirectory, windowUtils, saveCidAsFile, exportDocument, @@ -56,6 +58,7 @@ export function AppContextProvider({ queryClient: AppQueryClient ipc: AppIPC externalOpen: (url: string) => Promise + openDirectory: (directory: string) => Promise windowUtils: WindowUtils saveCidAsFile: (cid: string, name: string) => Promise exportDocument: ( @@ -82,6 +85,7 @@ export function AppContextProvider({ queryClient, ipc, externalOpen, + openDirectory, windowUtils, saveCidAsFile, exportDocument, diff --git a/frontend/packages/app/components/export-doc-button.tsx b/frontend/packages/app/components/export-doc-button.tsx index bcfca3f26..0af53c404 100644 --- a/frontend/packages/app/components/export-doc-button.tsx +++ b/frontend/packages/app/components/export-doc-button.tsx @@ -1,6 +1,7 @@ import {HMBlockNode, toHMBlock} from '@mintter/shared' import {Button, Tooltip, toast} from '@mintter/ui' import {Download} from '@tamagui/lucide-icons' +import {SizableText, YStack} from 'tamagui' import {useAppContext} from '../app-context' import {usePublication} from '../models/documents' import {convertBlocksToMarkdown} from '../utils/blocks-to-markdown' @@ -14,7 +15,7 @@ export const ExportDocButton = ({ }) => { const pub = usePublication({id: docId, version: version}) const title = pub.data?.document?.title || 'document' - const {exportDocument} = useAppContext() + const {exportDocument, openDirectory} = useAppContext() return ( <> @@ -34,7 +35,30 @@ export const ExportDocButton = ({ const markdownWithTitle = `# ${title}\n\n${markdownContent}` exportDocument(title, markdownWithTitle, mediaFiles) .then((res) => { - toast.success(res) + const success = ( + <> + + + Successfully exported document "{title}" to:{' '} + {`${res}`}. + + { + openDirectory(res) + }} + > + Show directory + + + + ) + toast.success('', {customContent: success}) }) .catch((err) => { toast.error(err) diff --git a/frontend/packages/app/pages/export-page.tsx b/frontend/packages/app/pages/export-page.tsx index ba2acb011..73bae0128 100644 --- a/frontend/packages/app/pages/export-page.tsx +++ b/frontend/packages/app/pages/export-page.tsx @@ -27,7 +27,7 @@ export default function ExportPage() { const [documents, setDocuments] = useState([]) const [allSelected, setAllSelected] = useState(false) const [loading, setLoading] = useState(false) - const {exportDocuments} = useAppContext() + const {exportDocuments, openDirectory} = useAppContext() const route = useNavRoute() if (route.key !== 'export') throw new Error('invalid route') @@ -173,7 +173,26 @@ export default function ExportPage() { exportDocuments(documentsToExport) .then((res) => { - toast.success(res) + const success = ( + <> + + + Successfully exported documents to: {`${res}`}. + + { + openDirectory(res) + }} + > + Show directory + + + + ) + toast.success('', {customContent: success}) setLoading(false) }) .catch((err) => { diff --git a/frontend/packages/app/utils/blocks-to-markdown.ts b/frontend/packages/app/utils/blocks-to-markdown.ts index d1b1cf49f..b46f63eb0 100644 --- a/frontend/packages/app/utils/blocks-to-markdown.ts +++ b/frontend/packages/app/utils/blocks-to-markdown.ts @@ -15,7 +15,7 @@ function applyStyles(text, styles) { function convertContentItemToHtml( contentItem, - docMap: Map, + docMap?: Map, ) { let text = contentItem.text || '' const {styles = {}} = contentItem @@ -27,10 +27,9 @@ function convertContentItemToHtml( contentItem.content[0].text, contentItem.content[0].styles || {}, ) - const docPath = docMap.get(contentItem.href) - return `${linkText}` + let docPath = contentItem.href + if (docMap) docPath = docMap.get(contentItem.href) + return `${linkText}` } else { return text } @@ -39,7 +38,7 @@ function convertContentItemToHtml( function convertBlockToHtml( block, isListItem = false, - docMap: Map, + docMap?: Map, ) { let childrenHtml = '' if (block.children) { @@ -106,7 +105,7 @@ function convertBlockToHtml( function convertBlocksToHtml( blocks: HMBlock[], - docMap: Map, + docMap?: Map, ) { const htmlContent: string = blocks .map((block) => convertBlockToHtml(block, undefined, docMap)) @@ -156,7 +155,7 @@ async function extractMediaFiles(blocks: HMBlock[]) { export async function convertBlocksToMarkdown( blocks: HMBlock[], - docMap: Map, + docMap?: Map, ) { const mediaFiles = await extractMediaFiles(blocks) const markdownFile = await unified()