Updated version check components and strings.

This commit is contained in:
Mike Cao 2020-09-29 16:25:44 -07:00
parent 9f9208ad18
commit 57bb1cb655
20 changed files with 124 additions and 62 deletions

View file

@ -1,5 +1,5 @@
import { createSlice } from '@reduxjs/toolkit';
import { getItem } from 'lib/web';
import { get, getItem } from 'lib/web';
import { LOCALE_CONFIG, THEME_CONFIG } from 'lib/constants';
const app = createSlice({
@ -7,6 +7,10 @@ const app = createSlice({
initialState: {
locale: getItem(LOCALE_CONFIG) || 'en-US',
theme: getItem(THEME_CONFIG) || 'light',
versions: {
current: process.env.VERSION,
latest: null,
},
},
reducers: {
setLocale(state, action) {
@ -17,9 +21,49 @@ const app = createSlice({
state.theme = action.payload;
return state;
},
setVersions(state, action) {
state.versions = action.payload;
return state;
},
},
});
export const { setLocale, setTheme } = app.actions;
export const { setLocale, setTheme, setVersions } = app.actions;
export default app.reducer;
export function checkVersion() {
return async (dispatch, getState) => {
const {
app: {
versions: { current },
},
} = getState();
const data = await get('https://api.github.com/repos/mikecao/umami/releases/latest');
if (!data || !data['tag_name']) {
return;
}
const latest = data['tag_name'].startsWith('v') ? data['tag_name'].slice(1) : data['tag_name'];
if (latest === current) {
return;
}
const latestArray = latest.split('.');
const currentArray = current.split('.');
for (let i = 0; i < 3; i++) {
if (Number(latestArray[i]) > Number(currentArray[i])) {
return dispatch(
setVersions({
current,
latest: latest,
}),
);
}
}
};
}