-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to allow multiple ids to be edited
Signed-off-by: ibolton336 <ibolton@redhat.com>
- Loading branch information
1 parent
41d47c3
commit 0eeb915
Showing
5 changed files
with
72 additions
and
55 deletions.
There are no files selected for viewing
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
27 changes: 0 additions & 27 deletions
27
client/src/app/pages/external/jira/useUpdatingTrackerId.ts
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
client/src/app/pages/external/jira/useUpdatingTrackerIds.ts
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,42 @@ | ||
import { useState } from "react"; | ||
import dayjs from "dayjs"; | ||
|
||
export type UpdatableId = { | ||
id: number; | ||
expirationTime: dayjs.ConfigType; | ||
}; | ||
|
||
const useUpdatingTrackerIds = () => { | ||
const [updatingTrackerIds, setUpdatingTrackerIds] = useState< | ||
Map<number, dayjs.Dayjs> | ||
>(new Map()); | ||
|
||
const addUpdatingTrackerId = (id: number) => { | ||
const now = dayjs(); | ||
const existingExpiry = updatingTrackerIds.get(id); | ||
|
||
if (!existingExpiry || existingExpiry.isBefore(now)) { | ||
const expiryDate = dayjs().add(8, "seconds"); | ||
|
||
setUpdatingTrackerIds((prevMap) => { | ||
const updatedMap = new Map(prevMap); | ||
updatedMap.set(id, expiryDate); | ||
return updatedMap; | ||
}); | ||
|
||
const timeRemaining = expiryDate.diff(now); | ||
|
||
setTimeout(() => { | ||
setUpdatingTrackerIds((prevMap) => { | ||
const updatedMap = new Map(prevMap); | ||
updatedMap.delete(id); | ||
return updatedMap; | ||
}); | ||
}, timeRemaining); | ||
} | ||
}; | ||
|
||
return [updatingTrackerIds, addUpdatingTrackerId] as const; | ||
}; | ||
|
||
export default useUpdatingTrackerIds; |