🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
rename date mode to day
Bill Yangbc731577914b
diff --git a/client/src/app/components/Header/DateSelector.tsx b/client/src/app/components/Header/DateSelector.tsxindex 1e91cd4c1..dc31a0309 100644--- a/client/src/app/components/Header/DateSelector.tsx+++ b/client/src/app/components/Header/DateSelector.tsx@@ -17,14 +17,14 @@ const getLabel = (time: Time) => {return `${time.startDate} - ${time.endDate}`;}- if (time.mode === "date") {- if (time.date === DateTime.now().toISODate()) {+ if (time.mode === "day") {+ if (time.day === DateTime.now().toISODate()) {return "Today";}- if (time.date === DateTime.now().minus({ days: 1 }).toISODate()) {+ if (time.day === DateTime.now().minus({ days: 1 }).toISODate()) {return "Yesterday";}- return time.date;+ return time.day;}};@@ -40,8 +40,8 @@ export function DateSelector() {<DropdownMenuItemonClick={() =>setTime({- mode: "date",- date: DateTime.now().toISODate(),+ mode: "day",+ day: DateTime.now().toISODate(),})}>@@ -51,7 +51,7 @@ export function DateSelector() {onClick={() =>setTime({mode: "range",- startDate: DateTime.now().minus({ days: 7 }).toISODate(),+ startDate: DateTime.now().minus({ days: 6 }).toISODate(),endDate: DateTime.now().toISODate(),})}@@ -62,7 +62,7 @@ export function DateSelector() {onClick={() =>setTime({mode: "range",- startDate: DateTime.now().minus({ days: 30 }).toISODate(),+ startDate: DateTime.now().minus({ days: 29 }).toISODate(),endDate: DateTime.now().toISODate(),})}diff --git a/client/src/app/components/MainSection/BucketSelection.tsx b/client/src/app/components/MainSection/BucketSelection.tsxindex d9413df14..39b96e098 100644--- a/client/src/app/components/MainSection/BucketSelection.tsx+++ b/client/src/app/components/MainSection/BucketSelection.tsx@@ -11,7 +11,7 @@ import {import { DateTime } from "luxon";const getOptions = (time: Time) => {- if (time.mode === "date") {+ if (time.mode === "day") {return (<SelectContent><SelectItem size="sm" value="hour">diff --git a/client/src/app/components/MainSection/Chart.tsx b/client/src/app/components/MainSection/Chart.tsxindex d72351e5f..b9e579a50 100644--- a/client/src/app/components/MainSection/Chart.tsx+++ b/client/src/app/components/MainSection/Chart.tsx@@ -4,7 +4,7 @@ import { ResponsiveLine } from "@nivo/line";import { GetPageViewsResponse } from "../../actions/getPageviews";import { DateTime } from "luxon";import { round } from "lodash";-import { useTimeSelection } from "../../../lib/timeSelectionStore";+import { Time, useTimeSelection } from "../../../lib/timeSelectionStore";export const nivoTheme: Theme = {axis: {@@ -54,6 +54,22 @@ export const nivoTheme: Theme = {export const formatter = Intl.NumberFormat("en", { notation: "compact" });+const getMax = (time: Time) => {+ if (time.mode === "day") {+ return DateTime.fromISO(time.day)+ .endOf("day")+ .minus({ minutes: 59 })+ .toJSDate();+ } else if (time.mode === "week") {+ return DateTime.fromISO(time.week).endOf("week").toJSDate();+ } else if (time.mode === "month") {+ return DateTime.fromISO(time.month).endOf("month").toJSDate();+ } else if (time.mode === "year") {+ return DateTime.fromISO(time.year).endOf("year").toJSDate();+ }+ return undefined;+};+export function Chart({data,}: {@@ -66,16 +82,17 @@ export function Chart({}) {const { time, bucket } = useTimeSelection();+ const formattedData = data?.data?.map((e) => ({+ x: DateTime.fromSQL(e.time).toUTC().toFormat("yyyy-MM-dd HH:mm:ss"),+ y: e.pageviews,+ }));+return (<ResponsiveLinedata={[{id: "1",- data:- data?.data?.map((e) => ({- x: e.time,- y: e.pageviews,- })) ?? [],+ data: formattedData ?? [],},]}theme={nivoTheme}@@ -84,6 +101,8 @@ export function Chart({type: "time",format: "%Y-%m-%d %H:%M:%S",precision: "second",+ useUTC: true,+ max: getMax(time),}}yScale={{type: "linear",@@ -102,11 +121,11 @@ export function Chart({tickRotation: 0,truncateTickAt: 0,tickValues:- time.mode === "date"+ time.mode === "day"? Math.min(24, data?.data?.length ?? 0): Math.min(12, data?.data?.length ?? 0),format: (value) => {- if (time.mode === "date") {+ if (time.mode === "day") {return DateTime.fromJSDate(value).toFormat("ha");} else if (time.mode === "range") {return DateTime.fromJSDate(value).toFormat("MMM d");diff --git a/client/src/app/hooks/utils.ts b/client/src/app/hooks/utils.tsindex dab280a42..20e66d85f 100644--- a/client/src/app/hooks/utils.ts+++ b/client/src/app/hooks/utils.ts@@ -10,5 +10,8 @@ export function getStartAndEndDate(time: Time) {if (time.mode === "year") {return { startDate: time.year, endDate: time.year };}- return { startDate: time.date, endDate: time.date };+ if (time.mode === "week") {+ return { startDate: time.week, endDate: time.week };+ }+ return { startDate: time.day, endDate: time.day };}diff --git a/client/src/lib/timeSelectionStore.ts b/client/src/lib/timeSelectionStore.tsindex 16079141b..d70bb4dcf 100644--- a/client/src/lib/timeSelectionStore.ts+++ b/client/src/lib/timeSelectionStore.ts@@ -2,8 +2,8 @@ import { DateTime } from "luxon";import { create } from "zustand";type DateMode = {- mode: "date";- date: string;+ mode: "day";+ day: string;};type DateRangeMode = {@@ -40,12 +40,12 @@ type Store = {export const useTimeSelection = create<Store>((set) => ({time: {- mode: "date",- date: DateTime.now().toISODate(),+ mode: "day",+ day: DateTime.now().toISODate(),},setTime: (time) => {let bucketToUse: TimeBucket = "hour";- if (time.mode === "date") {+ if (time.mode === "day") {bucketToUse = "hour";} else if (time.mode === "range") {const timeRangeLength = DateTime.fromISO(time.endDate).diff(@@ -73,10 +73,10 @@ export const useTimeSelection = create<Store>((set) => ({export const goBack = () => {const { time, setTime } = useTimeSelection.getState();- if (time.mode === "date") {+ if (time.mode === "day") {setTime({- mode: "date",- date: DateTime.fromISO(time.date).minus({ days: 1 }).toISODate() ?? "",+ mode: "day",+ day: DateTime.fromISO(time.day).minus({ days: 1 }).toISODate() ?? "",});} else if (time.mode === "range") {const startDate = DateTime.fromISO(time.startDate);@@ -96,14 +96,14 @@ export const goBack = () => {export const goForward = () => {const { time, setTime } = useTimeSelection.getState();- if (time.mode === "date") {+ if (time.mode === "day") {setTime({- mode: "date",- date:- DateTime.fromISO(time.date).plus({ days: 1 }).toISODate() ??+ mode: "day",+ day:+ DateTime.fromISO(time.day).plus({ days: 1 }).toISODate() ??"" > DateTime.now().toISODate()? DateTime.now().toISODate()- : DateTime.fromISO(time.date).plus({ days: 1 }).toISODate() ?? "",+ : DateTime.fromISO(time.day).plus({ days: 1 }).toISODate() ?? "",});} else if (time.mode === "range") {const startDate = DateTime.fromISO(time.startDate);