-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #786 from CareTogether/fix-clipboard-safari
Fix #660
- Loading branch information
Showing
4 changed files
with
162 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { atom, useRecoilState } from 'recoil'; | ||
|
||
export const showGlobalSnackBar = atom<string | null>({ | ||
key: 'showGlobalSnackBar', | ||
default: null, | ||
}); | ||
|
||
export function useGlobalSnackBar() { | ||
const [message, setMessage] = useRecoilState(showGlobalSnackBar); | ||
|
||
return { | ||
message, | ||
setAndShowGlobalSnackBar: (newMessage: string) => { | ||
setMessage((currentMessage) => { | ||
if (currentMessage === null) { | ||
return newMessage; | ||
} | ||
|
||
// If newMessage is equal to the currentMessage, add a " (x)" at the end | ||
// to indicate how many times that notification was shown. | ||
const match = currentMessage | ||
?.replace(newMessage, '') | ||
.match(/^\s\((\d)\)$/); | ||
|
||
const currentMessageIncludesCounter = match !== null; | ||
|
||
const isADuplicatedMessage = | ||
currentMessageIncludesCounter || currentMessage === newMessage; | ||
|
||
const currentMessageNumber = match ? parseInt(match[1]) : 0; | ||
|
||
if (isADuplicatedMessage) { | ||
return `${newMessage} (${currentMessageNumber + 1})`; | ||
} | ||
|
||
return newMessage; | ||
}); | ||
}, | ||
resetSnackBar: () => { | ||
setMessage(null); | ||
}, | ||
}; | ||
} |
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