Skip to content

Commit fa4d872

Browse files
authored
Merge pull request #980 from manifoldco/dangodev/wait-for-auth
use waitForAuth on resource components
2 parents 1b59da3 + 4483e5d commit fa4d872

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
66
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [0.9.8] - 2020-03-30
99

1010
### Fixed
1111

@@ -543,7 +543,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
543543
- Changed the `manifold-resource-credentials` component to use the standalone `manifold-credentials`
544544
component.
545545

546-
[unreleased]: https://github.com/manifoldco/ui/compare/v0.9.7...HEAD
546+
[0.9.8]: https://github.com/manifoldco/ui/compare/v0.9.7...v0.9.8
547547
[0.9.7]: https://github.com/manifoldco/ui/compare/v0.9.6...v0.9.7
548548
[0.9.6]: https://github.com/manifoldco/ui/compare/v0.9.5...v0.9.6
549549
[0.9.5]: https://github.com/manifoldco/ui/compare/v0.9.4...v0.9.5

src/components/manifold-data-resource-list/manifold-data-resource-list.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { h, Component, Prop, State, Event, EventEmitter, Element } from '@stencil/core';
22

33
import { connection } from '../../global/app';
4+
import { waitForAuthToken } from '../../utils/auth';
45
import logger, { loadMark } from '../../utils/logger';
56
import fetchAllPages from '../../utils/fetchAllPages';
67
import { GraphqlFetch } from '../../utils/graphqlFetch';
@@ -38,7 +39,17 @@ export class ManifoldDataResourceList {
3839
@Event({ eventName: 'manifold-resourceList-click', bubbles: true }) clickEvent: EventEmitter;
3940

4041
@loadMark()
41-
componentWillLoad() {
42+
async componentWillLoad() {
43+
// if auth token missing, wait
44+
if (!connection.getAuthToken()) {
45+
await waitForAuthToken(
46+
() => connection.authToken,
47+
connection.waitTime,
48+
() => Promise.resolve()
49+
);
50+
}
51+
52+
// start polling
4253
this.fetchResources();
4354
if (!this.paused) {
4455
this.interval = window.setInterval(() => this.fetchResources(), 3000);

src/components/manifold-resource-container/manifold-resource-container.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { h, Element, Component, Prop, State, Watch, Event, EventEmitter } from '
22

33
import ResourceTunnel from '../../data/resource';
44
import { connection } from '../../global/app';
5+
import { waitForAuthToken } from '../../utils/auth';
56
import logger, { loadMark } from '../../utils/logger';
67
import {
78
ResourceStatusLabel,
@@ -42,7 +43,17 @@ export class ManifoldResourceContainer {
4243
}
4344

4445
@loadMark()
45-
componentWillLoad() {
46+
async componentWillLoad() {
47+
// if auth token missing, wait
48+
if (!connection.getAuthToken()) {
49+
await waitForAuthToken(
50+
() => connection.authToken,
51+
connection.waitTime,
52+
() => Promise.resolve()
53+
);
54+
}
55+
56+
// fetch initial resource
4657
this.fetchResource(this.resourceLabel);
4758
}
4859

@@ -55,11 +66,6 @@ export class ManifoldResourceContainer {
5566
return;
5667
}
5768

58-
// for this component, wait for auth before fetching
59-
if (!connection.getAuthToken()) {
60-
return;
61-
}
62-
6369
const variables: ResourceWithOwnerQueryVariables = { resourceLabel, owner: this.ownerId };
6470
const { data, errors } = await this.graphqlFetch<ResourceWithOwnerQuery>({
6571
query: queryWithOwner,

src/components/manifold-resource-list/manifold-resource-list.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { h, Component, Prop, State, Element, Watch } from '@stencil/core';
22

33
import { GraphqlFetch } from '../../utils/graphqlFetch';
44
import { connection } from '../../global/app';
5+
import { waitForAuthToken } from '../../utils/auth';
56
import logger, { loadMark } from '../../utils/logger';
67
import queryWithOwner from './resources-with-owner.graphql';
78
import { Query, ResourceEdge, Resources_With_OwnerQueryVariables } from '../../types/graphql';
@@ -36,7 +37,17 @@ export class ManifoldResourceList {
3637
}
3738

3839
@loadMark()
39-
componentWillLoad() {
40+
async componentWillLoad() {
41+
// if auth token missing, wait
42+
if (!connection.getAuthToken()) {
43+
await waitForAuthToken(
44+
() => connection.authToken,
45+
connection.waitTime,
46+
() => Promise.resolve()
47+
);
48+
}
49+
50+
// start polling
4051
this.fetchResources();
4152
if (!this.paused) {
4253
this.interval = window.setInterval(() => this.fetchResources(), 3000);
@@ -54,11 +65,6 @@ export class ManifoldResourceList {
5465
return;
5566
}
5667

57-
// for this component, wait for auth before fetching
58-
if (!connection.getAuthToken()) {
59-
return;
60-
}
61-
6268
const variables: Resources_With_OwnerQueryVariables = {
6369
first: 50,
6470
after: '',

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export async function ensureAuthToken() {
88
return connection.authToken;
99
}
1010

11-
await waitForAuthToken(() => connection.authToken, connection.waitTime, Promise.resolve);
11+
await waitForAuthToken(
12+
() => connection.authToken,
13+
connection.waitTime,
14+
() => Promise.resolve()
15+
);
1216

1317
return connection.authToken;
1418
}

0 commit comments

Comments
 (0)