-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Ensure issuesGroupedState is up to date #348
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||
import { Box, Spinner, Stack, Skeleton } from '@chakra-ui/react'; | ||||||||||
import { useHookstate } from '@hookstate/core'; | ||||||||||
import { hookstate, useHookstateMemo } from '@hookstate/core'; | ||||||||||
import type { Dayjs } from 'dayjs'; | ||||||||||
import _ from 'lodash'; | ||||||||||
import React, { useEffect, useMemo, useState } from 'react'; | ||||||||||
|
@@ -22,8 +22,6 @@ import { globalTimeScaler } from '../../lib/client/TimeScaler'; | |||||||||
import { convertIssueDataStateToDetailedViewGroupOld } from '../../lib/client/convertIssueDataToDetailedViewGroup'; | ||||||||||
import { useRouter } from 'next/router'; | ||||||||||
import { ErrorBoundary } from '../errors/ErrorBoundary'; | ||||||||||
import { usePrevious } from '../../hooks/usePrevious'; | ||||||||||
import getUniqIdForGroupedIssues from '../../lib/client/getUniqIdForGroupedIssues'; | ||||||||||
import { useShowTodayMarker } from '../../hooks/useShowTodayMarker'; | ||||||||||
import { useGlobalLoadingState } from '../../hooks/useGlobalLoadingState'; | ||||||||||
|
||||||||||
|
@@ -36,19 +34,14 @@ export function RoadmapDetailed({ | |||||||||
const [isDevMode, _setIsDevMode] = useState(false); | ||||||||||
const viewMode = useViewMode() as ViewMode; | ||||||||||
const router = useRouter(); | ||||||||||
|
||||||||||
const issuesGroupedState = useHookstate<DetailedViewGroup[]>([]); | ||||||||||
const groupedIssuesId = getUniqIdForGroupedIssues(issuesGroupedState.value) | ||||||||||
const groupedIssuesIdPrev = usePrevious(groupedIssuesId); | ||||||||||
const globalLoadingState = useGlobalLoadingState(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving global loading state up to the top |
||||||||||
const query = router.query | ||||||||||
const showTodayMarker = useShowTodayMarker(); | ||||||||||
|
||||||||||
const setIssuesGroupedState = issuesGroupedState.set | ||||||||||
useEffect(() => { | ||||||||||
if (viewMode && groupedIssuesIdPrev !== groupedIssuesId) { | ||||||||||
setIssuesGroupedState(() => convertIssueDataStateToDetailedViewGroupOld(issueDataState, viewMode, query)) | ||||||||||
} | ||||||||||
}, [viewMode, query, setIssuesGroupedState, issueDataState, groupedIssuesIdPrev, groupedIssuesId]); | ||||||||||
const memoGrouped = useHookstateMemo( | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useHookstateMemo properly recognizes uniqueness of hookState objects. |
||||||||||
() => convertIssueDataStateToDetailedViewGroupOld(issueDataState, viewMode, query), | ||||||||||
[viewMode, query, issueDataState] | ||||||||||
) | ||||||||||
const issuesGroupedState = hookstate<DetailedViewGroup[]>(memoGrouped) | ||||||||||
|
||||||||||
/** | ||||||||||
* Magic numbers that just seem to work are: | ||||||||||
|
@@ -63,15 +56,13 @@ export function RoadmapDetailed({ | |||||||||
*/ | ||||||||||
const [numHeaderTicks, setNumHeaderTicks] = useState(5); | ||||||||||
const [numGridCols, setNumGridCols] = useState(45); | ||||||||||
const globalLoadingState = useGlobalLoadingState(); | ||||||||||
|
||||||||||
|
||||||||||
// for preventing dayjsDates from being recalculated if it doesn't need to be | ||||||||||
const issuesGroupedId = issuesGroupedState.value.map((g) => g.groupName).join(','); | ||||||||||
/** | ||||||||||
* Collect all due dates from all issues, as DayJS dates. | ||||||||||
*/ | ||||||||||
const dayjsDates: Dayjs[] = useMemo(() => { | ||||||||||
const dayjsDates: Dayjs[] = useHookstateMemo(() => { | ||||||||||
const today = dayjs(); | ||||||||||
let innerDayjsDates: Dayjs[] = [] | ||||||||||
try { | ||||||||||
|
@@ -114,7 +105,7 @@ export function RoadmapDetailed({ | |||||||||
|
||||||||||
return innerDayjsDates; | ||||||||||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||||||||||
}, [issuesGroupedState.length, issuesGroupedId]); | ||||||||||
}, [issuesGroupedState, issuesGroupedId]); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useHookstateMemo properly recognizes uniqueness of hookState objects. |
||||||||||
|
||||||||||
/** | ||||||||||
* * Ensure that the dates are | ||||||||||
|
@@ -129,15 +120,6 @@ export function RoadmapDetailed({ | |||||||||
globalTimeScaler.setScale(dates, numGridCols * 1.09); | ||||||||||
}, [dates, numGridCols]); | ||||||||||
|
||||||||||
const invalidGroups = issuesGroupedState.filter((group) => group.ornull == null || group.items.ornull == null) | ||||||||||
if (issuesGroupedState.value.length === 0 || invalidGroups.length > 0) { | ||||||||||
if (invalidGroups.length > 0) { | ||||||||||
invalidGroups.forEach((g) => { | ||||||||||
console.warn('Found an invalid group: ', g.value); | ||||||||||
}); | ||||||||||
} | ||||||||||
return <Spinner />; | ||||||||||
} | ||||||||||
|
||||||||||
// return early while loading. | ||||||||||
if (globalLoadingState.get()) { | ||||||||||
|
@@ -151,6 +133,15 @@ export function RoadmapDetailed({ | |||||||||
</Stack> | ||||||||||
) | ||||||||||
} | ||||||||||
const invalidGroups = issuesGroupedState.filter((group) => group.ornull == null || group.items.ornull == null) | ||||||||||
if (issuesGroupedState.value.length === 0 || invalidGroups.length > 0) { | ||||||||||
if (invalidGroups.length > 0) { | ||||||||||
invalidGroups.forEach((g) => { | ||||||||||
console.warn('Found an invalid group: ', g.value); | ||||||||||
}); | ||||||||||
Comment on lines
+139
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optionally
Suggested change
|
||||||||||
} | ||||||||||
return <Spinner />; | ||||||||||
} | ||||||||||
Comment on lines
+136
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only processing invalidGroups after globalLoadingState check |
||||||||||
|
||||||||||
/** | ||||||||||
* Current getTicks function returns 1 less than the number of ticks we want. | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,10 +71,9 @@ export function RoadmapTabbedView({ | |
} | ||
|
||
return ( | ||
<Skeleton isLoaded={!globalLoadingState.get()}> | ||
<Skeleton isLoaded={!globalLoadingState.get()} key={index}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix react warning |
||
<Tab | ||
className={styles.gridViewTab} | ||
key={index} | ||
> | ||
<Center> | ||
<TabIcon /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import NextLink from 'next/link'; | ||
import { Flex, Text, Box, Center } from '@chakra-ui/react'; | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import type { State } from '@hookstate/core' | ||
import React, { useState } from 'react'; | ||
import { State, useHookstateEffect, useHookstateMemo } from '@hookstate/core' | ||
|
||
import { dayjs } from '../../lib/client/dayjs'; | ||
import { IssueData, IssueDataViewInput } from '../../lib/types'; | ||
|
@@ -33,13 +33,12 @@ export function GridRow({ | |
const viewMode = useViewMode(); | ||
const routerQuery = useRouter().query; | ||
const [closestDateIdx, setClosestDateIdx] = useState(Math.round(globalTimeScaler.getColumn(dayjs.utc(milestone.due_date.get()).toDate()))); | ||
useEffect(() => { | ||
useHookstateEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: useHookstateEffect is supposed to recognize hookstate objects, but doesn't seem to work properly, unlike useHookstateMemo (which does work properly, not rerunning the hook callback if hookstate object wasn't changed) |
||
setClosestDateIdx(Math.round(globalTimeScaler.getColumn(dayjs.utc(milestone.due_date.get()).toDate()))); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [milestone.due_date, globalTimeScaler.getDomain()]); | ||
}, [milestone.due_date, ...globalTimeScaler.getDomain()]); | ||
const span = Math.max(4, numGridCols / timelineTicks.length); | ||
const closest = span * (closestDateIdx - 1); | ||
const childLink = useMemo(() => getLinkForRoadmapChild({ viewMode, issueData: milestone.get(), query: routerQuery, currentRoadmapRoot: issueDataState.value }), [issueDataState.value, milestone, routerQuery, viewMode]); | ||
const childLink = useHookstateMemo(() => getLinkForRoadmapChild({ viewMode, issueData: milestone.get(), query: routerQuery, currentRoadmapRoot: issueDataState.value }), [issueDataState, milestone, routerQuery, viewMode]); | ||
const clickable = milestone.children.length > 0; | ||
|
||
if (milestone == null || milestone.ornull == null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Did this API change?