fix: removed unpublish button
This commit is contained in:
@@ -948,57 +948,6 @@ export class PostEngine extends EventEmitter {
|
|||||||
return !!(dbPost && dbPost.filePath && dbPost.filePath !== '');
|
return !!(dbPost && dbPost.filePath && dbPost.filePath !== '');
|
||||||
}
|
}
|
||||||
|
|
||||||
async unpublishPost(id: string): Promise<PostData | null> {
|
|
||||||
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.
|
* Rebuild the FTS index for all posts in the current project.
|
||||||
* Call this after changing the search language or after migration.
|
* Call this after changing the search language or after migration.
|
||||||
|
|||||||
@@ -135,11 +135,6 @@ export function registerIpcHandlers(): void {
|
|||||||
return engine.publishPost(id);
|
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) => {
|
ipcMain.handle('posts:discard', async (_, id: string) => {
|
||||||
const engine = getPostEngine();
|
const engine = getPostEngine();
|
||||||
return engine.discardChanges(id);
|
return engine.discardChanges(id);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||||||
getAll: (options?: { limit?: number; offset?: number }) => ipcRenderer.invoke('posts:getAll', options),
|
getAll: (options?: { limit?: number; offset?: number }) => ipcRenderer.invoke('posts:getAll', options),
|
||||||
getByStatus: (status: string) => ipcRenderer.invoke('posts:getByStatus', status),
|
getByStatus: (status: string) => ipcRenderer.invoke('posts:getByStatus', status),
|
||||||
publish: (id: string) => ipcRenderer.invoke('posts:publish', id),
|
publish: (id: string) => ipcRenderer.invoke('posts:publish', id),
|
||||||
unpublish: (id: string) => ipcRenderer.invoke('posts:unpublish', id),
|
|
||||||
discard: (id: string) => ipcRenderer.invoke('posts:discard', id),
|
discard: (id: string) => ipcRenderer.invoke('posts:discard', id),
|
||||||
hasPublishedVersion: (id: string) => ipcRenderer.invoke('posts:hasPublishedVersion', id),
|
hasPublishedVersion: (id: string) => ipcRenderer.invoke('posts:hasPublishedVersion', id),
|
||||||
rebuildFromFiles: () => ipcRenderer.invoke('posts:rebuildFromFiles'),
|
rebuildFromFiles: () => ipcRenderer.invoke('posts:rebuildFromFiles'),
|
||||||
|
|||||||
@@ -331,24 +331,6 @@ const PostEditor: React.FC<PostEditorProps> = ({ post }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUnpublish = async () => {
|
|
||||||
try {
|
|
||||||
const updated = await window.electronAPI?.posts.unpublish(post.id);
|
|
||||||
if (updated) {
|
|
||||||
updatePost(post.id, updated as Partial<PostData>);
|
|
||||||
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 () => {
|
const handleDiscard = async () => {
|
||||||
// If this post has a published version, revert to it
|
// If this post has a published version, revert to it
|
||||||
// If never published, delete the post entirely
|
// If never published, delete the post entirely
|
||||||
@@ -436,12 +418,10 @@ const PostEditor: React.FC<PostEditorProps> = ({ post }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsubscribeSave = window.electronAPI?.on('menu:save', handleSave);
|
const unsubscribeSave = window.electronAPI?.on('menu:save', handleSave);
|
||||||
const unsubscribePublish = window.electronAPI?.on('menu:publishSelected', handlePublish);
|
const unsubscribePublish = window.electronAPI?.on('menu:publishSelected', handlePublish);
|
||||||
const unsubscribeUnpublish = window.electronAPI?.on('menu:unpublishSelected', handleUnpublish);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unsubscribeSave?.();
|
unsubscribeSave?.();
|
||||||
unsubscribePublish?.();
|
unsubscribePublish?.();
|
||||||
unsubscribeUnpublish?.();
|
|
||||||
};
|
};
|
||||||
}, [handleSave]);
|
}, [handleSave]);
|
||||||
|
|
||||||
@@ -459,7 +439,7 @@ const PostEditor: React.FC<PostEditorProps> = ({ post }) => {
|
|||||||
{post.status}
|
{post.status}
|
||||||
</span>
|
</span>
|
||||||
{isSaving && <span className="auto-save-indicator">Saving...</span>}
|
{isSaving && <span className="auto-save-indicator">Saving...</span>}
|
||||||
{post.status === 'draft' ? (
|
{post.status === 'draft' && (
|
||||||
<button
|
<button
|
||||||
onClick={handlePublish}
|
onClick={handlePublish}
|
||||||
className="success"
|
className="success"
|
||||||
@@ -467,14 +447,6 @@ const PostEditor: React.FC<PostEditorProps> = ({ post }) => {
|
|||||||
>
|
>
|
||||||
Publish
|
Publish
|
||||||
</button>
|
</button>
|
||||||
) : (
|
|
||||||
<button
|
|
||||||
onClick={handleUnpublish}
|
|
||||||
className="secondary"
|
|
||||||
title="Return to draft status"
|
|
||||||
>
|
|
||||||
Unpublish
|
|
||||||
</button>
|
|
||||||
)}
|
)}
|
||||||
{post.status === 'draft' && (
|
{post.status === 'draft' && (
|
||||||
<button
|
<button
|
||||||
|
|||||||
1
src/renderer/types/electron.d.ts
vendored
1
src/renderer/types/electron.d.ts
vendored
@@ -189,7 +189,6 @@ export interface ElectronAPI {
|
|||||||
getAll: (options?: { limit?: number; offset?: number }) => Promise<PaginatedPostsResult>;
|
getAll: (options?: { limit?: number; offset?: number }) => Promise<PaginatedPostsResult>;
|
||||||
getByStatus: (status: string) => Promise<PostData[]>;
|
getByStatus: (status: string) => Promise<PostData[]>;
|
||||||
publish: (id: string) => Promise<PostData | null>;
|
publish: (id: string) => Promise<PostData | null>;
|
||||||
unpublish: (id: string) => Promise<PostData | null>;
|
|
||||||
discard: (id: string) => Promise<PostData | null>;
|
discard: (id: string) => Promise<PostData | null>;
|
||||||
hasPublishedVersion: (id: string) => Promise<boolean>;
|
hasPublishedVersion: (id: string) => Promise<boolean>;
|
||||||
rebuildFromFiles: () => Promise<void>;
|
rebuildFromFiles: () => Promise<void>;
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ Object.defineProperty(globalThis, 'window', {
|
|||||||
getAll: vi.fn(),
|
getAll: vi.fn(),
|
||||||
getByStatus: vi.fn(),
|
getByStatus: vi.fn(),
|
||||||
publish: vi.fn(),
|
publish: vi.fn(),
|
||||||
unpublish: vi.fn(),
|
|
||||||
rebuildFromFiles: vi.fn(),
|
rebuildFromFiles: vi.fn(),
|
||||||
search: vi.fn(),
|
search: vi.fn(),
|
||||||
filter: vi.fn(),
|
filter: vi.fn(),
|
||||||
|
|||||||
Reference in New Issue
Block a user