Commit d89df221 authored by Robert Knight's avatar Robert Knight

Simplify control flow in `groups#load`

Rework the block that fetches the direct-linked annotation's group and
adds it to the featured groups list so that there is only one return
point at the end.
parent a2da80d6
...@@ -230,7 +230,7 @@ function groups( ...@@ -230,7 +230,7 @@ function groups(
}) })
.then(([myGroups, featuredGroups, token, selectedAnn, selectedGroup]) => { .then(([myGroups, featuredGroups, token, selectedAnn, selectedGroup]) => {
// If there is a direct-linked group, add it to the featured groups list. // If there is a direct-linked group, add it to the featured groups list.
const allFeaturedGroups = let allFeaturedGroups =
selectedGroup !== null && selectedGroup !== null &&
!featuredGroups.some(g => g.id === selectedGroup.id) !featuredGroups.some(g => g.id === selectedGroup.id)
? featuredGroups.concat([selectedGroup]) ? featuredGroups.concat([selectedGroup])
...@@ -250,29 +250,24 @@ function groups( ...@@ -250,29 +250,24 @@ function groups(
// If the direct-linked annotation's group has not already been fetched, // If the direct-linked annotation's group has not already been fetched,
// fetch it. // fetch it.
if (!selectedAnnGroup) { if (!selectedAnnGroup) {
return fetchGroup({ const initialFeaturedGroups = allFeaturedGroups;
allFeaturedGroups = fetchGroup({
id: selectedAnn.group, id: selectedAnn.group,
expand: params.expand, expand: params.expand,
}).then(directLinkedAnnGroup => { }).then(directLinkedAnnGroup => {
// If the directLinkedAnnotation's group fetch failed, return // If the directLinkedAnnotation's group fetch failed, return
// the list of groups without it. // the list of groups without it.
if (!directLinkedAnnGroup) { if (!directLinkedAnnGroup) {
return [myGroups, allFeaturedGroups, documentUri, token]; return initialFeaturedGroups;
} }
// If the directLinkedAnnotation's group fetch was successful, // If the directLinkedAnnotation's group fetch was successful,
// combine it with the other groups. // combine it with the other groups.
return [ return initialFeaturedGroups.concat(directLinkedAnnGroup);
myGroups,
allFeaturedGroups.concat(directLinkedAnnGroup),
documentUri,
token,
];
}); });
} }
} }
// If there is no direct-linked annotation, return the list of groups without it. return Promise.all([myGroups, allFeaturedGroups, documentUri, token]);
return [myGroups, allFeaturedGroups, documentUri, token];
}) })
.then(([myGroups, featuredGroups, documentUri, token]) => { .then(([myGroups, featuredGroups, documentUri, token]) => {
const groups = combineGroups(myGroups, featuredGroups, documentUri); const groups = combineGroups(myGroups, featuredGroups, documentUri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment