-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
highlight workplan row when inserted or edited (#1084)
* highlight workplan row when inserted or edited * clear timeout if it exists * simplify save task and save milestone methods * remove try catch at resource level
- Loading branch information
1 parent
c86c7f1
commit 77350e6
Showing
9 changed files
with
230 additions
and
102 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
epictrack-web/src/components/workPlan/event/EventContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { createContext } from "react"; | ||
import { EVENT_TYPE } from "../phase/type"; | ||
|
||
export interface HighlightedRow { | ||
type: EVENT_TYPE; | ||
id: number; | ||
} | ||
|
||
interface EventContextProps { | ||
highlightedRow: HighlightedRow | null; | ||
handleHighlightRow: (rowToHighlight?: HighlightedRow) => void; | ||
} | ||
|
||
export const EventContext = createContext<EventContextProps>({ | ||
highlightedRow: null, | ||
handleHighlightRow: (_rowToHighlight?: HighlightedRow) => { | ||
return; | ||
}, | ||
}); | ||
|
||
let highlightTimout: null | NodeJS.Timeout = null; | ||
export const EventProvider = ({ | ||
children, | ||
}: { | ||
children: JSX.Element | JSX.Element[]; | ||
}) => { | ||
const [highlightedRow, setHighlightedRow] = | ||
React.useState<HighlightedRow | null>(null); | ||
|
||
const handleHighlightRow = (rowToHighlight?: HighlightedRow) => { | ||
if (!rowToHighlight) return; | ||
if (highlightTimout) { | ||
clearTimeout(highlightTimout); | ||
} | ||
const HIGHLIGHT_DURATION = 6000; | ||
setHighlightedRow(rowToHighlight); | ||
highlightTimout = setTimeout(() => { | ||
setHighlightedRow(null); | ||
}, HIGHLIGHT_DURATION); | ||
}; | ||
|
||
return ( | ||
<EventContext.Provider | ||
value={{ | ||
highlightedRow, | ||
handleHighlightRow, | ||
}} | ||
> | ||
{children} | ||
</EventContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
import { EventProvider } from "./EventContext"; | ||
import EventList from "./EventList"; | ||
|
||
const Event = () => { | ||
return ( | ||
<EventProvider> | ||
<EventList /> | ||
</EventProvider> | ||
); | ||
}; | ||
|
||
export default Event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.