-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Shows client side loading state for jira tracker (#1409)
Closes [False 'not connected' status for new Jira instance](https://issues.redhat.com/browse/MTA-1019) --------- Signed-off-by: ibolton336 <ibolton@redhat.com>
- Loading branch information
1 parent
7690380
commit fae624b
Showing
5 changed files
with
89 additions
and
23 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
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; |
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