jellyfin-vue/store/backdrop.ts
MrTimscampi 09b94982b1 feat(backdrop): add backdrop support
A component has been added to the default layout, which displays a blurhash from a Vuex store. The
Vuex store can either set or clear backdrops. To set a backdrop, you must pass a BaseItemDto[] in
order to retrieve the relevant images.
2020-09-25 14:14:17 +02:00

40 lines
973 B
TypeScript

import { ActionTree, GetterTree, MutationTree } from 'vuex';
export interface BackdropState {
blurhash: string;
}
export const state = (): BackdropState => ({
blurhash: ''
});
export const getters: GetterTree<BackdropState, BackdropState> = {
getBackdropBlurhash: (state: BackdropState) => state.blurhash
};
export const mutations: MutationTree<BackdropState> = {
SET_CURRENT_BACKDROP(state: BackdropState, newBlurhash: string) {
state.blurhash = newBlurhash;
},
CLEAR_CURRENT_BACKDROP(state: BackdropState) {
state.blurhash = '';
}
};
export const actions: ActionTree<BackdropState, BackdropState> = {
set({ commit }, { item }) {
let hash: string;
if (item.ImageBlurHashes.Backdrop && item.BackdropImageTags) {
hash = item.ImageBlurHashes?.Backdrop[item.BackdropImageTags[0]];
} else {
hash = '';
}
commit('SET_CURRENT_BACKDROP', hash);
},
clear({ commit }) {
commit('CLEAR_CURRENT_BACKDROP');
}
};