Show error if could not load space hierarchy (#7399)
parent
144e4c61fc
commit
f389324571
|
@ -477,17 +477,19 @@ export const useRoomHierarchy = (space: Room): {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
rooms: IHierarchyRoom[];
|
rooms: IHierarchyRoom[];
|
||||||
hierarchy: RoomHierarchy;
|
hierarchy: RoomHierarchy;
|
||||||
loadMore(pageSize?: number): Promise <void>;
|
error: Error;
|
||||||
|
loadMore(pageSize?: number): Promise<void>;
|
||||||
} => {
|
} => {
|
||||||
const [rooms, setRooms] = useState<IHierarchyRoom[]>([]);
|
const [rooms, setRooms] = useState<IHierarchyRoom[]>([]);
|
||||||
const [hierarchy, setHierarchy] = useState<RoomHierarchy>();
|
const [hierarchy, setHierarchy] = useState<RoomHierarchy>();
|
||||||
|
const [error, setError] = useState<Error>();
|
||||||
|
|
||||||
const resetHierarchy = useCallback(() => {
|
const resetHierarchy = useCallback(() => {
|
||||||
const hierarchy = new RoomHierarchy(space, INITIAL_PAGE_SIZE);
|
const hierarchy = new RoomHierarchy(space, INITIAL_PAGE_SIZE);
|
||||||
hierarchy.load().then(() => {
|
hierarchy.load().then(() => {
|
||||||
if (space !== hierarchy.root) return; // discard stale results
|
if (space !== hierarchy.root) return; // discard stale results
|
||||||
setRooms(hierarchy.rooms);
|
setRooms(hierarchy.rooms);
|
||||||
});
|
}, setError);
|
||||||
setHierarchy(hierarchy);
|
setHierarchy(hierarchy);
|
||||||
}, [space]);
|
}, [space]);
|
||||||
useEffect(resetHierarchy, [resetHierarchy]);
|
useEffect(resetHierarchy, [resetHierarchy]);
|
||||||
|
@ -501,12 +503,12 @@ export const useRoomHierarchy = (space: Room): {
|
||||||
|
|
||||||
const loadMore = useCallback(async (pageSize?: number) => {
|
const loadMore = useCallback(async (pageSize?: number) => {
|
||||||
if (hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport) return;
|
if (hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport) return;
|
||||||
await hierarchy.load(pageSize);
|
await hierarchy.load(pageSize).catch(setError);
|
||||||
setRooms(hierarchy.rooms);
|
setRooms(hierarchy.rooms);
|
||||||
}, [hierarchy]);
|
}, [hierarchy]);
|
||||||
|
|
||||||
const loading = hierarchy?.loading ?? true;
|
const loading = hierarchy?.loading ?? true;
|
||||||
return { loading, rooms, hierarchy, loadMore };
|
return { loading, rooms, hierarchy, loadMore, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
const useIntersectionObserver = (callback: () => void) => {
|
const useIntersectionObserver = (callback: () => void) => {
|
||||||
|
@ -649,7 +651,7 @@ const SpaceHierarchy = ({
|
||||||
|
|
||||||
const [selected, setSelected] = useState(new Map<string, Set<string>>()); // Map<parentId, Set<childId>>
|
const [selected, setSelected] = useState(new Map<string, Set<string>>()); // Map<parentId, Set<childId>>
|
||||||
|
|
||||||
const { loading, rooms, hierarchy, loadMore } = useRoomHierarchy(space);
|
const { loading, rooms, hierarchy, loadMore, error: hierarchyError } = useRoomHierarchy(space);
|
||||||
|
|
||||||
const filteredRoomSet = useMemo<Set<IHierarchyRoom>>(() => {
|
const filteredRoomSet = useMemo<Set<IHierarchyRoom>>(() => {
|
||||||
if (!rooms?.length) return new Set();
|
if (!rooms?.length) return new Set();
|
||||||
|
@ -677,6 +679,10 @@ const SpaceHierarchy = ({
|
||||||
}, [rooms, hierarchy, query]);
|
}, [rooms, hierarchy, query]);
|
||||||
|
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
let errorText = error;
|
||||||
|
if (!error && hierarchyError) {
|
||||||
|
errorText = _t("Failed to load list of rooms.");
|
||||||
|
}
|
||||||
|
|
||||||
const loaderRef = useIntersectionObserver(loadMore);
|
const loaderRef = useIntersectionObserver(loadMore);
|
||||||
|
|
||||||
|
@ -759,8 +765,8 @@ const SpaceHierarchy = ({
|
||||||
) }
|
) }
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{ error && <div className="mx_SpaceHierarchy_error">
|
{ errorText && <div className="mx_SpaceHierarchy_error">
|
||||||
{ error }
|
{ errorText }
|
||||||
</div> }
|
</div> }
|
||||||
<ul
|
<ul
|
||||||
className="mx_SpaceHierarchy_list"
|
className="mx_SpaceHierarchy_list"
|
||||||
|
|
|
@ -3077,6 +3077,7 @@
|
||||||
"Removing...": "Removing...",
|
"Removing...": "Removing...",
|
||||||
"Mark as not suggested": "Mark as not suggested",
|
"Mark as not suggested": "Mark as not suggested",
|
||||||
"Mark as suggested": "Mark as suggested",
|
"Mark as suggested": "Mark as suggested",
|
||||||
|
"Failed to load list of rooms.": "Failed to load list of rooms.",
|
||||||
"Your server does not support showing space hierarchies.": "Your server does not support showing space hierarchies.",
|
"Your server does not support showing space hierarchies.": "Your server does not support showing space hierarchies.",
|
||||||
"No results found": "No results found",
|
"No results found": "No results found",
|
||||||
"You may want to try a different search or check for typos.": "You may want to try a different search or check for typos.",
|
"You may want to try a different search or check for typos.": "You may want to try a different search or check for typos.",
|
||||||
|
|
Loading…
Reference in New Issue