Skip to content

Commit

Permalink
Merge pull request #51 from scaife-viewer/201-library-race
Browse files Browse the repository at this point in the history
Handle any race condition on loading library widget
  • Loading branch information
jacobwegner authored Jul 31, 2020
2 parents b5a7209 + 0520b73 commit 76e22f3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/reader/widgets/ReaderWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:query="query"
:variables="queryVariables"
:update="queryUpdate"
:skip="urn === null"
>
<template v-slot="{ result: { data } }">
<Paginator :urn="data && data.previous" direction="left" />
Expand Down Expand Up @@ -42,6 +43,9 @@
scaifeConfig: {},
methods: {
setVersionMetadata() {
if (this.urn === null) {
return;
}
this.$store.dispatch(
UPDATE_METADATA,
{ urn: this.urn.version },
Expand Down Expand Up @@ -92,7 +96,7 @@
},
});
}
if (this.version !== this.urn.version) {
if (this.urn && this.version !== this.urn.version) {
this.setVersionMetadata();
}
},
Expand All @@ -117,7 +121,7 @@
`;
},
queryVariables() {
return { urn: this.urn.absolute };
return { urn: this.urn === null ? '' : this.urn.absolute };
},
displayMode() {
return this.$store.state.displayMode;
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/AudioWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
.map(e => e.node.audioAnnotations.edges.map(a => a.node))
.flat();
},
skip() {
return this.urn === null;
},
},
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/LibraryWidget/LibraryWidget.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<div class="library-widget u-widget u-flex">
<ul class="node-tree root" v-if="libraryTree">
<Node v-for="(node, index) in libraryTree" :key="index" :node="node" />
<LoaderBall v-if="$apolloData.queries.libraryTree.loading" />
<ul class="node-tree root" v-else-if="libraryTree">
<Node v-for="node in libraryTree" :key="node.data.urn" :node="node" />
</ul>
</div>
</template>
Expand All @@ -21,7 +22,6 @@
}
}
`,
// transform response before setting as `data.libraryTree`
update(data) {
const nid = data.tree.tree[0];
return nid.children.reduce((a, b) => {
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/LibraryWidget/Node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
},
computed: {
highlight() {
return this.readerUrn.version === this.urn;
return this.readerUrn && this.readerUrn.version === this.urn;
},
nodeUrnIndex() {
return this.readerUrn.absolute.indexOf(
return this.readerUrn && this.readerUrn.absolute.indexOf(
this.urn.slice(0, this.urn.length - 1), // trim trailing colon
);
},
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/NamedEntitiesWidget/NamedEntitiesWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
data() {
return {
entities: [],
filteredEntities: [],
};
},
Expand Down Expand Up @@ -102,6 +103,9 @@
update(data) {
return data.namedEntities.edges.map(e => e.node);
},
skip() {
return this.urn === null;
},
},
},
};
Expand Down
10 changes: 6 additions & 4 deletions src/widgets/NewAlexandriaWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
// special-case handling for the Folios version of
// the Iliad
return (
this.originalPassage.version ===
'urn:cts:greekLit:tlg0012.tlg001.msA-folios:'
this.originalPassage && this.originalPassage.version ===
'urn:cts:greekLit:tlg0012.tlg001.msA-folios:'
);
},
originalPassage() {
Expand All @@ -53,7 +53,7 @@
handler() {
if (this.needsHealing) {
this.healFolioURN();
} else {
} else if (this.originalPassage) {
this.healedPassage = this.originalPassage.toString();
}
},
Expand Down Expand Up @@ -100,6 +100,9 @@
fetchPassageTextParts() {
// retrieves the lowest text parts for a folio level reference,
// e.g. 12r --> 12r.1.1-12.r.1.25
if (this.originalPassage === null) {
return;
}
const query = gql`
{
passageTextParts(
Expand All @@ -120,7 +123,6 @@
return node;
});
});
return query;
},
extractPassageTextPartRefs() {
// extracts the ref(s) from the text parts
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/ScholiaWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
};
});
},
skip() {
return this.urn === null;
},
},
},
};
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/TokenAnnotationWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
update(data) {
return data.passageTextParts.edges.map(line => line.node);
},
skip() {
return this.urn === null;
},
},
},
};
Expand Down

0 comments on commit 76e22f3

Please sign in to comment.