mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Moved code into src folder. Added build for component library.
This commit is contained in:
parent
7a7233ead4
commit
ede658771e
490 changed files with 749 additions and 442 deletions
47
src/store/app.js
Normal file
47
src/store/app.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { create } from 'zustand';
|
||||
import {
|
||||
DATE_RANGE_CONFIG,
|
||||
DEFAULT_DATE_RANGE,
|
||||
DEFAULT_LOCALE,
|
||||
DEFAULT_THEME,
|
||||
LOCALE_CONFIG,
|
||||
THEME_CONFIG,
|
||||
} from 'lib/constants';
|
||||
import { getItem } from 'next-basics';
|
||||
|
||||
const initialState = {
|
||||
locale: getItem(LOCALE_CONFIG) || DEFAULT_LOCALE,
|
||||
theme: getItem(THEME_CONFIG) || DEFAULT_THEME,
|
||||
dateRange: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE,
|
||||
shareToken: null,
|
||||
user: null,
|
||||
config: null,
|
||||
};
|
||||
|
||||
const store = create(() => ({ ...initialState }));
|
||||
|
||||
export function setTheme(theme) {
|
||||
store.setState({ theme });
|
||||
}
|
||||
|
||||
export function setLocale(locale) {
|
||||
store.setState({ locale });
|
||||
}
|
||||
|
||||
export function setShareToken(shareToken) {
|
||||
store.setState({ shareToken });
|
||||
}
|
||||
|
||||
export function setUser(user) {
|
||||
store.setState({ user });
|
||||
}
|
||||
|
||||
export function setConfig(config) {
|
||||
store.setState({ config });
|
||||
}
|
||||
|
||||
export function setDateRange(dateRange) {
|
||||
store.setState({ dateRange });
|
||||
}
|
||||
|
||||
export default store;
|
||||
20
src/store/dashboard.js
Normal file
20
src/store/dashboard.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { create } from 'zustand';
|
||||
import { DASHBOARD_CONFIG, DEFAULT_WEBSITE_LIMIT } from 'lib/constants';
|
||||
import { getItem, setItem } from 'next-basics';
|
||||
|
||||
export const initialState = {
|
||||
showCharts: true,
|
||||
limit: DEFAULT_WEBSITE_LIMIT,
|
||||
websiteOrder: [],
|
||||
editing: false,
|
||||
};
|
||||
|
||||
const store = create(() => ({ ...initialState, ...getItem(DASHBOARD_CONFIG) }));
|
||||
|
||||
export function saveDashboard(settings) {
|
||||
store.setState(settings);
|
||||
|
||||
setItem(DASHBOARD_CONFIG, store.getState());
|
||||
}
|
||||
|
||||
export default store;
|
||||
13
src/store/queries.js
Normal file
13
src/store/queries.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { create } from 'zustand';
|
||||
|
||||
const store = create(() => ({}));
|
||||
|
||||
export function saveQuery(key, data) {
|
||||
store.setState({ [key]: data });
|
||||
}
|
||||
|
||||
export function getQuery(key) {
|
||||
return store.getState()[key];
|
||||
}
|
||||
|
||||
export default store;
|
||||
55
src/store/version.js
Normal file
55
src/store/version.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { create } from 'zustand';
|
||||
import produce from 'immer';
|
||||
import semver from 'semver';
|
||||
import { CURRENT_VERSION, VERSION_CHECK, UPDATES_URL } from 'lib/constants';
|
||||
import { getItem } from 'next-basics';
|
||||
|
||||
const initialState = {
|
||||
current: CURRENT_VERSION,
|
||||
latest: null,
|
||||
hasUpdate: false,
|
||||
checked: false,
|
||||
releaseUrl: null,
|
||||
};
|
||||
|
||||
const store = create(() => ({ ...initialState }));
|
||||
|
||||
export async function checkVersion() {
|
||||
const { current } = store.getState();
|
||||
|
||||
const data = await fetch(`${UPDATES_URL}?v=${current}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
}).then(res => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
store.setState(
|
||||
produce(state => {
|
||||
const { latest, url } = data;
|
||||
const lastCheck = getItem(VERSION_CHECK);
|
||||
|
||||
const hasUpdate = !!(latest && lastCheck?.version !== latest && semver.gt(latest, current));
|
||||
|
||||
state.current = current;
|
||||
state.latest = latest;
|
||||
state.hasUpdate = hasUpdate;
|
||||
state.checked = true;
|
||||
state.releaseUrl = url;
|
||||
|
||||
return state;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export default store;
|
||||
25
src/store/websites.ts
Normal file
25
src/store/websites.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { create } from 'zustand';
|
||||
import produce from 'immer';
|
||||
import { DateRange } from 'lib/types';
|
||||
|
||||
const store = create(() => ({}));
|
||||
|
||||
export function getWebsiteDateRange(websiteId: string) {
|
||||
return store.getState()?.[websiteId];
|
||||
}
|
||||
|
||||
export function setWebsiteDateRange(websiteId: string, dateRange: DateRange) {
|
||||
store.setState(
|
||||
produce(state => {
|
||||
if (!state[websiteId]) {
|
||||
state[websiteId] = {};
|
||||
}
|
||||
|
||||
state[websiteId].dateRange = { ...dateRange, modified: Date.now() };
|
||||
|
||||
return state;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export default store;
|
||||
Loading…
Add table
Add a link
Reference in a new issue