2022-05-28 18:43:56 +02:00
|
|
|
import * as Store from 'electron-store';
|
2023-08-18 15:57:31 +02:00
|
|
|
import { defineStore } from 'pinia';
|
2021-04-03 12:17:40 +02:00
|
|
|
|
2023-12-13 18:29:45 +01:00
|
|
|
export type TagCode = 'all' | 'note' | 'todo' | 'query'
|
|
|
|
|
2023-12-01 14:18:40 +01:00
|
|
|
export interface ConnectionNote {
|
|
|
|
uid: string;
|
2023-12-13 18:29:45 +01:00
|
|
|
cUid: string | null;
|
2023-12-06 08:44:07 +01:00
|
|
|
title?: string;
|
2023-12-21 10:16:46 +01:00
|
|
|
isArchived: boolean;
|
2023-12-13 18:29:45 +01:00
|
|
|
type: TagCode;
|
2023-12-01 14:18:40 +01:00
|
|
|
note: string;
|
|
|
|
date: Date;
|
|
|
|
}
|
|
|
|
|
2023-12-25 11:19:23 +01:00
|
|
|
const persistentStore = new Store({ name: 'notes' });
|
|
|
|
|
|
|
|
// Migrate old scratchpad on new notes TODO: remove in future releases
|
|
|
|
const oldNotes = persistentStore.get('notes') as string;
|
|
|
|
if (oldNotes) {
|
|
|
|
const newNotes = persistentStore.get('connectionNotes', []) as ConnectionNote[];
|
|
|
|
newNotes.unshift({
|
|
|
|
uid: 'N:LEGACY',
|
|
|
|
cUid: null,
|
|
|
|
isArchived: false,
|
|
|
|
type: 'note',
|
|
|
|
note: oldNotes,
|
|
|
|
date: new Date()
|
|
|
|
});
|
|
|
|
|
|
|
|
persistentStore.delete('notes');
|
|
|
|
|
|
|
|
persistentStore.set('connectionNotes', newNotes);
|
|
|
|
}
|
|
|
|
|
2022-04-30 00:47:37 +02:00
|
|
|
export const useScratchpadStore = defineStore('scratchpad', {
|
|
|
|
state: () => ({
|
2023-12-22 18:48:16 +01:00
|
|
|
selectedTag: 'all',
|
2023-12-01 14:18:40 +01:00
|
|
|
/** Connection specific notes */
|
2023-12-13 18:29:45 +01:00
|
|
|
connectionNotes: persistentStore.get('connectionNotes', []) as ConnectionNote[]
|
2022-04-30 00:47:37 +02:00
|
|
|
}),
|
2021-04-03 12:17:40 +02:00
|
|
|
actions: {
|
2023-12-06 08:44:07 +01:00
|
|
|
changeNotes (notes: ConnectionNote[]) {
|
|
|
|
this.connectionNotes = notes;
|
|
|
|
persistentStore.set('connectionNotes', this.connectionNotes);
|
2023-12-21 10:16:46 +01:00
|
|
|
},
|
|
|
|
addNote (note: ConnectionNote) {
|
|
|
|
this.connectionNotes = [
|
|
|
|
note,
|
|
|
|
...this.connectionNotes
|
|
|
|
];
|
|
|
|
persistentStore.set('connectionNotes', this.connectionNotes);
|
2023-12-21 18:10:51 +01:00
|
|
|
},
|
|
|
|
editNote (note: ConnectionNote) {
|
|
|
|
this.connectionNotes = (this.connectionNotes as ConnectionNote[]).map(n => {
|
|
|
|
if (n.uid === note.uid)
|
|
|
|
n = note;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
});
|
|
|
|
persistentStore.set('connectionNotes', this.connectionNotes);
|
2021-04-03 12:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-30 00:47:37 +02:00
|
|
|
});
|