Skip to content

Commit

Permalink
feat: save historys to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrkafuu committed Mar 18, 2022
1 parent 325fa0b commit fde0cab
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/store/modules/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OverlayAPI, { ExtendData } from 'ffxiv-overlay-api';
import { makeAutoObservable } from 'mobx';
import { Store } from '..';
import { cloneDeep } from '../../utils/lodash';
import { getLS, setLS } from '../../utils/storage';

const cleanData: ExtendData = {
isActive: false,
Expand Down Expand Up @@ -47,6 +48,12 @@ class API {
constructor(rootStore: Store) {
this.rootStore = rootStore;

// load historys from storage
const historys = getLS('historys');
if (historys && Array.isArray(historys) && historys.length <= 5) {
this.historys = historys;
}

// add overlay callback
this.overlay.addListener('CombatData', (rawData) => {
const data = rawData.extendData;
Expand Down Expand Up @@ -93,6 +100,8 @@ class API {
if (lastData && !lastData.isActive && payload.isActive) {
this.historys.length >= 5 && this.historys.pop();
this.historys.unshift({ time: Date.now(), ...lastData });
// save to storage
setLS('historys', this.historys);
}
// record data for future use
lastData = cloneDeep(payload);
Expand Down

0 comments on commit fde0cab

Please sign in to comment.