mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 13:38:13 +00:00
feature: local storage
This commit is contained in:
@@ -13,6 +13,7 @@ import { RouterView } from 'vue-router';
|
|||||||
import { IUser, AuthState } from './types/types';
|
import { IUser, AuthState } from './types/types';
|
||||||
import useRouteGuard from './mixins/useRouteGuard';
|
import useRouteGuard from './mixins/useRouteGuard';
|
||||||
import { useStore } from './store';
|
import { useStore } from './store';
|
||||||
|
import useLocalStorage from './mixins/useLocalStorage';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
mixins: [dataMixin],
|
mixins: [dataMixin],
|
||||||
@@ -20,7 +21,10 @@ export default defineComponent({
|
|||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
const { routeAuthGuard } = useRouteGuard();
|
const { routeAuthGuard } = useRouteGuard();
|
||||||
|
const { setupStorage } = useLocalStorage();
|
||||||
|
|
||||||
routeAuthGuard();
|
routeAuthGuard();
|
||||||
|
setupStorage();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
store: useStore(),
|
store: useStore(),
|
||||||
|
|||||||
@@ -53,6 +53,12 @@
|
|||||||
<button style="margin-left: 0.5em" @click="clearInput">Wyczyść</button>
|
<button style="margin-left: 0.5em" @click="clearInput">Wyczyść</button>
|
||||||
</div>
|
</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">
|
<div class="pane">
|
||||||
<button @click="changelogVisible = !changelogVisible">
|
<button @click="changelogVisible = !changelogVisible">
|
||||||
{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog
|
{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog
|
||||||
|
|||||||
@@ -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,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
@@ -103,10 +103,12 @@ export default defineComponent({
|
|||||||
computed: {
|
computed: {
|
||||||
sortedStationList() {
|
sortedStationList() {
|
||||||
const sortedList = this.store.stationList.sort((a, b) => (a.name > b.name ? 1 : -1));
|
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) =>
|
return sortedList.filter(
|
||||||
station.name.toLowerCase().startsWith(this.store.searchedSceneryName.toLowerCase())
|
(station, i) =>
|
||||||
|
i < this.store.maxVisibleResults &&
|
||||||
|
station.name.toLowerCase().startsWith(this.store.searchedSceneryName.toLowerCase())
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user