mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-04 05:58:13 +00:00
refactor: code organization
This commit is contained in:
+12
-14
@@ -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,5 +1,5 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { SceneryRowItem } from '../types/types';
|
||||
import { SceneryRowItem } from '../types/sceneries.types';
|
||||
|
||||
export default defineComponent({
|
||||
methods: {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user