Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "joplin-plugin-note-categorization",
"version": "0.1.8",
"version": "0.1.9",
"scripts": {
"dist": "webpack --env joplin-plugin-config=buildMain && webpack --env joplin-plugin-config=buildExtraScripts && npm run copyAssets && webpack --env joplin-plugin-config=createArchive",
"prepare": "npm run dist",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 1,
"id": "com.harsh16gupta.notecategorization",
"app_min_version": "3.5",
"version": "0.1.8",
"version": "0.1.9",
"name": "Note Categorization Plugin",
"description": "AI-based note categorisation: clusters notes semantically, suggests tags and notebook structures, and detects stale notes.",
"author": "Harsh Gupta",
Expand Down
32 changes: 32 additions & 0 deletions src/panel/setupPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export async function setupPanel(operationState: OperationState): Promise<string
await joplin.views.panels.show(panel, false);

let panelState: PanelMessage | { type: 'idle' } = { type: 'idle' };
operationState.setPanelState = (state: PanelMessage) => {
panelState = state;
};

let lastResultsState: {
strategies: BenchmarkResult[];
notes: PanelNote[];
Expand Down Expand Up @@ -62,13 +66,24 @@ export async function setupPanel(operationState: OperationState): Promise<string
return panelState;
}
if (lastResultsState) {
const isApplyOrUndo =
panelState.type === 'apply_status' ||
panelState.type === 'apply_progress' ||
panelState.type === 'apply_complete' ||
panelState.type === 'apply_error' ||
panelState.type === 'undo_status' ||
panelState.type === 'undo_progress' ||
panelState.type === 'undo_complete' ||
panelState.type === 'undo_error';

return {
type: 'results',
strategies: lastResultsState.strategies,
notes: lastResultsState.notes,
selectedStrategyIndex: lastResultsState.selectedStrategyIndex,
isNativeAiUsed: lastResultsState.isNativeAiUsed,
isAiNamingUsed: lastResultsState.isAiNamingUsed,
panelState: isApplyOrUndo ? panelState : undefined,
};
}
return panelState;
Expand All @@ -78,7 +93,24 @@ export async function setupPanel(operationState: OperationState): Promise<string
strategies: msg.strategies,
notes: msg.notes,
selectedStrategyIndex: msg.selectedStrategyIndex,
isNativeAiUsed: lastResultsState?.isNativeAiUsed,
isAiNamingUsed: lastResultsState?.isAiNamingUsed,
};
if (
panelState.type === 'apply_complete' ||
panelState.type === 'undo_complete' ||
panelState.type === 'apply_error' ||
panelState.type === 'undo_error'
) {
panelState = {
type: 'results',
strategies: msg.strategies,
notes: msg.notes,
selectedStrategyIndex: msg.selectedStrategyIndex,
isNativeAiUsed: lastResultsState?.isNativeAiUsed,
isAiNamingUsed: lastResultsState?.isAiNamingUsed,
};
}
return { success: true };

case 'openNote':
Expand Down
15 changes: 14 additions & 1 deletion src/settings/registerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@ import { SettingItemType as SettingType } from 'api/types';
import { log } from '../utils/logger';
import { undoCategorizationChanges } from '../commands/applyChanges';

import { PanelMessage } from '../types/panel';

export interface OperationState {
inProgress: boolean;
setPanelState?: (state: PanelMessage) => void;
}

const OP_IN_PROGRESS_MSG = 'An operation is already in progress. Please wait for it to complete.';

/**
* Executes undo operation triggered natively (from Tools menu or Joplin Settings).
* Updates backend panelState via operationState.setPanelState so that when the webview
* remounts, getInitialState surfaces the undo status/completion banner.
* Direct modal user feedback during native options execution is provided via showMessageBox.
*/
export async function runNativeUndo(source: string, operationState: OperationState): Promise<void> {
if (operationState.inProgress) {
await joplin.views.dialogs.showMessageBox(OP_IN_PROGRESS_MSG);
return;
}
operationState.inProgress = true;
operationState.setPanelState?.({ type: 'undo_status', text: 'Initializing undo...' });
try {
let lastMessage = '';
await undoCategorizationChanges((state) => {
operationState.setPanelState?.(state);
log(`Native ${source} Undo: ${'text' in state ? state.text : state.type}`);
if (state.type === 'undo_complete') {
lastMessage = 'Reverted categorization changes successfully!';
Expand All @@ -29,7 +40,9 @@ export async function runNativeUndo(source: string, operationState: OperationSta
await joplin.views.dialogs.showMessageBox(lastMessage);
}
} catch (err) {
await joplin.views.dialogs.showMessageBox(`Undo failed: ${err instanceof Error ? err.message : String(err)}`);
const errMsg = err instanceof Error ? err.message : String(err);
operationState.setPanelState?.({ type: 'undo_error', message: errMsg });
await joplin.views.dialogs.showMessageBox(`Undo failed: ${errMsg}`);
} finally {
operationState.inProgress = false;
}
Expand Down
20 changes: 12 additions & 8 deletions src/types/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export interface ApplyMessage {
clusterTags: { [clusterId: number]: string[] };
}

export type ApplyUndoPanelMessage =
| { type: 'apply_status'; text: string }
| { type: 'apply_progress'; current: number; total: number }
| { type: 'apply_complete' }
| { type: 'apply_error'; message: string }
| { type: 'undo_status'; text: string }
| { type: 'undo_progress'; current: number; total: number }
| { type: 'undo_complete' }
| { type: 'undo_error'; message: string };

// Plugin → Webview
export type PanelMessage =
| { type: 'status'; text: string; isNativeAiUsed?: boolean }
Expand All @@ -39,17 +49,11 @@ export type PanelMessage =
selectedStrategyIndex?: number;
isNativeAiUsed?: boolean;
isAiNamingUsed?: boolean;
panelState?: ApplyUndoPanelMessage;
/* eslint-disable-next-line no-mixed-spaces-and-tabs */
}
| { type: 'error'; message: string }
| { type: 'apply_status'; text: string }
| { type: 'apply_progress'; current: number; total: number }
| { type: 'apply_complete' }
| { type: 'apply_error'; message: string }
| { type: 'undo_status'; text: string }
| { type: 'undo_progress'; current: number; total: number }
| { type: 'undo_complete' }
| { type: 'undo_error'; message: string };
| ApplyUndoPanelMessage;

// Webview → Plugin
export type WebviewMessage =
Expand Down
Loading
Loading