Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

add redux and fix bug when open projects

kruzhambus2bb7887babba
diff --git a/src/pages/Captcha/Settings/CaptchaSettings.container.jsx b/src/pages/Captcha/Settings/CaptchaSettings.container.jsx
index a70721881..954c8fef3 100644
--- a/src/pages/Captcha/Settings/CaptchaSettings.container.jsx
+++ b/src/pages/Captcha/Settings/CaptchaSettings.container.jsx
@@ -35,7 +35,7 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(UIActions.removeCaptchProject(pid))
},
deleteProjectCache: (pid) => {
- dispatch(UIActions.deleteProjectCache(pid))
+ dispatch(UIActions.deleteCaptchaProjectCache(pid))
},
showError: (message) => {
dispatch(errorsActions.genericError(message))
diff --git a/src/pages/Captcha/View/ViewCaptcha.container.jsx b/src/pages/Captcha/View/ViewCaptcha.container.jsx
index a811cf889..15b585c21 100644
--- a/src/pages/Captcha/View/ViewCaptcha.container.jsx
+++ b/src/pages/Captcha/View/ViewCaptcha.container.jsx
@@ -6,14 +6,13 @@ import { alertsActions } from 'redux/actions/alerts'
import ViewProject from './ViewCaptcha'
const mapStateToProps = (state) => ({
- projects: state.ui.projects.projects,
- isLoading: state.ui.projects.isLoading,
- cache: state.ui.cache.analytics,
- projectViewPrefs: state.ui.cache.projectViewPrefs,
+ projects: state.ui.projects.captchaProjects,
+ isLoading: state.ui.projects.isLoadingCaptcha,
+ cache: state.ui.cache.captchaAnalytics,
+ projectViewPrefs: state.ui.cache.captchaProjectsViewPrefs,
authenticated: state.auth.authenticated,
timezone: state.auth.user.timezone,
isPaidTierUsed: state.auth.isPaidTierUsed,
- extensions: state.ui.misc.extensions,
user: state.auth.user,
})
@@ -22,22 +21,16 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(errorsActions.genericError(message))
},
setProjectCache: (pid, data, key) => {
- dispatch(UIActions.setProjectCache(pid, data, key))
- },
- setPublicProject: (project) => {
- dispatch(UIActions.setPublicProject(project))
+ dispatch(UIActions.setCaptchaProjectCache(pid, data, key))
},
setProjects: (project) => {
- dispatch(UIActions.setProjects(project))
- },
- setLiveStatsForProject: (id, count) => {
- dispatch(UIActions.setLiveStatsForProject(id, count))
+ dispatch(UIActions.setCaptchaProjects(project))
},
generateAlert: (message, type) => {
dispatch(alertsActions.generateAlerts(message, type))
},
setProjectViewPrefs: (pid, period, timeBucket, rangeDate) => {
- dispatch(UIActions.setProjectViewPrefs(pid, period, timeBucket, rangeDate))
+ dispatch(UIActions.setCaptchaProjectsViewPrefs(pid, period, timeBucket, rangeDate))
},
})
diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.js
index 6896afba9..8bea73f23 100644
--- a/src/redux/actions/ui/index.js
+++ b/src/redux/actions/ui/index.js
@@ -123,6 +123,13 @@ const setProjectCache = (pid, data, key) => ({
},
})
+const setCaptchaProjectCache = (pid, data, key) => ({
+ type: types.SET_CAPTCHA_PROJECT_CHACHE,
+ payload: {
+ pid, data, key,
+ },
+})
+
const setProjectCachePerf = (pid, data, key) => ({
type: types.SET_PROJECT_CACHE_PERF,
payload: {
@@ -144,6 +151,13 @@ const deleteProjectCache = (pid, period, timeBucket) => ({
},
})
+const deleteCaptchaProjectCache = (pid, period, timeBucket) => ({
+ type: types.DELETE_CAPTCHA_PROJECT_CACHE,
+ payload: {
+ pid, period, timeBucket,
+ },
+})
+
const deleteProjectCachePerf = (pid, period, timeBucket) => ({
type: types.DELETE_PROJECT_CACHE_PERF,
payload: {
@@ -158,6 +172,13 @@ const setProjectViewPrefs = (pid, period, timeBucket, rangeDate) => ({
},
})
+const setCaptchaProjectsViewPrefs = (pid, period, timeBucket, rangeDate) => ({
+ type: types.SET_CAPTCHA_PROJECTS_VIEW_PREFS,
+ payload: {
+ pid, period, timeBucket, rangeDate,
+ },
+})
+
const setTheme = (theme) => ({
type: types.SET_THEME,
payload: {
@@ -304,6 +325,9 @@ const UIActions = {
loadProjectsCaptcha,
setCaptchaLoading,
removeCaptchProject,
+ setCaptchaProjectsViewPrefs,
+ setCaptchaProjectCache,
+ deleteCaptchaProjectCache,
}
export default UIActions
diff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.js
index a5705baba..e37ea59cb 100644
--- a/src/redux/actions/ui/types.js
+++ b/src/redux/actions/ui/types.js
@@ -4,8 +4,11 @@ export const types = {
SET_PROJECTS_LOADING: 'UI_SET_PROJECTS_LOADING',
REMOVE_PROJECT: 'UI_REMOVE_PROJECT',
SET_PROJECT_CACHE: 'UI_SET_PROJECT_CACHE',
+ SET_CAPTCHA_PROJECT_CHACHE: 'UI_SET_CAPTCHA_PROJECT_CHACHE',
DELETE_PROJECT_CACHE: 'UI_DELETE_PROJECT_CACHE',
+ DELETE_CAPTCHA_PROJECT_CACHE: 'UI_DELETE_CAPTCHA_PROJECT_CACHE',
SET_PROJECT_VIEW_PREFS: 'UI_SET_PROJECT_VIEW_PREFS',
+ SET_CAPTCHA_PROJECTS_VIEW_PREFS: 'UI_SET_CAPTCHA_PROJECTS_VIEW_PREFS',
SET_PROJECTS: 'UI_SET_PROJECTS',
SET_EXTENSIONS: 'UI_SET_EXTENSIONS',
LOAD_EXTENSIONS: 'UI_LOAD_EXTENSIONS',
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index 2298f33e7..e9cc4862b 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -114,6 +114,7 @@ export const TITLE_SUFFIX = '| Swetrix'
export const LS_THEME_SETTING = 'colour-theme'
export const LS_VIEW_PREFS_SETTING = 'proj-view-preferences'
+export const LS_CAPTCHA_VIEW_PREFS_SETTING = 'captcha-view-preferences'
export const DEFAULT_TIMEZONE = 'Etc/GMT'
diff --git a/src/redux/reducers/ui/cache.js b/src/redux/reducers/ui/cache.js
index 4ee4a80ec..7a661844e 100644
--- a/src/redux/reducers/ui/cache.js
+++ b/src/redux/reducers/ui/cache.js
@@ -2,16 +2,16 @@ import { types } from 'redux/actions/ui/types'
import _filter from 'lodash/filter'
import _isEmpty from 'lodash/isEmpty'
-import { getProjectCacheKey, LS_VIEW_PREFS_SETTING } from 'redux/constants'
+import { getProjectCacheKey, LS_VIEW_PREFS_SETTING, LS_CAPTCHA_VIEW_PREFS_SETTING } from 'redux/constants'
-export const getInitialViewPrefs = () => {
+export const getInitialViewPrefs = (LS_VIEW) => {
if (typeof window !== 'undefined' && window.localStorage) {
- const storedPrefs = window.localStorage.getItem(LS_VIEW_PREFS_SETTING)
+ const storedPrefs = window.localStorage.getItem(LS_VIEW)
if (typeof storedPrefs === 'string') {
try {
return JSON.parse(storedPrefs)
} catch (e) {
- window.localStorage.removeItem(LS_VIEW_PREFS_SETTING)
+ window.localStorage.removeItem(LS_VIEW)
}
}
}
@@ -27,8 +27,12 @@ const getInitialState = () => {
analyticsPerf: {},
+ captchaAnalytics: {},
+
+ captchaProjectsViewPrefs: getInitialViewPrefs(LS_CAPTCHA_VIEW_PREFS_SETTING),
+
// { pid: { period: '7d', timeBucket: 'day' }, ... }
- projectViewPrefs: getInitialViewPrefs(),
+ projectViewPrefs: getInitialViewPrefs(LS_VIEW_PREFS_SETTING),
}
}
@@ -50,6 +54,21 @@ const cacheReducer = (state = getInitialState(), { type, payload }) => {
}
}
+ case types.SET_CAPTCHA_PROJECT_CACHE: {
+ const { pid, data, key } = payload
+
+ return {
+ ...state,
+ captchaAnalytics: {
+ ...state.captchaAnalytics,
+ [pid]: {
+ ...state.captchaAnalytics[pid],
+ [key]: data,
+ },
+ },
+ }
+ }
+
case types.DELETE_PROJECT_CACHE: {
const { pid, period, timeBucket } = payload
const key = getProjectCacheKey(period, timeBucket)
@@ -77,6 +96,33 @@ const cacheReducer = (state = getInitialState(), { type, payload }) => {
}
}
+ case types.DELETE_CAPTCHA_PROJECT_CACHE: {
+ const { pid, period, timeBucket } = payload
+ const key = getProjectCacheKey(period, timeBucket)
+
+ if (_isEmpty(period) || _isEmpty(timeBucket)) {
+ if (_isEmpty(pid)) {
+ return {
+ ...state,
+ captchaAnalytics: {},
+ }
+ }
+
+ return {
+ ...state,
+ captchaAnalytics: _filter(state.captchaAnalytics, (project) => project !== pid),
+ }
+ }
+
+ return {
+ ...state,
+ captchaAnalytics: {
+ ...state.captchaAnalytics,
+ [pid]: _filter(state.captchaAnalytics[pid], (ckey) => ckey !== key),
+ },
+ }
+ }
+
case types.SET_PROJECT_VIEW_PREFS: {
const {
pid, period, timeBucket, rangeDate,
@@ -95,6 +141,24 @@ const cacheReducer = (state = getInitialState(), { type, payload }) => {
}
}
+ case types.SET_CAPTCHA_PROJECTS_VIEW_PREFS: {
+ const {
+ pid, period, timeBucket, rangeDate,
+ } = payload
+
+ return {
+ ...state,
+ captchaProjectsViewPrefs: {
+ ...state.captchaProjectsViewPrefs,
+ [pid]: rangeDate ? {
+ period, timeBucket, rangeDate,
+ } : {
+ period, timeBucket,
+ },
+ },
+ }
+ }
+
case types.SET_PROJECT_CACHE_PERF: {
const { pid, data, key } = payload