Skip to content

Commit

Permalink
fix: code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Jan 14, 2025
1 parent 12f59b1 commit 5c13d58
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 317 deletions.
40 changes: 22 additions & 18 deletions src/modules/account/home/memberAnalytics/MemberActionsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ import {
import { MyAnalyticsDateRangeDataContext } from '~analytics/context/MyAnalyticsDateRangeContext';
import { groupActions } from '~analytics/utils';

function getFreqFromData(actions: [string, Action[]][]) {
const { months, days, years } = intervalToDuration({
start: new Date(actions[0]?.[0]),
end: new Date(actions[1]?.[0]),
});

// get bar interval
if (years && years >= 1) {
return GroupByInterval.Year;
} else if (days === 1) {
return GroupByInterval.Day;
} else if (months === 1 && !days) {
return GroupByInterval.Month;
} else {
return 'other';
}
}

export function MemberActionsChart({
actions,
}: Readonly<{
Expand All @@ -56,32 +74,18 @@ export function MemberActionsChart({
isLargeScreen ? MAX_BARS_LARGE_SCREEN : MAX_BARS_SMALL_SCREEN,
);

const actionsEntires = Object.entries(groupedActionsByInterval);
const actionsEntries = Object.entries(groupedActionsByInterval);
const freq = getFreqFromData(actionsEntries);

const { months, days, years } = intervalToDuration({
start: new Date(actionsEntires[0]?.[0]),
end: new Date(actionsEntires[1]?.[0]),
});

// get bar interval
const freq =
years && years >= 1
? GroupByInterval.Year
: days === 1
? GroupByInterval.Day
: months === 1 && !days
? GroupByInterval.Month
: 'other';

const noOfActionTypesOverInterval = actionsEntires.map(
const noOfActionTypesOverInterval = actionsEntries.map(
([dateString, localActions], index) => {
const actionsOverIntervalTypeCounts = countBy(localActions, 'type');

// getting chart x-axis title for specified interval
let title = '';
const date = new Date(dateString);
const nextDate = new Date(
actionsEntires[index + 1]?.[0] || dateRange.endDate,
actionsEntries[index + 1]?.[0] || dateRange.endDate,
);

switch (freq) {
Expand Down
20 changes: 0 additions & 20 deletions src/modules/analytics/mockServer/database.ts

This file was deleted.

278 changes: 0 additions & 278 deletions src/modules/analytics/mockServer/mockServer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/modules/landing/Platforms/PlatformCube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

import { PlatformColorSurface } from './PlatformColorSurface';

function Row({ children }: { children: ReactNode }) {
function Row({ children }: Readonly<{ children: ReactNode }>) {
return (
<Stack direction={{ xs: 'column', sm: 'row' }} gap="2px">
{children}
Expand Down

0 comments on commit 5c13d58

Please sign in to comment.