mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	This PR fixes two problems: (1) The initial redirect put us into an infinite loop when redirecting, because trying to go back to the root would always trigger the initial redirect component. Throwing you back to project screen. (2) Using UI config in the useLastViewedProject to get the basePath introduced a race condition where you needed data from the uiConfig in order to fetch the correct key from local storage. The fix here was to use the basePath coded into the HTML file, so we can synchronously retrieve the correct key at startup. Co-authored-by: kwasniew <kwasniewski.mateusz@gmail.com>
		
			
				
	
	
		
			23 lines
		
	
	
		
			579 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			579 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { useEffect, useState } from 'react';
 | |
| import { getLocalStorageItem, setLocalStorageItem } from '../utils/storage';
 | |
| import { basePath } from 'utils/formatPath';
 | |
| 
 | |
| export const useLastViewedProject = () => {
 | |
|     const key = `${basePath}:unleash-lastViewedProject`;
 | |
| 
 | |
|     const [lastViewed, setLastViewed] = useState(() => {
 | |
|         return getLocalStorageItem(key);
 | |
|     });
 | |
| 
 | |
|     useEffect(() => {
 | |
|         if (lastViewed) {
 | |
|             setLocalStorageItem(key, lastViewed);
 | |
|         }
 | |
|     }, [lastViewed, key]);
 | |
| 
 | |
|     return {
 | |
|         lastViewed,
 | |
|         setLastViewed,
 | |
|     };
 | |
| };
 |