2022-07-03 10:25:12 +00:00
|
|
|
import { defineStore, storeToRefs } from 'pinia'
|
2022-07-03 15:50:41 +00:00
|
|
|
import { getCookie, setCookie } from 'typescript-cookie'
|
|
|
|
|
import { useCookies } from 'vue3-cookies'
|
2022-07-03 10:25:12 +00:00
|
|
|
import { BasicColumns, ColumnInfo, ColumnName, Columns, DetailsColumns, MoveColumns } from '../lib/columns'
|
2022-07-03 15:50:41 +00:00
|
|
|
import { Reviver, StoreColSet, StoreStr, StoreStrSet } from '../lib/storage'
|
2022-07-03 10:25:12 +00:00
|
|
|
import { ColumnSet } from '../lib/table'
|
|
|
|
|
import { TricksterInventory } from '../lib/trickster'
|
2022-07-03 15:50:41 +00:00
|
|
|
import { nameCookie} from '../session_storage'
|
2022-07-03 10:25:12 +00:00
|
|
|
|
|
|
|
|
const _defaultColumn:(ColumnInfo| ColumnName)[] = [
|
|
|
|
|
...BasicColumns,
|
|
|
|
|
...MoveColumns,
|
|
|
|
|
...DetailsColumns,
|
|
|
|
|
]
|
|
|
|
|
export const useStore = defineStore('state', {
|
|
|
|
|
state: ()=> {
|
2022-07-03 15:50:41 +00:00
|
|
|
const last_table = getCookie(nameCookie("last_table"))
|
|
|
|
|
const last_screen = getCookie(nameCookie("last_screen"))
|
|
|
|
|
const last_columns = getCookie(nameCookie("last_columns"))?.split(",")
|
|
|
|
|
const last_tags = getCookie(nameCookie("last_tags"))?.split(",")
|
2022-07-03 10:25:12 +00:00
|
|
|
return {
|
|
|
|
|
invs: new Map() as Map<string,TricksterInventory>,
|
2022-07-03 15:50:41 +00:00
|
|
|
accounts: new Set() as Set<string>,
|
|
|
|
|
activeTable: last_table ? last_table: "none",
|
|
|
|
|
screen: last_screen ? last_screen : "default",
|
|
|
|
|
columns: last_columns ? new ColumnSet([..._defaultColumn,...last_columns]) : new ColumnSet(_defaultColumn),
|
|
|
|
|
tags: last_tags ? new ColumnSet(last_tags) : new ColumnSet(),
|
|
|
|
|
dirty: 0,
|
2022-07-03 10:25:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-07-03 15:50:41 +00:00
|
|
|
|
|
|
|
|
export const StoreReviver = {
|
|
|
|
|
accounts: StoreStrSet,
|
|
|
|
|
activeTable: StoreStr,
|
|
|
|
|
screen: StoreStr,
|
|
|
|
|
columns: StoreColSet,
|
|
|
|
|
tags: StoreColSet,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface StoreProps {
|
|
|
|
|
invs: Map<string,TricksterInventory>
|
|
|
|
|
accounts: Set<string>
|
|
|
|
|
activeTable: string
|
|
|
|
|
screen: string
|
|
|
|
|
columns: ColumnSet
|
|
|
|
|
tags: ColumnSet
|
|
|
|
|
dirty: number
|
|
|
|
|
}
|
|
|
|
|
export const loadStore = ()=> {
|
|
|
|
|
let store = useStoreRef()
|
|
|
|
|
for(const [k, v] of Object.entries(StoreReviver)){
|
|
|
|
|
const coke = getCookie(nameCookie("last_"+k))
|
|
|
|
|
if(coke){
|
|
|
|
|
if((store[k as keyof StoreProps]) != undefined){
|
|
|
|
|
store[k as keyof StoreProps].value = v.Revive(coke)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const saveStore = ()=> {
|
|
|
|
|
let store = useStoreRef()
|
|
|
|
|
for(const [k, v] of Object.entries(StoreReviver)){
|
|
|
|
|
let coke;
|
|
|
|
|
|
|
|
|
|
if((store[k as keyof StoreProps]) != undefined){
|
|
|
|
|
coke = v.Murder(store[k as keyof StoreProps].value as any)
|
|
|
|
|
}
|
|
|
|
|
if(coke){
|
|
|
|
|
setCookie(nameCookie("last_"+k),coke)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useStoreRef = ()=>{
|
|
|
|
|
const refs = storeToRefs(useStore())
|
|
|
|
|
return refs
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type RefStore = ReturnType<typeof useStoreRef>;
|
2022-07-03 10:25:12 +00:00
|
|
|
|
|
|
|
|
|