From 258e313f0ef0dc4dff11ba5dfe15157604e6f5d6 Mon Sep 17 00:00:00 2001 From: hugo Date: Wed, 11 Feb 2026 16:14:41 +0100 Subject: [PATCH] fix: removed unpublish button --- src/main/engine/PostEngine.ts | 51 ----------------------- src/main/ipc/handlers.ts | 5 --- src/main/preload.ts | 1 - src/renderer/components/Editor/Editor.tsx | 30 +------------ src/renderer/types/electron.d.ts | 1 - tests/setup.ts | 1 - 6 files changed, 1 insertion(+), 88 deletions(-) diff --git a/src/main/engine/PostEngine.ts b/src/main/engine/PostEngine.ts index 2dade04..4dc6a96 100644 --- a/src/main/engine/PostEngine.ts +++ b/src/main/engine/PostEngine.ts @@ -948,57 +948,6 @@ export class PostEngine extends EventEmitter { return !!(dbPost && dbPost.filePath && dbPost.filePath !== ''); } - async unpublishPost(id: string): Promise { - const db = getDatabase().getLocal(); - const client = getDatabase().getLocalClient(); - const existing = await this.getPost(id); - - if (!existing) { - return null; - } - - const dbPost = await db.select().from(posts).where(eq(posts.id, id)).get(); - if (!dbPost) { - return null; - } - - // Delete the published file (content moves to DB) - if (dbPost.filePath) { - try { - await fs.unlink(dbPost.filePath); - } catch { - // File might not exist - } - } - - const updated: PostData = { - ...existing, - status: 'draft', - updatedAt: new Date(), - }; - - const checksum = this.calculateChecksum(updated.content); - - // Store content in DB, clear filePath - await db.update(posts) - .set({ - content: updated.content, - status: 'draft', - filePath: '', - updatedAt: updated.updatedAt, - publishedAt: null, - syncStatus: 'pending', - checksum, - }) - .where(eq(posts.id, id)); - - // Update FTS index - await this.updateFTSIndex(updated); - - this.emit('postUpdated', updated); - return updated; - } - /** * Rebuild the FTS index for all posts in the current project. * Call this after changing the search language or after migration. diff --git a/src/main/ipc/handlers.ts b/src/main/ipc/handlers.ts index 93863ce..26b7e62 100644 --- a/src/main/ipc/handlers.ts +++ b/src/main/ipc/handlers.ts @@ -135,11 +135,6 @@ export function registerIpcHandlers(): void { return engine.publishPost(id); }); - ipcMain.handle('posts:unpublish', async (_, id: string) => { - const engine = getPostEngine(); - return engine.unpublishPost(id); - }); - ipcMain.handle('posts:discard', async (_, id: string) => { const engine = getPostEngine(); return engine.discardChanges(id); diff --git a/src/main/preload.ts b/src/main/preload.ts index c9d9f7a..38ba919 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -24,7 +24,6 @@ contextBridge.exposeInMainWorld('electronAPI', { getAll: (options?: { limit?: number; offset?: number }) => ipcRenderer.invoke('posts:getAll', options), getByStatus: (status: string) => ipcRenderer.invoke('posts:getByStatus', status), publish: (id: string) => ipcRenderer.invoke('posts:publish', id), - unpublish: (id: string) => ipcRenderer.invoke('posts:unpublish', id), discard: (id: string) => ipcRenderer.invoke('posts:discard', id), hasPublishedVersion: (id: string) => ipcRenderer.invoke('posts:hasPublishedVersion', id), rebuildFromFiles: () => ipcRenderer.invoke('posts:rebuildFromFiles'), diff --git a/src/renderer/components/Editor/Editor.tsx b/src/renderer/components/Editor/Editor.tsx index c980ad8..9ceba4a 100644 --- a/src/renderer/components/Editor/Editor.tsx +++ b/src/renderer/components/Editor/Editor.tsx @@ -331,24 +331,6 @@ const PostEditor: React.FC = ({ post }) => { } }; - const handleUnpublish = async () => { - try { - const updated = await window.electronAPI?.posts.unpublish(post.id); - if (updated) { - updatePost(post.id, updated as Partial); - showToast.success('Post unpublished'); - } - } catch (error) { - console.error('Failed to unpublish post:', error); - const err = error as Error; - showErrorModal({ - title: 'Unpublish Failed', - message: err.message || 'Failed to unpublish post', - stack: err.stack, - }); - } - }; - const handleDiscard = async () => { // If this post has a published version, revert to it // If never published, delete the post entirely @@ -436,12 +418,10 @@ const PostEditor: React.FC = ({ post }) => { useEffect(() => { const unsubscribeSave = window.electronAPI?.on('menu:save', handleSave); const unsubscribePublish = window.electronAPI?.on('menu:publishSelected', handlePublish); - const unsubscribeUnpublish = window.electronAPI?.on('menu:unpublishSelected', handleUnpublish); return () => { unsubscribeSave?.(); unsubscribePublish?.(); - unsubscribeUnpublish?.(); }; }, [handleSave]); @@ -459,7 +439,7 @@ const PostEditor: React.FC = ({ post }) => { {post.status} {isSaving && Saving...} - {post.status === 'draft' ? ( + {post.status === 'draft' && ( - ) : ( - )} {post.status === 'draft' && (