fix: post creation working again, also slugs
This commit is contained in:
@@ -232,7 +232,7 @@ export class PostEngine extends EventEmitter {
|
||||
const post: PostData = {
|
||||
id,
|
||||
projectId: data.projectId || this.currentProjectId,
|
||||
title: data.title || 'Untitled',
|
||||
title: data.title ?? '',
|
||||
slug,
|
||||
excerpt: data.excerpt,
|
||||
content: data.content || '',
|
||||
@@ -303,11 +303,18 @@ export class PostEngine extends EventEmitter {
|
||||
newStatus = 'draft';
|
||||
}
|
||||
|
||||
// Auto-update slug when title changes, but only if post was never published
|
||||
let newSlug = data.slug ?? existing.slug;
|
||||
if (data.title !== undefined && data.title !== existing.title && !existing.publishedAt) {
|
||||
newSlug = await this.generateUniqueSlug(data.title || 'untitled', id);
|
||||
}
|
||||
|
||||
const updated: PostData = {
|
||||
...existing,
|
||||
...data,
|
||||
id, // Ensure ID doesn't change
|
||||
projectId: existing.projectId, // Ensure projectId doesn't change
|
||||
slug: newSlug,
|
||||
status: newStatus as 'draft' | 'published' | 'archived',
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
@@ -44,8 +44,14 @@ function createWindow(): void {
|
||||
}
|
||||
|
||||
// Forward events to renderer
|
||||
ipcMain.on('forward-to-renderer', (_event, eventName: string, ...args: unknown[]) => {
|
||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
// Note: ipcMain.emit() (used by forwardEvent in handlers) is a raw EventEmitter emit,
|
||||
// so the first arg is NOT an IpcMainEvent — it's the event name string directly.
|
||||
ipcMain.on('forward-to-renderer', (eventNameOrEvent: any, ...args: unknown[]) => {
|
||||
// When called via ipcMain.emit(), first arg is the channel string directly
|
||||
const eventName: string = typeof eventNameOrEvent === 'string'
|
||||
? eventNameOrEvent
|
||||
: args.shift() as string;
|
||||
if (mainWindow && !mainWindow.isDestroyed() && typeof eventName === 'string') {
|
||||
mainWindow.webContents.send(eventName, ...args);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user