-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #41725 from software-mansion-labs/search/kicu/3989…
…0-action-buttons [Search v1] Add handling of actions and improve Search list items
- Loading branch information
Showing
29 changed files
with
346 additions
and
91 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
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,58 @@ | ||
import React, {useCallback, useContext, useMemo, useState} from 'react'; | ||
import type ChildrenProps from '@src/types/utils/ChildrenProps'; | ||
import type {SearchContext} from './types'; | ||
|
||
const defaultSearchContext = { | ||
currentSearchHash: -1, | ||
selectedTransactionIDs: [], | ||
setCurrentSearchHash: () => {}, | ||
setSelectedTransactionIds: () => {}, | ||
}; | ||
|
||
const Context = React.createContext<SearchContext>(defaultSearchContext); | ||
|
||
function SearchContextProvider({children}: ChildrenProps) { | ||
const [searchContextData, setSearchContextData] = useState<Pick<SearchContext, 'currentSearchHash' | 'selectedTransactionIDs'>>({ | ||
currentSearchHash: defaultSearchContext.currentSearchHash, | ||
selectedTransactionIDs: defaultSearchContext.selectedTransactionIDs, | ||
}); | ||
|
||
const setCurrentSearchHash = useCallback( | ||
(searchHash: number) => { | ||
setSearchContextData({ | ||
...searchContextData, | ||
currentSearchHash: searchHash, | ||
}); | ||
}, | ||
[searchContextData], | ||
); | ||
|
||
const setSelectedTransactionIds = useCallback( | ||
(selectedTransactionIDs: string[]) => { | ||
setSearchContextData({ | ||
...searchContextData, | ||
selectedTransactionIDs, | ||
}); | ||
}, | ||
[searchContextData], | ||
); | ||
|
||
const searchContext = useMemo<SearchContext>( | ||
() => ({ | ||
...searchContextData, | ||
setCurrentSearchHash, | ||
setSelectedTransactionIds, | ||
}), | ||
[searchContextData, setCurrentSearchHash, setSelectedTransactionIds], | ||
); | ||
|
||
return <Context.Provider value={searchContext}>{children}</Context.Provider>; | ||
} | ||
|
||
function useSearchContext() { | ||
return useContext(Context); | ||
} | ||
|
||
SearchContextProvider.displayName = 'SearchContextProvider'; | ||
|
||
export {SearchContextProvider, useSearchContext}; |
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
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.