Convert store to typescript w/ matching interfaces

This commit is contained in:
2022-07-26 23:00:58 +02:00
parent 5eadb0b47a
commit 8216502eeb
15 changed files with 178 additions and 105 deletions

View File

@@ -1,23 +0,0 @@
export default {
namespaced: true,
state: {
darkmodeSupported: undefined,
userChoice: undefined
},
getters: {
darkmodeSupported: (state) => {
return state.darkmodeSupported
}
},
mutations: {
SET_DARKMODE_SUPPORT: (state, browserSupported) => {
state.darkmodeSupported = browserSupported
}
},
actions: {
findAndSetDarkmodeSupported({ commit }) {
const browserSupported = window.matchMedia('(prefers-color-scheme)').media !== 'not all'
commit('SET_DARKMODE_SUPPORT', browserSupported)
}
}
}

View File

@@ -0,0 +1,31 @@
import IStateDarkmode from "../interfaces/IStateDarkmode";
const state: IStateDarkmode = {
darkmodeSupported: false,
userChoice: undefined
};
export default {
namespaced: true,
state,
getters: {
darkmodeSupported: (state: IStateDarkmode) => {
return state.darkmodeSupported;
}
},
mutations: {
SET_DARKMODE_SUPPORT: (
state: IStateDarkmode,
browserSupported: boolean
) => {
state.darkmodeSupported = browserSupported;
}
},
actions: {
findAndSetDarkmodeSupported({ commit }) {
const browserSupported =
window.matchMedia("(prefers-color-scheme)").media !== "not all";
commit("SET_DARKMODE_SUPPORT", browserSupported);
}
}
};

View File

@@ -1,4 +1,6 @@
const capitalize = string => {
import type IStateDocumentTitle from "../interfaces/IStateDocumentTitle";
const capitalize = (string: string) => {
if (!string) return;
return string.includes(" ")
@@ -11,37 +13,39 @@ const capitalize = string => {
: string.charAt(0).toUpperCase() + string.slice(1);
};
const setDocumentTitle = state => {
const setDocumentTitle = (state: IStateDocumentTitle) => {
document.title = `${state.emoji} ${state.titlePrefix} | ${capitalize(
state.title
)}`;
};
const state: IStateDocumentTitle = {
emoji: "",
titlePrefix: "seasoned",
title: undefined
};
export default {
namespaced: true,
state: {
emoji: "",
titlePrefix: "seasoned",
title: undefined
},
state,
getters: {
title: state => state.title
title: (state: IStateDocumentTitle) => state.title
},
mutations: {
SET_EMOJI: (state, emoji) => {
SET_EMOJI: (state: IStateDocumentTitle, emoji: string) => {
state.emoji = emoji;
setDocumentTitle(state);
},
SET_TITLE: (state, title) => {
SET_TITLE: (state: IStateDocumentTitle, title: string) => {
state.title = title;
setDocumentTitle(state);
}
},
actions: {
updateEmoji({ commit }, emoji) {
updateEmoji({ commit }, emoji: String) {
commit("SET_EMOJI", emoji);
},
updateTitle({ commit }, title) {
updateTitle({ commit }, title: String) {
commit("SET_TITLE", title);
}
}

View File

@@ -1,8 +1,12 @@
import type IStateHamburger from "../interfaces/IStateHamburger";
const state: IStateHamburger = {
open: false
};
export default {
namespaced: true,
state: {
open: false
},
state,
getters: {
isOpen: state => state.open
},

View File

@@ -1,22 +1,19 @@
import { PopupTypes } from "../interfaces/IStatePopup";
import type { IStatePopup } from "../interfaces/IStatePopup";
const removeIncludedQueryParams = (params, key) => {
if (params.has(key)) params.delete(key);
return params;
};
const updateQueryParams = (id = null, type = null) => {
const updateQueryParams = (id: number | null = null, type: string = "") => {
let params = new URLSearchParams(window.location.search);
params = removeIncludedQueryParams(params, "movie");
params = removeIncludedQueryParams(params, "show");
params = removeIncludedQueryParams(params, "person");
if (id && type === "movie") {
params.append("movie", id);
}
if (id && type === "show") {
params.append("show", id);
}
if (id && type === "person") {
params.append("person", id);
if (id && type in PopupTypes) {
params.append(type, id.toString());
}
let url = `${window.location.protocol}//${window.location.hostname}${
@@ -31,13 +28,15 @@ const updateQueryParams = (id = null, type = null) => {
}
};
const state: IStatePopup = {
id: null,
type: null,
open: false
};
export default {
namespaced: true,
state: {
id: null,
type: null,
open: false
},
state,
getters: {
isOpen: state => state.open,
id: state => state.id,

View File

@@ -1,40 +0,0 @@
export default {
namespaced: true,
state: {
results: [],
resultCount: null
},
getters: {
results: (state) => {
return state.results
},
resultCount: (state) => {
return state.resultCount
}
},
mutations: {
SET_RESULTS: (state, results) => {
state.results = results;
},
SET_RESULT_COUNT: (state, count) => {
state.resultCount = count;
},
RESET: (state) => {
state.results = []
state.resultCount = null
}
},
actions: {
setResults({ commit }, results) {
commit('SET_RESULTS', results)
},
setResultCount({ commit }, count) {
commit('SET_RESULT_COUNT', count)
},
reset({ commit }) {
commit('RESET')
}
}
}

View File

@@ -0,0 +1,47 @@
import type ITorrent from "../interfaces/ITorrent";
import type IStateTorrent from "../interfaces/IStateTorrent";
const state: IStateTorrent = {
results: [],
resultCount: null
};
export default {
namespaced: true,
state: {
results: [],
resultCount: null
},
getters: {
results: (state: IStateTorrent) => {
return state.results;
},
resultCount: (state: IStateTorrent) => {
return state.resultCount;
}
},
mutations: {
SET_RESULTS: (state: IStateTorrent, results: Array<ITorrent>) => {
state.results = results;
},
SET_RESULT_COUNT: (state: IStateTorrent, count: number) => {
state.resultCount = count;
},
RESET: (state: IStateTorrent) => {
state.results = [];
state.resultCount = null;
}
},
actions: {
setResults({ commit }, results: Array<ITorrent>) {
commit("SET_RESULTS", results);
},
setResultCount({ commit }, count: number) {
commit("SET_RESULT_COUNT", count);
},
reset({ commit }) {
commit("RESET");
}
}
};