fix: removed unpublish button
This commit is contained in:
@@ -948,57 +948,6 @@ export class PostEngine extends EventEmitter {
|
||||
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.
|
||||
* Call this after changing the search language or after migration.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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 () => {
|
||||
// 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<PostEditorProps> = ({ 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<PostEditorProps> = ({ post }) => {
|
||||
{post.status}
|
||||
</span>
|
||||
{isSaving && <span className="auto-save-indicator">Saving...</span>}
|
||||
{post.status === 'draft' ? (
|
||||
{post.status === 'draft' && (
|
||||
<button
|
||||
onClick={handlePublish}
|
||||
className="success"
|
||||
@@ -467,14 +447,6 @@ const PostEditor: React.FC<PostEditorProps> = ({ post }) => {
|
||||
>
|
||||
Publish
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleUnpublish}
|
||||
className="secondary"
|
||||
title="Return to draft status"
|
||||
>
|
||||
Unpublish
|
||||
</button>
|
||||
)}
|
||||
{post.status === 'draft' && (
|
||||
<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>;
|
||||
getByStatus: (status: string) => Promise<PostData[]>;
|
||||
publish: (id: string) => Promise<PostData | null>;
|
||||
unpublish: (id: string) => Promise<PostData | null>;
|
||||
discard: (id: string) => Promise<PostData | null>;
|
||||
hasPublishedVersion: (id: string) => Promise<boolean>;
|
||||
rebuildFromFiles: () => Promise<void>;
|
||||
|
||||
@@ -44,7 +44,6 @@ Object.defineProperty(globalThis, 'window', {
|
||||
getAll: vi.fn(),
|
||||
getByStatus: vi.fn(),
|
||||
publish: vi.fn(),
|
||||
unpublish: vi.fn(),
|
||||
rebuildFromFiles: vi.fn(),
|
||||
search: vi.fn(),
|
||||
filter: vi.fn(),
|
||||
|
||||
Reference in New Issue
Block a user