refactor: code organization

This commit is contained in:
2024-10-23 15:23:33 +02:00
parent 018357c5ed
commit 5a32c96a88
29 changed files with 1134 additions and 615 deletions
+12 -14
View File
@@ -1,13 +1,11 @@
import { defineComponent } from 'vue';
import { useStore } from '../store';
import { ChangeProp, SceneryRowItem } from '../types/types';
import { useSceneriesStore } from '../stores/sceneries.store';
import { ChangeProp, SceneryRowItem } from '../types/sceneries.types';
export default defineComponent({
setup() {
return {
store: useStore(),
};
},
data: () => ({
sceneriesStore: useSceneriesStore(),
}),
methods: {
addChange(sceneryData: SceneryRowItem, propName: string, oldValue: any, newValue: any) {
@@ -17,22 +15,22 @@ export default defineComponent({
const sceneryId = sceneryData.id;
let changeItem = this.store.changeList.find((item) => item.id == sceneryId);
let changeItem = this.sceneriesStore.changeList.find((item) => item.id == sceneryId);
if (!changeItem) {
changeItem = { id: sceneryId, name: sceneryData.name };
this.store.changeList.push(changeItem);
this.sceneriesStore.changeList.push(changeItem);
}
changeItem[changePropName] = newValue;
const sceneryBackup = this.store.backupList.find((scenery) => scenery.id == sceneryId);
const sceneryBackup = this.sceneriesStore.backupList.find((scenery) => scenery.id == sceneryId);
if (!sceneryBackup) return;
if (sceneryBackup && sceneryBackup[changePropName] == changeItem[changePropName]) delete changeItem[changePropName];
if (Object.keys(changeItem).length == 2 && changeItem.id)
this.store.changeList = this.store.changeList.filter((item) => changeItem?.id != item.id);
this.sceneriesStore.changeList = this.sceneriesStore.changeList.filter((item) => changeItem?.id != item.id);
},
addRemovalChange(sceneryData: SceneryRowItem) {
@@ -40,13 +38,13 @@ export default defineComponent({
// Sceneria niewpisana do bazy danych (id stworzone przez stronę)
if (sceneryId.toString().startsWith('#')) {
this.store.changeList = this.store.changeList.filter((item) => item.id != sceneryId);
this.sceneriesStore.changeList = this.sceneriesStore.changeList.filter((item) => item.id != sceneryId);
return;
}
let changeItem = this.store.changeList.find((item) => item.id == sceneryId);
let changeItem = this.sceneriesStore.changeList.find((item) => item.id == sceneryId);
if (!changeItem) this.store.changeList.push({ id: sceneryId, name: sceneryData.name, toRemove: true });
if (!changeItem) this.sceneriesStore.changeList.push({ id: sceneryId, name: sceneryData.name, toRemove: true });
else changeItem['toRemove'] = true;
},
},
+1 -1
View File
@@ -1,5 +1,5 @@
import { defineComponent } from 'vue';
import { SceneryRowItem } from '../types/types';
import { SceneryRowItem } from '../types/sceneries.types';
export default defineComponent({
methods: {
+4 -5
View File
@@ -1,16 +1,16 @@
import { computed, watch } from 'vue';
import { useStore } from '../store';
import { useSceneriesStore } from '../stores/sceneries.store';
export default () => {
const store = useStore();
const sceneriesStore = useSceneriesStore();
const setupStorage = () => {
// On mounted
store.maxVisibleResults = Number(window.localStorage.getItem('maxVisibleResults')) || 30;
sceneriesStore.maxVisibleResults = Number(window.localStorage.getItem('maxVisibleResults')) || 30;
// Max vis. results
watch(
computed(() => store.maxVisibleResults),
computed(() => sceneriesStore.maxVisibleResults),
(v) => {
window.localStorage.setItem('maxVisibleResults', v.toString());
}
@@ -21,4 +21,3 @@ export default () => {
setupStorage,
};
};