Add app store

This commit is contained in:
2020-09-16 11:15:26 +03:00
parent 5d33377a50
commit 9482f7e359
13 changed files with 168 additions and 65 deletions

View File

@@ -2,7 +2,7 @@
<div id="app">
<div class="left-panel"
:class="{'left-panel-closed': leftPanelClosed}">
<LeftPanel @closeLeftPanel="closeLeftPanel()"></LeftPanel>
<LeftPanel></LeftPanel>
</div>
<div class="content w-100"
:class="{'content-when-left-panel-open': !leftPanelClosed}">
@@ -45,6 +45,8 @@ import LeftPanel from '@/components/LeftPanel.vue'
import LottieAnimation from "lottie-vuejs/src/LottieAnimation.vue";
import { StoreType } from '@/store';
interface AnimData {
direction: number;
currentTime: number;
@@ -73,8 +75,6 @@ interface ILottieAnimation {
},
})
export default class App extends Vue {
public leftPanelClosed: boolean = true;
@Ref('close-icon') public readonly closeIcon!: ILottieAnimation;
setAnimController(controller: IAnimController) {
@@ -111,6 +111,17 @@ export default class App extends Vue {
this.leftPanelClosed = true;
}
get leftPanelClosed(): boolean {
return (this.$store as StoreType).state.app.leftPanelClosed;
}
set leftPanelClosed(value: boolean) {
const store = (this.$store as StoreType);
store.dispatch('app/setLeftPanelCloseStatus', value)
.catch(error => console.log(error));
}
}
</script>

View File

@@ -43,26 +43,36 @@
</template>
<script lang="ts">
import 'reflect-metadata';
import { Component, Prop, Vue } from 'vue-property-decorator';
@Component
export default class LeftPanel extends Vue {
public closed: boolean = true;
import { StoreType } from '@/store';
@Component({
name: 'LeftPanel',
})
export default class LeftPanel extends Vue {
isActiveLink(name: string): boolean {
return this.$route.name === name;
}
closeLeftPanel() {
(this.$store as StoreType).dispatch('app/setLeftPanelCloseStatus', true)
.catch(error => console.log(error));
}
goToHome() {
if (this.$route.name !== "Home")
this.$router.push({'name': 'Home'});
this.$emit('closeLeftPanel');
this.closeLeftPanel();
}
goToAboutMe() {
if (this.$route.name !== "About Me")
this.$router.push({'name': 'About Me'});
this.$emit('closeLeftPanel');
this.closeLeftPanel();
}
}
</script>

View File

@@ -1,9 +1,7 @@
import { Actions } from 'vuex-smart-module';
import Vue from 'vue';
import { AxiosResponse, AxiosError } from 'axios';
import AlbumsState from './state';
import AlbumsState, { IAlbum } from './state';
import AlbumsGetters from './getters';
import AlbumsMutations from './muttations';
import AlbumsMutations from './mutations';
export default class AlbumsActions extends Actions<
AlbumsState,
@@ -11,5 +9,53 @@ export default class AlbumsActions extends Actions<
AlbumsMutations,
AlbumsActions
> {
$init() {
const albums: IAlbum[] = [
{
name: 'Test',
description: 'Test description',
protected: false,
folderName: 'test',
files: [
'p (1).jpg',
'p (2).jpg',
'p (3).jpg',
'p (4).jpg',
'p (5).jpg',
'p (6).jpg',
]
},
{
name: 'Test 2',
description: 'Test 2 description',
protected: false,
folderName: 'test2',
files: [
'p (1).jpg',
'p (2).jpg',
'p (3).jpg',
'p (4).jpg',
'p (5).jpg',
]
},
{
name: 'Test 3',
description: 'Test 3 description',
protected: false,
folderName: 'test3',
files: [
'p (1).jpg',
'p (2).jpg',
'p (3).jpg',
'p (4).jpg',
'p (5).jpg',
]
}
];
setTimeout(() => this.commit('updateAlbums', albums), 500);
}
}

View File

@@ -1,7 +1,7 @@
import { Module } from 'vuex-smart-module';
import AlbumsState from './state';
import AlbumsGetters from './getters';
import AlbumsMutations from './muttations';
import AlbumsMutations from './mutations';
import AlbumsActions from './actions';

15
src/store/app/actions.ts Normal file
View File

@@ -0,0 +1,15 @@
import { Actions } from 'vuex-smart-module';
import AppState from './state';
import AppGetters from './getters';
import AppMutations from './mutations';
export default class AppActions extends Actions<
AppState,
AppGetters,
AppMutations,
AppActions
> {
setLeftPanelCloseStatus(value: boolean) {
this.commit("setLeftPanelCloseStatus", value);
}
}

6
src/store/app/getters.ts Normal file
View File

@@ -0,0 +1,6 @@
import { Getters } from 'vuex-smart-module';
import AppState from './state';
export default class AppGetters extends Getters<AppState> {
}

16
src/store/app/index.ts Normal file
View File

@@ -0,0 +1,16 @@
import { Module } from 'vuex-smart-module';
import AppState from './state';
import AppGetters from './getters';
import AppMutations from './mutations';
import AppActions from './actions';
import AlbumsMutations from '../albums/mutations';
const appModule = new Module({
state: AppState,
getters: AppGetters,
mutations: AppMutations,
actions: AppActions,
});
export default appModule;

View File

@@ -0,0 +1,8 @@
import { Mutations } from 'vuex-smart-module';
import AppState from './state';
export default class AppMutations extends Mutations<AppState> {
setLeftPanelCloseStatus(value: boolean) {
this.state.leftPanelClosed = value;
}
}

3
src/store/app/state.ts Normal file
View File

@@ -0,0 +1,3 @@
export default class AppState {
leftPanelClosed: boolean = true;
}

View File

@@ -7,11 +7,15 @@ import { Store } from 'vuex';
import albums from './albums';
import albumsState from './albums/state';
import app from './app';
import appState from './app/state';
Vue.use(Vuex);
interface IStore {
albums: albumsState
albums: albumsState,
app: appState
}
export type StoreType = Store<IStore>;
@@ -20,6 +24,7 @@ const store: StoreType = createStore(
new Module({
modules: {
albums,
app
}
}),
{

View File

@@ -1,6 +1,10 @@
<template>
<div>
<LeftBlock title="HOME" description="kreorg photos" picture="/pictures/home.jpg" :leftPanelClosed="leftPanelClosed"></LeftBlock>
<LeftBlock
title="HOME"
description="kreorg photos"
picture="/pictures/home.jpg"
:leftPanelClosed="leftPanelClosed"></LeftBlock>
</div>
</template>

View File

@@ -11,11 +11,13 @@
<script lang="ts">
import 'reflect-metadata';
import { Component, Prop, Vue } from 'vue-property-decorator';
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
import LeftBlock from '@/components/LeftBlock.vue';
import Album from '@/components/Album.vue';
import { IAlbum } from '@/store/albums/state'
import { IAlbum } from '@/store/albums/state';
import { StoreType } from '@/store';
@Component({
@@ -30,57 +32,34 @@ export default class Home extends Vue {
public albums: IAlbum[] = [];
public sourceAlbums: IAlbum[] = [
{
name: 'Test',
description: 'Test description',
protected: false,
public timeoutsIds: number[] = [];
folderName: 'test',
files: [
'p (1).jpg',
'p (2).jpg',
'p (3).jpg',
'p (4).jpg',
'p (5).jpg',
'p (6).jpg',
]
},
{
name: 'Test 2',
description: 'Test 2 description',
protected: false,
get albumsSource() {
const store = (this.$store as StoreType);
folderName: 'test2',
files: [
'p (1).jpg',
'p (2).jpg',
'p (3).jpg',
'p (4).jpg',
'p (5).jpg',
]
},
{
name: 'Test 3',
description: 'Test 3 description',
protected: false,
const albums = store.state.albums.albums;
folderName: 'test3',
files: [
'p (1).jpg',
'p (2).jpg',
'p (3).jpg',
'p (4).jpg',
'p (5).jpg',
]
if (albums === null)
return [];
return albums;
}
];
mounted() {
this.sourceAlbums.forEach((item, index) => {
@Watch('albumsSource')
onAlbumsSourceChanged(val: IAlbum[], oldVal: IAlbum[] | null) {
this.updateAlbums();
}
updateAlbums() {
this.albums = [];
this.albumsSource.forEach((item, index) => {
setTimeout(() => this.albums.push(item), 300 * index);
})
}
mounted() {
this.updateAlbums();
}
}
</script>