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 to localstorage & fix bug

kruzhambus69d1f447fde1
diff --git a/src/pages/Project/View/ViewProject.tsx b/src/pages/Project/View/ViewProject.tsx
index 74902ad34..a100d09fc 100644
--- a/src/pages/Project/View/ViewProject.tsx
+++ b/src/pages/Project/View/ViewProject.tsx
@@ -43,7 +43,7 @@ import {
tbPeriodPairs, getProjectCacheKey, LIVE_VISITORS_UPDATE_INTERVAL, DEFAULT_TIMEZONE, CDN_URL, isDevelopment,
timeBucketToDays, getProjectCacheCustomKey, roleViewer, MAX_MONTHS_IN_PAST, PROJECT_TABS,
TimeFormat, getProjectForcastCacheKey, chartTypes, roleAdmin, TRAFFIC_PANELS_ORDER, PERFORMANCE_PANELS_ORDER, isSelfhosted, tbPeriodPairsCompare,
- PERIOD_PAIRS_COMPARE, periodToCompareDate, filtersPeriodPairs,
+ PERIOD_PAIRS_COMPARE, periodToCompareDate, filtersPeriodPairs, IS_ACTIVE_COMPARE,
} from 'redux/constants'
import { IUser } from 'redux/models/IUser'
import { IProject, ILiveStats } from 'redux/models/IProject'
@@ -217,7 +217,19 @@ const ViewProject = ({
label: string
period: string
}[]>(tbPeriodPairsCompare(t))
- const [isActiveCompare, setIsActiveCompare] = useState<boolean>(false)
+ const [isActiveCompare, setIsActiveCompare] = useState<boolean>(() => {
+ const activeCompare = getItem(IS_ACTIVE_COMPARE)
+
+ if (typeof activeCompare === 'string') {
+ return activeCompare === 'true'
+ }
+
+ if (typeof activeCompare === 'boolean') {
+ return activeCompare
+ }
+
+ return false
+ })
const [activePeriodCompare, setActivePeriodCompare] = useState<string>(periodPairsCompare[0].period)
const activeDropdownLabelCompare = useMemo(() => _find(periodPairsCompare, p => p.period === activePeriodCompare)?.label, [periodPairsCompare, activePeriodCompare])
const [dateRangeCompare, setDateRangeCompare] = useState<null | Date[]>(null)
@@ -493,6 +505,7 @@ const ViewProject = ({
} else {
date = _find(periodToCompareDate, (item) => item.period === period)?.formula()
}
+
if (date) {
fromCompare = getFormatDate(date.from)
toCompare = getFormatDate(date.to)
@@ -1474,6 +1487,7 @@ const ViewProject = ({
// loadAnalytics when compare period change or compare selected
useEffect(() => {
+ setItem(IS_ACTIVE_COMPARE, JSON.stringify(isActiveCompare))
if (activePeriodCompare === PERIOD_PAIRS_COMPARE.CUSTOM && !dateRangeCompare) {
return
}
diff --git a/src/redux/constants/index.ts b/src/redux/constants/index.ts
index d97717100..596c2bca1 100644
--- a/src/redux/constants/index.ts
+++ b/src/redux/constants/index.ts
@@ -118,7 +118,7 @@ export const periodToCompareDate: {
const to = new Date()
to.setDate(to.getDate() - 1)
const from = new Date()
- from.setDate(to.getDate() - 1)
+ from.setDate(from.getDate() - 2)
return {
from,
to,
@@ -130,7 +130,7 @@ export const periodToCompareDate: {
const to = new Date()
to.setDate(to.getDate() - 7)
const from = new Date()
- from.setDate(to.getDate() - 7)
+ from.setDate(from.getDate() - 14)
return {
from,
to,
@@ -142,7 +142,7 @@ export const periodToCompareDate: {
const to = new Date()
to.setDate(to.getDate() - 28)
const from = new Date()
- from.setDate(to.getDate() - 28)
+ from.setDate(from.getDate() - 56)
return {
from,
to,
@@ -154,7 +154,7 @@ export const periodToCompareDate: {
const to = new Date()
to.setMonth(to.getMonth() - 3)
const from = new Date()
- from.setMonth(to.getMonth() - 3)
+ from.setMonth(from.getMonth() - 6)
return {
from,
to,
@@ -166,7 +166,7 @@ export const periodToCompareDate: {
const to = new Date()
to.setMonth(to.getMonth() - 12)
const from = new Date()
- from.setMonth(to.getMonth() - 12)
+ from.setMonth(from.getMonth() - 24)
return {
from,
to,
@@ -316,6 +316,7 @@ export const REFRESH_TOKEN: string = 'refresh_token'
// LocalStorage
export const PAGE_FORCE_REFRESHED = 'page-force-refreshed'
+export const IS_ACTIVE_COMPARE = 'is-active-compare'
// List of languages with translations available
export const whitelist: string[] = ['en', 'uk', 'pl', 'de', 'sv', 'el', 'ru', 'hi', 'zh']