refactor: migrate old scratchpad into notes

This commit is contained in:
Fabio Di Stasio 2023-12-25 11:19:23 +01:00
parent 9a732ea197
commit 532002ca01
2 changed files with 21 additions and 4 deletions

View File

@ -21,7 +21,7 @@
class="titlebar-element"
@click="openDevTools"
>
<BaseIcon icon-name="mdiCodeTags" :size="24" />
<BaseIcon icon-name="mdiBugPlayOutline" :size="24" />
</div>
<div
v-if="isDevelopment"

View File

@ -1,6 +1,5 @@
import * as Store from 'electron-store';
import { defineStore } from 'pinia';
const persistentStore = new Store({ name: 'notes' });
export type TagCode = 'all' | 'note' | 'todo' | 'query'
@ -14,11 +13,29 @@ export interface ConnectionNote {
date: Date;
}
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);
}
export const useScratchpadStore = defineStore('scratchpad', {
state: () => ({
selectedTag: 'all',
/** Global notes */
notes: persistentStore.get('notes', '# HOW TO SUPPORT ANTARES\n\n- [ ] Leave a star to Antares [GitHub repo](https://github.com/antares-sql/antares)\n- [ ] Send feedbacks and advices\n- [ ] Report for bugs\n- [ ] If you enjoy, share Antares with friends\n\n# ABOUT SCRATCHPAD\n\nThis is a scratchpad where you can save your **personal notes**. It supports `markdown` format, but you are free to use plain text.\nThis content is just a placeholder, feel free to clear it to make space for your notes.\n') as string,
/** Connection specific notes */
connectionNotes: persistentStore.get('connectionNotes', []) as ConnectionNote[]
}),