-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into refactor/implement-transaction-summary-on…
…-details
- Loading branch information
Showing
12 changed files
with
790 additions
and
1,779 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
import { useCallback, useState } from "react"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
|
||
export const useAccordion = () => { | ||
const [isExpanded, setIsExpanded] = useState(true); | ||
const getStorageKey = (key: string) => `accordion_${key}_isExpanded`; | ||
|
||
export const useAccordion = (key: string) => { | ||
const storageKey = getStorageKey(key); | ||
const [isExpanded, setIsExpanded] = useState<boolean>(() => { | ||
const storedValue = localStorage.getItem(storageKey); | ||
return storedValue ? JSON.parse(storedValue) : true; | ||
}); | ||
|
||
const handleHeaderClick = useCallback( | ||
(event: React.MouseEvent) => { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
|
||
setIsExpanded(!isExpanded); | ||
const newValue = !isExpanded; | ||
setIsExpanded(newValue); | ||
localStorage.setItem(storageKey, JSON.stringify(newValue)); | ||
}, | ||
[isExpanded], | ||
[isExpanded, storageKey], | ||
); | ||
|
||
useEffect(() => { | ||
const handleStorageChange = () => { | ||
const storedValue = localStorage.getItem(storageKey); | ||
if (storedValue) { | ||
setIsExpanded(JSON.parse(storedValue)); | ||
} | ||
}; | ||
|
||
window.addEventListener("storage", handleStorageChange); | ||
return () => window.removeEventListener("storage", handleStorageChange); | ||
}, [storageKey]); | ||
|
||
return { handleHeaderClick, isExpanded }; | ||
}; |
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
Oops, something went wrong.