feature: local storage

This commit is contained in:
2023-01-31 17:33:56 +01:00
parent 2cb8b1dc15
commit 34759735d1
4 changed files with 39 additions and 3 deletions
+4
View File
@@ -13,6 +13,7 @@ import { RouterView } from 'vue-router';
import { IUser, AuthState } from './types/types';
import useRouteGuard from './mixins/useRouteGuard';
import { useStore } from './store';
import useLocalStorage from './mixins/useLocalStorage';
export default defineComponent({
mixins: [dataMixin],
@@ -20,7 +21,10 @@ export default defineComponent({
setup() {
const { routeAuthGuard } = useRouteGuard();
const { setupStorage } = useLocalStorage();
routeAuthGuard();
setupStorage();
return {
store: useStore(),
+6
View File
@@ -53,6 +53,12 @@
<button style="margin-left: 0.5em" @click="clearInput">Wyczyść</button>
</div>
<div class="pane">
Pokazuj maks.
<input type="number" min="1" v-model="store.maxVisibleResults" style="width: 50px; margin: 0 0.5em;" />
wyników
</div>
<div class="pane">
<button @click="changelogVisible = !changelogVisible">
{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog
+24
View File
@@ -0,0 +1,24 @@
import { computed, watch } from 'vue';
import { useStore } from '../store';
export default () => {
const store = useStore();
const setupStorage = () => {
// On mounted
store.maxVisibleResults = Number(window.localStorage.getItem('maxVisibleResults')) || 30;
// Max vis. results
watch(
computed(() => store.maxVisibleResults),
(v) => {
window.localStorage.setItem('maxVisibleResults', v.toString());
}
);
};
return {
setupStorage,
};
};
+5 -3
View File
@@ -103,10 +103,12 @@ export default defineComponent({
computed: {
sortedStationList() {
const sortedList = this.store.stationList.sort((a, b) => (a.name > b.name ? 1 : -1));
if (!this.store.searchedSceneryName || this.store.searchedSceneryName == '') return sortedList;
// if (!this.store.searchedSceneryName || this.store.searchedSceneryName == '') return sortedList;
return sortedList.filter((station) =>
station.name.toLowerCase().startsWith(this.store.searchedSceneryName.toLowerCase())
return sortedList.filter(
(station, i) =>
i < this.store.maxVisibleResults &&
station.name.toLowerCase().startsWith(this.store.searchedSceneryName.toLowerCase())
);
},
},