Skip to content

Commit

Permalink
Merge pull request #103 from ranger-ross/upcoming-reviews-dropdown
Browse files Browse the repository at this point in the history
Upcoming reviews dropdown refactoring
  • Loading branch information
ranger-ross authored Feb 10, 2022
2 parents 830a946 + b11dcd8 commit 0821c0e
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 296 deletions.
8 changes: 4 additions & 4 deletions src/anki/components/AnkiReviewsChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {daysToMillis, millisToDays, truncDate} from "../../util/DateUtils.js";
import AnkiApiService from "../service/AnkiApiService.js";
import {scaleBand} from 'd3-scale';
import {getVisibleLabelIndices} from "../../util/ChartUtils.js";
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";

function DataPoint(date, previousDataPoint) {
let dp = {
Expand Down Expand Up @@ -146,9 +146,9 @@ function AnkiReviewsChart({deckNames, showTotals}) {
</Typography>
</Grid>
<Grid item xs={12} md={4} style={{textAlign: 'end'}}>
<DaysSelector days={daysToLookBack}
setDays={setDaysToLookBack}
options={[
<PeriodSelector period={daysToLookBack}
setPeriod={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
Expand Down
28 changes: 14 additions & 14 deletions src/anki/components/AnkiTotalCardsHistoryChart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Card, CardContent, CircularProgress, Grid, Typography} from "@mui/material";
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";
import {daysToMillis, millisToDays, truncDate} from "../../util/DateUtils.js";
import {ArgumentAxis, Chart, Legend, Tooltip, ValueAxis} from "@devexpress/dx-react-chart-material-ui";
import {ArgumentScale, EventTracker, LineSeries} from "@devexpress/dx-react-chart";
Expand Down Expand Up @@ -153,19 +153,19 @@ function AnkiTotalCardsHistoryChart({deckNames}) {
</Typography>
</Grid>
<Grid item xs={12} md={4} style={{textAlign: 'end'}}>
<DaysSelector days={daysToLookBack}
setDays={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!cardData ? {
value: millisToDays(Date.now() - cardData[0].date),
text: 'All'
} : null
]}
<PeriodSelector period={daysToLookBack}
setPeriod={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!cardData ? {
value: millisToDays(Date.now() - cardData[0].date),
text: 'All'
} : null
]}
/>
</Grid>
</Grid>
Expand Down
8 changes: 4 additions & 4 deletions src/anki/components/AnkiUpcomingReviewsChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {scaleBand} from 'd3-scale';
import {useSelectedAnkiDecks} from "../../hooks/useSelectedAnkiDecks.jsx";
import {truncDate} from "../../util/DateUtils.js";
import {getVisibleLabelIndices} from "../../util/ChartUtils.js";
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";
import {createAnkiCardsDueQuery} from "../service/AnkiDataUtil.js";

function DataPoint(day) {
Expand Down Expand Up @@ -120,16 +120,16 @@ function AnkiUpcomingReviewsChart() {
</Grid>

<Grid item xs={12} md={4} style={{textAlign: 'end'}}>
<DaysSelector
<PeriodSelector
period={days}
setPeriod={setDays}
options={[
{value: 7, text: '7'},
{value: 14, text: '14'},
{value: 30, text: '30'},
{value: 60, text: '60'},
{value: 90, text: '90'},
]}
days={days}
setDays={setDays}
/>
</Grid>

Expand Down
28 changes: 14 additions & 14 deletions src/bunpro/components/BunProReviewsHistoryChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ArgumentScale, BarSeries, EventTracker, Stack} from "@devexpress/dx-reac
import {daysToMillis, getMonthName, millisToDays, truncDate, truncMonth, truncWeek} from "../../util/DateUtils.js";
import {scaleBand} from 'd3-scale';
import {getVisibleLabelIndices} from "../../util/ChartUtils.js";
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";
import {fetchAllBunProReviews} from "../service/BunProDataUtil.js";
import useWindowDimensions from "../../hooks/useWindowDimensions.jsx";
import ToolTipLabel from "../../shared/ToolTipLabel.jsx";
Expand Down Expand Up @@ -190,19 +190,19 @@ function BunProReviewsHistoryChart() {
</Typography>
</Grid>
<Grid item xs={12} md={4} style={{textAlign: 'end'}}>
<DaysSelector days={daysToLookBack}
setDays={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!rawData && rawData.length > 0 ? {
value: millisToDays(Date.now() - new Date(rawData[0]['created_at'])),
text: 'All'
} : null
]}
<PeriodSelector period={daysToLookBack}
setPeriod={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!rawData && rawData.length > 0 ? {
value: millisToDays(Date.now() - new Date(rawData[0]['created_at'])),
text: 'All'
} : null
]}
/>
</Grid>
</Grid>
Expand Down
28 changes: 14 additions & 14 deletions src/bunpro/components/BunProTotalGrammarPointsChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ArgumentScale, EventTracker, LineSeries} from "@devexpress/dx-react-char
import {daysToMillis, millisToDays, truncDate} from "../../util/DateUtils.js";
import {scaleBand} from 'd3-scale';
import {getVisibleLabelIndices} from "../../util/ChartUtils.js";
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";
import useWindowDimensions from "../../hooks/useWindowDimensions.jsx";
import BunProApiService from "../service/BunProApiService.js";
import {createGrammarPointsLookupMap} from "../service/BunProDataUtil.js";
Expand Down Expand Up @@ -157,19 +157,19 @@ function BunProTotalGrammarPointsChart() {
</Typography>
</Grid>
<Grid item xs={12} md={4} style={{textAlign: 'end'}}>
<DaysSelector days={daysToLookBack}
setDays={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!rawData ? {
value: millisToDays(Date.now() - rawData[0].date),
text: 'All'
} : null
]}
<PeriodSelector period={daysToLookBack}
setPeriod={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!rawData ? {
value: millisToDays(Date.now() - rawData[0].date),
text: 'All'
} : null
]}
/>
</Grid>
</Grid>
Expand Down
28 changes: 14 additions & 14 deletions src/bunpro/components/BunProTotalReviewsChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ArgumentScale, EventTracker, LineSeries} from "@devexpress/dx-react-char
import {daysToMillis, millisToDays, truncDate} from "../../util/DateUtils.js";
import {scaleBand} from 'd3-scale';
import {getVisibleLabelIndices} from "../../util/ChartUtils.js";
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";
import {fetchAllBunProReviews} from "../service/BunProDataUtil.js";
import useWindowDimensions from "../../hooks/useWindowDimensions.jsx";

Expand Down Expand Up @@ -139,19 +139,19 @@ function BunProTotalReviewsChart() {
</Typography>
</Grid>
<Grid item xs={12} md={4} style={{textAlign: 'end'}}>
<DaysSelector days={daysToLookBack}
setDays={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!rawData ? {
value: millisToDays(Date.now() - rawData[0].date),
text: 'All'
} : null
]}
<PeriodSelector period={daysToLookBack}
setPeriod={setDaysToLookBack}
options={[
{value: 30, text: '1 Mon'},
{value: 60, text: '2 Mon'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
!!rawData ? {
value: millisToDays(Date.now() - rawData[0].date),
text: 'All'
} : null
]}
/>
</Grid>
</Grid>
Expand Down
39 changes: 18 additions & 21 deletions src/bunpro/components/BunProUpcomingReviewsChart.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useEffect, useMemo, useState} from "react";
import {Card, CardContent, Checkbox, CircularProgress, Typography} from "@mui/material";
import {Card, CardContent, CircularProgress, Typography} from "@mui/material";
import {addHours, truncMinutes} from '../../util/DateUtils.js';
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";
import {scaleBand} from 'd3-scale';
import BunProApiService from "../service/BunProApiService.js";
import {createGrammarPointsLookupMap, filterDeadGhostReviews} from "../service/BunProDataUtil.js";
Expand All @@ -10,7 +10,7 @@ import {ArgumentScale, BarSeries, EventTracker, LineSeries, Stack, ValueScale} f
import FilterableLegend from "../../shared/FilterableLegend.jsx";
import {
addTimeToDate, createUpcomingReviewsChartBarLabel,
createUpcomingReviewsChartLabel, formatTimeUnitLabelText,
createUpcomingReviewsChartLabel, formatTimeUnitLabelText, UnitSelector,
UpcomingReviewPeriods,
UpcomingReviewUnits
} from "../../util/UpcomingReviewChartUtils.jsx";
Expand Down Expand Up @@ -178,29 +178,26 @@ function BunProUpcomingReviewsChart() {
<div style={{display: 'flex', flexDirection: 'column', height: '100%'}}>
<div style={{display: 'flex', justifyContent: 'space-between'}}>

<div>
<Checkbox value={unit.key === UpcomingReviewUnits.days.key}
onChange={e => {
if (e.target.checked) {
setPeriod(UpcomingReviewUnits.days.default);
setUnit(UpcomingReviewUnits.days);
} else {
setPeriod(UpcomingReviewUnits.hours.default);
setUnit(UpcomingReviewUnits.hours);
}
}}
/>
Show Days
</div>
<UnitSelector
unit={unit}
onChange={unit => {
setPeriod(unit.default);
setUnit(unit);
}}
options={[
UpcomingReviewUnits.hours,
UpcomingReviewUnits.days,
]}
/>

<Typography variant={'h5'}>
Upcoming Reviews
</Typography>

<DaysSelector days={period}
setDays={setPeriod}
options={unit === UpcomingReviewUnits.days ?
UpcomingReviewPeriods.days : UpcomingReviewPeriods.hours}
<PeriodSelector period={period}
setPeriod={setPeriod}
options={unit === UpcomingReviewUnits.days ?
UpcomingReviewPeriods.days : UpcomingReviewPeriods.hours}
/>
</div>

Expand Down
24 changes: 12 additions & 12 deletions src/overview/components/OverviewReviewHistoryChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {EventTracker} from "@devexpress/dx-react-chart";
import {scaleBand} from 'd3-scale';
import React from 'react';
import {getVisibleLabelIndices} from "../../util/ChartUtils.js";
import DaysSelector from "../../shared/DaysSelector.jsx";
import PeriodSelector from "../../shared/PeriodSelector.jsx";
import WanikaniApiService from "../../wanikani/service/WanikaniApiService.js";
import {daysToMillis, truncDate} from "../../util/DateUtils.js";
import AnkiApiService from "../../anki/service/AnkiApiService.js";
Expand Down Expand Up @@ -277,17 +277,17 @@ function OverviewReviewsHistoryChart() {
</Grid>
) : (
<Grid item xs={12} md={4} style={{textAlign: 'end'}}>
<DaysSelector days={daysToLookBack}
setDays={setDaysToLookBack}
options={[
{value: 7, text: '7'},
{value: 14, text: '14'},
{value: 30, text: '30'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
{value: 10_000, text: 'All'},
]}
<PeriodSelector period={daysToLookBack}
setPeriod={setDaysToLookBack}
options={[
{value: 7, text: '7'},
{value: 14, text: '14'},
{value: 30, text: '30'},
{value: 90, text: '3 Mon'},
{value: 180, text: '6 Mon'},
{value: 365, text: '1 Yr'},
{value: 10_000, text: 'All'},
]}
/>
</Grid>
)}
Expand Down
Loading

0 comments on commit 0821c0e

Please sign in to comment.