1
- import { Typography } from '@mui/material' ;
1
+ import { Alert , Skeleton , Typography } from '@mui/material' ;
2
2
3
3
import { DiscriminatedItem , ItemType , PermissionLevel } from '@graasp/sdk' ;
4
4
@@ -29,7 +29,7 @@ const RootNavigationTree = ({
29
29
const { t : translateBuilder } = useBuilderTranslation ( ) ;
30
30
31
31
// todo: to change with real recent items (most used)
32
- const { data : recentItems } = hooks . useAccessibleItems (
32
+ const { data : recentItems , isLoading } = hooks . useAccessibleItems (
33
33
// you can move into an item you have at least write permission
34
34
{
35
35
permissions : [ PermissionLevel . Admin , PermissionLevel . Write ] ,
@@ -46,55 +46,69 @@ const RootNavigationTree = ({
46
46
path : items [ 0 ] . path ,
47
47
} ) ;
48
48
49
- return (
50
- < >
51
- < Typography color = "darkgrey" variant = "subtitle2" >
52
- { translateBuilder ( BUILDER . HOME_TITLE ) }
53
- </ Typography >
54
- { rootMenuItems . map ( ( mi ) => (
55
- < RowMenu
56
- key = { mi . name }
57
- item = { mi }
58
- onNavigate = { onNavigate }
59
- selectedId = { selectedId }
60
- onClick = { onClick }
61
- // root items cannot be disabled - but they are disabled by the button
62
- />
63
- ) ) }
64
- { recentFolders && (
65
- < >
66
- < Typography color = "darkgrey" variant = "subtitle2" >
67
- { translateBuilder ( BUILDER . ITEM_SELECTION_NAVIGATION_RECENT_ITEMS ) }
68
- </ Typography >
69
- { recentFolders . map ( ( item ) => (
49
+ if ( recentItems ) {
50
+ return (
51
+ < >
52
+ < Typography color = "darkgrey" variant = "subtitle2" >
53
+ { translateBuilder ( BUILDER . HOME_TITLE ) }
54
+ </ Typography >
55
+ { rootMenuItems . map ( ( mi ) => (
56
+ < RowMenu
57
+ key = { mi . name }
58
+ item = { mi }
59
+ onNavigate = { onNavigate }
60
+ selectedId = { selectedId }
61
+ onClick = { onClick }
62
+ // root items cannot be disabled - but they are disabled by the button
63
+ />
64
+ ) ) }
65
+ { recentFolders && (
66
+ < >
67
+ < Typography color = "darkgrey" variant = "subtitle2" >
68
+ { translateBuilder ( BUILDER . ITEM_SELECTION_NAVIGATION_RECENT_ITEMS ) }
69
+ </ Typography >
70
+ { recentFolders . map ( ( item ) => (
71
+ < RowMenu
72
+ key = { item . name }
73
+ item = { item }
74
+ onNavigate = { onNavigate }
75
+ selectedId = { selectedId }
76
+ onClick = { onClick }
77
+ isDisabled = { isDisabled }
78
+ />
79
+ ) ) }
80
+ </ >
81
+ ) }
82
+ { /* show second parent to allow moving a level above */ }
83
+ { parents && parents . length > 1 && (
84
+ < >
85
+ < Typography color = "darkgrey" variant = "subtitle2" >
86
+ { translateBuilder ( BUILDER . ITEM_SELECTION_NAVIGATION_PARENT ) }
87
+ </ Typography >
70
88
< RowMenu
71
- key = { item . name }
72
- item = { item }
89
+ item = { parents [ parents . length - 2 ] }
73
90
onNavigate = { onNavigate }
74
91
selectedId = { selectedId }
75
92
onClick = { onClick }
76
93
isDisabled = { isDisabled }
77
94
/>
78
- ) ) }
79
- </ >
80
- ) }
81
- { /* show second parent to allow moving a level above */ }
82
- { parents && parents . length > 1 && (
83
- < >
84
- < Typography color = "darkgrey" variant = "subtitle2" >
85
- { translateBuilder ( BUILDER . ITEM_SELECTION_NAVIGATION_PARENT ) }
86
- </ Typography >
87
- < RowMenu
88
- item = { parents [ parents . length - 2 ] }
89
- onNavigate = { onNavigate }
90
- selectedId = { selectedId }
91
- onClick = { onClick }
92
- isDisabled = { isDisabled }
93
- />
94
- </ >
95
- ) }
96
- </ >
97
- ) ;
95
+ </ >
96
+ ) }
97
+ </ >
98
+ ) ;
99
+ }
100
+
101
+ if ( isLoading ) {
102
+ return (
103
+ < >
104
+ < Skeleton height = { 50 } />
105
+ < Skeleton height = { 50 } />
106
+ < Skeleton height = { 50 } />
107
+ </ >
108
+ ) ;
109
+ }
110
+
111
+ return < Alert severity = "error" > An unexpected error happened</ Alert > ;
98
112
} ;
99
113
100
114
export default RootNavigationTree ;
0 commit comments