Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maoserr committed Jun 29, 2024
1 parent 0890efa commit b48dba9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/pages/sidebar/SideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<TabPanel header="Overview">
<ChapToolbar @add="add_chap" @parse="parse"
@epub="gen_epub" @delete="delete_chap"
@cache="cache" @load="load"
@export_csv="export_csv" @import_csv="import_csv"/>
<DataTable :value="chaps"
ref="dt"
Expand Down Expand Up @@ -135,6 +136,7 @@ import LinksParse from "./parserconfig/LinksParse.vue";
import NextParse from "./parserconfig/AddPageParse.vue";
import TextParse from "./parserconfig/TextParse.vue";
import InputText from "primevue/inputtext";
import OptionsManager from "../../services/common/OptionsMan";
let parse_man: ParserManager
Expand Down Expand Up @@ -220,6 +222,15 @@ function delete_chap() {
selected_chaps.value = [];
}
async function cache(){
await OptionsManager.Instance.cache_state(chaps.value, meta.value)
write_info("Cached chapters & meta data")
}
function load(){
}
onMounted(async () => {
init_sidebarwin()
Expand Down
12 changes: 11 additions & 1 deletion src/pages/sidebar/overview/ChapToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const emits = defineEmits<{
parse: [],
epub: [],
delete: [],
cache: [],
load: [],
export_csv: [],
import_csv: [file:File]
}>()
Expand Down Expand Up @@ -105,10 +107,18 @@ const sel_file = (event: any) =>{
<Button v-tooltip:a.bottom="'Delete selected chapters'"
:disabled="chap_op_disable"
@click="$emit('delete')"
icon="pi pi-trash" severity="warning"
icon="pi pi-trash" severity="warning" class="mr-2"
size="small"/>
</template>
<template #end>
<Button v-tooltip:a.bottom="'Cache current data'"
@click="$emit('cache')"
icon="pi pi-save" class="mr-2"
size="small"/>
<Button v-tooltip:a.bottom="'Load cache'"
@click="$emit('load')"
icon="pi pi-folder-open" class="mr-2"
size="small"/>
<Button type="button" v-tooltip:a.bottom="'More'" icon="pi pi-ellipsis-v" @click="toggle"
severity="secondary" size="small"
aria-haspopup="true" aria-controls="overlay_menu"/>
Expand Down
22 changes: 20 additions & 2 deletions src/services/common/OptionsMan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import browser from "webextension-polyfill";
import {Chapter, NovelMetaData} from "../novel/novel_data";

interface Options {
load_saved: boolean
Expand All @@ -13,13 +14,13 @@ export default class OptionsManager {
}

static get Instance() {
if (!this._instance){
if (!this._instance) {
this._instance = new this()
}
return this._instance;
}

async get_option<T>(name:keyof Options):Promise<T>{
async get_option<T>(name: keyof Options): Promise<T> {
if (this.options === undefined) {
this.options = (await browser.storage.sync.get("options")) as Options
}
Expand Down Expand Up @@ -51,4 +52,21 @@ export default class OptionsManager {
return {"main": await this.get_initial()};
}
}

/**
* Caches current parsed state
* @param chaps Chapters
* @param meta Metadata
*/
async cache_state(chaps: Chapter[], meta: NovelMetaData) {
await browser.storage.local.set(
{
chapter: JSON.stringify(chaps),
meta: JSON.stringify(meta)
})
}

async load_state():Promise<[Chapter[],NovelMetaData]>{
const chaps= JSON.parse(browser.storage.local.get("chapter"))
}
}

0 comments on commit b48dba9

Please sign in to comment.