More prefs cleanup (#1882)
* Update useHomeTabs * Use queryClient to fetch * Replace useHomeTabs and useDesktopRightNavItems * Fix type error * Some cleanup
This commit is contained in:
		
							parent
							
								
									37a2204483
								
							
						
					
					
						commit
						c3edde8ac6
					
				
					 12 changed files with 177 additions and 176 deletions
				
			
		|  | @ -1,51 +0,0 @@ | |||
| import {useEffect, useState} from 'react' | ||||
| import {useStores} from 'state/index' | ||||
| import isEqual from 'lodash.isequal' | ||||
| import {AtUri} from '@atproto/api' | ||||
| import {FeedSourceModel} from 'state/models/content/feed-source' | ||||
| 
 | ||||
| interface RightNavItem { | ||||
|   uri: string | ||||
|   href: string | ||||
|   hostname: string | ||||
|   collection: string | ||||
|   rkey: string | ||||
|   displayName: string | ||||
| } | ||||
| 
 | ||||
| export function useDesktopRightNavItems(uris: string[]): RightNavItem[] { | ||||
|   const store = useStores() | ||||
|   const [items, setItems] = useState<RightNavItem[]>([]) | ||||
|   const [lastUris, setLastUris] = useState<string[]>([]) | ||||
| 
 | ||||
|   useEffect(() => { | ||||
|     if (isEqual(uris, lastUris)) { | ||||
|       // no changes
 | ||||
|       return | ||||
|     } | ||||
| 
 | ||||
|     async function fetchFeedInfo() { | ||||
|       const models = uris | ||||
|         .slice(0, 25) | ||||
|         .map(uri => new FeedSourceModel(store, uri)) | ||||
|       await Promise.all(models.map(m => m.setup())) | ||||
|       setItems( | ||||
|         models.map(model => { | ||||
|           const {hostname, collection, rkey} = new AtUri(model.uri) | ||||
|           return { | ||||
|             uri: model.uri, | ||||
|             href: model.href, | ||||
|             hostname, | ||||
|             collection, | ||||
|             rkey, | ||||
|             displayName: model.displayName, | ||||
|           } | ||||
|         }), | ||||
|       ) | ||||
|       setLastUris(uris) | ||||
|     } | ||||
|     fetchFeedInfo() | ||||
|   }, [store, uris, lastUris, setLastUris, setItems]) | ||||
| 
 | ||||
|   return items | ||||
| } | ||||
|  | @ -1,29 +0,0 @@ | |||
| import {useEffect, useState} from 'react' | ||||
| import {useStores} from 'state/index' | ||||
| import isEqual from 'lodash.isequal' | ||||
| import {FeedSourceModel} from 'state/models/content/feed-source' | ||||
| 
 | ||||
| export function useHomeTabs(uris: string[]): string[] { | ||||
|   const store = useStores() | ||||
|   const [tabs, setTabs] = useState<string[]>(['Following']) | ||||
|   const [lastUris, setLastUris] = useState<string[]>([]) | ||||
| 
 | ||||
|   useEffect(() => { | ||||
|     if (isEqual(uris, lastUris)) { | ||||
|       // no changes
 | ||||
|       return | ||||
|     } | ||||
| 
 | ||||
|     async function fetchFeedInfo() { | ||||
|       const models = uris | ||||
|         .slice(0, 25) | ||||
|         .map(uri => new FeedSourceModel(store, uri)) | ||||
|       await Promise.all(models.map(m => m.setup())) | ||||
|       setTabs(['Following'].concat(models.map(f => f.displayName))) | ||||
|       setLastUris(uris) | ||||
|     } | ||||
|     fetchFeedInfo() | ||||
|   }, [store, uris, lastUris, setLastUris, setTabs]) | ||||
| 
 | ||||
|   return tabs | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue