@@ -2,6 +2,7 @@ import type { EnvironmentId } from "@t3tools/contracts";
22import { buildProjectGroups } from "@t3tools/client-runtime/state/project-grouping" ;
33import {
44 createContext ,
5+ useCallback ,
56 useContext ,
67 useMemo ,
78 useRef ,
@@ -79,24 +80,26 @@ export function SettingsEnvironmentFilterProvider(props: {
7980} ) {
8081 const [ selectedIds , setSelectedIds ] = useState < ReadonlySet < EnvironmentId > | null > ( null ) ;
8182 const [ selectedProjectKey , setSelectedProjectKey ] = useState < string | null > ( null ) ;
82- // Written only by selectProject; a closed Settings has no project page left to read it.
8383 const currentProjectKey = useRef < string | null > ( null ) ;
8484 if ( ! props . open && ( selectedIds !== null || selectedProjectKey !== null ) ) {
85+ currentProjectKey . current = null ;
8586 setSelectedIds ( null ) ;
8687 setSelectedProjectKey ( null ) ;
8788 }
89+ const selectProject = useCallback ( ( projectKey : string | null ) => {
90+ currentProjectKey . current = projectKey ;
91+ setSelectedProjectKey ( projectKey ) ;
92+ } , [ ] ) ;
93+ const getSelectedProjectKey = useCallback ( ( ) => currentProjectKey . current , [ ] ) ;
8894 const value = useMemo (
8995 ( ) => ( {
9096 selectedIds,
9197 selectedProjectKey,
9298 setSelectedIds,
93- selectProject : ( projectKey : string | null ) => {
94- currentProjectKey . current = projectKey ;
95- setSelectedProjectKey ( projectKey ) ;
96- } ,
97- getSelectedProjectKey : ( ) => currentProjectKey . current ,
99+ selectProject,
100+ getSelectedProjectKey,
98101 } ) ,
99- [ selectedIds , selectedProjectKey ] ,
102+ [ selectedIds , selectedProjectKey , selectProject , getSelectedProjectKey ] ,
100103 ) ;
101104 return (
102105 < SettingsEnvironmentSelectionContext value = { value } >
0 commit comments