Skip to content

Commit

Permalink
fix: pinia state
Browse files Browse the repository at this point in the history
  • Loading branch information
mark9804 committed Apr 12, 2024
1 parent a6b4d05 commit 7364676
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useGlobalConfig = defineStore({
selectLine: 0,
language: "TextJp" as Language,
targetLang: "TextCn" as Language,
tmpMachineTranslate: new Map<string, string>(),
tmpMachineTranslate: {} as { [key: string]: string },
switchLanguage: 0b11,
showAllLanguage: true,
selectTag: "[wa:]",
Expand All @@ -25,12 +25,12 @@ export const useGlobalConfig = defineStore({
/* eslint-disable indent */
getTmpMachineTranslate:
state =>
(string = "") => {
const mapType = Object.prototype.toString.call(
(query = "") => {
const objectType = Object.prototype.toString.call(
state.tmpMachineTranslate
);
return mapType === "[object Map]"
? state.tmpMachineTranslate.get(string) || ""
return objectType === "[object Object]"
? state.tmpMachineTranslate?.[query] || ""
: state.tmpMachineTranslate;
},
/* eslint-enable indent */
Expand Down Expand Up @@ -65,10 +65,10 @@ export const useGlobalConfig = defineStore({
},
setTmpMachineTranslate(origin: string, text: string) {
const mapType = Object.prototype.toString.call(this.tmpMachineTranslate);
if (mapType !== "[object Map]") {
this.tmpMachineTranslate = new Map<string, string>();
if (mapType !== "[object Object]") {
this.tmpMachineTranslate = {};
}
this.tmpMachineTranslate.set(origin, text);
this.tmpMachineTranslate[origin] = text;
},
setLanguage(language: Language) {
this.language = language;
Expand All @@ -95,6 +95,9 @@ export const useGlobalConfig = defineStore({
this.initialize_config();
this.initialize_state();
},
resetTmpTranslation() {
this.tmpMachineTranslate = {};
},
setStudents(students: Student[]) {
this.students = students;
},
Expand Down

0 comments on commit 7364676

Please sign in to comment.