|
1 | 1 | import * as React from 'react' |
2 | 2 | import * as Types from '../../constants/types/fs' |
| 3 | +import * as Constants from '../../constants/fs' |
3 | 4 | import * as Kb from '../../common-adapters' |
4 | 5 | import * as Container from '../../util/container' |
5 | 6 | import TlfType from './rows/tlf-type-container' |
@@ -39,6 +40,7 @@ const getRenderItem = destinationPickerIndex => ({item, section}) => |
39 | 40 | ) : ( |
40 | 41 | <WrapRow> |
41 | 42 | <Tlf |
| 43 | + disabled={false} |
42 | 44 | name={item.name} |
43 | 45 | tlfType={item.tlfType} |
44 | 46 | mixedMode={true} |
@@ -74,23 +76,32 @@ const useTopNTlfs = ( |
74 | 76 | [tlfs, n, tlfType] |
75 | 77 | ) |
76 | 78 |
|
77 | | -const useRecentTlfs = (n: number): Array<SectionListItem> => { |
| 79 | +const useRecentTlfs = (n: number, destinationPickerIndex?: number): Array<SectionListItem> => { |
78 | 80 | const tlfs = Container.useSelector(state => state.fs.tlfs) |
| 81 | + const username = Container.useSelector(state => state.config.username) |
79 | 82 | const privateTopN = useTopNTlfs(Types.TlfType.Private, tlfs.private, n) |
80 | 83 | const publicTopN = useTopNTlfs(Types.TlfType.Public, tlfs.public, n) |
81 | 84 | const teamTopN = useTopNTlfs(Types.TlfType.Team, tlfs.team, n) |
82 | | - return React.useMemo( |
83 | | - () => |
84 | | - [...privateTopN, ...publicTopN, ...teamTopN] |
85 | | - .sort(({tlfMtime: t1}, {tlfMtime: t2}) => t2 - t1) |
86 | | - .slice(0, n) |
87 | | - .map(({name, tlfType}) => ({name, tlfType})), |
88 | | - [privateTopN, publicTopN, teamTopN, n] |
89 | | - ) |
| 85 | + return React.useMemo(() => { |
| 86 | + const recent = [...privateTopN, ...publicTopN, ...teamTopN] |
| 87 | + .sort(({tlfMtime: t1}, {tlfMtime: t2}) => t2 - t1) |
| 88 | + .map(({name, tlfType}) => ({name, tlfType})) |
| 89 | + const afterFilter = |
| 90 | + // This isn't perfect since it doesn't cover the case where a team TLF |
| 91 | + // could be readonly. But to do that we'd need some new caching in KBFS |
| 92 | + // to plumb it into the Tlfs structure without awful overhead. |
| 93 | + typeof destinationPickerIndex === 'number' |
| 94 | + ? recent.filter( |
| 95 | + ({name, tlfType}) => |
| 96 | + !Constants.hideOrDisableInDestinationPicker(tlfType, name, username, destinationPickerIndex) |
| 97 | + ) |
| 98 | + : recent |
| 99 | + return afterFilter.slice(0, n) |
| 100 | + }, [destinationPickerIndex, privateTopN, publicTopN, teamTopN, n, username]) |
90 | 101 | } |
91 | 102 |
|
92 | 103 | const Root = ({destinationPickerIndex}: Props) => { |
93 | | - const top10 = useRecentTlfs(10) |
| 104 | + const top10 = useRecentTlfs(10, destinationPickerIndex) |
94 | 105 | const sections = [ |
95 | 106 | ...(destinationPickerIndex |
96 | 107 | ? [] // don't show sfmi banner in destination picker |
|
0 commit comments