Skip to content

Commit 3378ae7

Browse files
Add loading state while seam API is requested (#242)
1 parent 8b2e218 commit 3378ae7

14 files changed

+292
-23
lines changed

lib/interact-for-access-code.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
33
import { interactForDevice } from "./interact-for-device"
4+
import { withLoading } from "./util/with-loading"
45

56
export const interactForAccessCode = async ({
67
device_id,
@@ -13,9 +14,11 @@ export const interactForAccessCode = async ({
1314
device_id = await interactForDevice()
1415
}
1516

16-
const accessCodes = await seam.accessCodes.list({
17-
device_id,
18-
})
17+
const accessCodes = await withLoading("Fetching access codes...", () =>
18+
seam.accessCodes.list({
19+
device_id,
20+
})
21+
)
1922

2023
const { accessCodeId } = await prompts({
2124
name: "accessCodeId",

lib/interact-for-acs-entrance.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
3+
import { withLoading } from "./util/with-loading"
34

45
export const interactForAcsEntrance = async () => {
56
const seam = await getSeam()
67

7-
const entrances = await seam.acs.entrances.list()
8+
const entrances = await withLoading("Fetching ACS entrances...", () =>
9+
seam.acs.entrances.list()
10+
)
811

912
const { acsEntranceId } = await prompts({
1013
name: "acsEntranceId",

lib/interact-for-acs-system.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
3+
import { withLoading } from "./util/with-loading"
34

45
export const interactForAcsSystem = async (message?: string) => {
56
const seam = await getSeam()
67

7-
const systems = await seam.acs.systems.list()
8+
const systems = await withLoading("Fetching ACS systems...", () =>
9+
seam.acs.systems.list()
10+
)
811

912
const { acsSystemId } = await prompts({
1013
name: "acsSystemId",

lib/interact-for-acs-user.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
33
import { interactForAcsSystem } from "./interact-for-acs-system"
4+
import { withLoading } from "./util/with-loading"
45

56
export const interactForAcsUser = async () => {
67
const seam = await getSeam()
@@ -9,9 +10,11 @@ export const interactForAcsUser = async () => {
910
"What acs_system does the acs_user belong to?"
1011
)
1112

12-
const users = await seam.acs.users.list({
13-
acs_system_id,
14-
})
13+
const users = await withLoading("Fetching ACS users...", () =>
14+
seam.acs.users.list({
15+
acs_system_id,
16+
})
17+
)
1518

1619
const { acsUserId } = await prompts({
1720
name: "acsUserId",

lib/interact-for-action-attempt-poll.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
33
import { ActionAttemptsGetResponse } from "@seamapi/http/connect"
4+
import { withLoading } from "./util/with-loading"
45

56
export const interactForActionAttemptPoll = async (
67
action_attempt: ActionAttemptsGetResponse["action_attempt"]
@@ -19,9 +20,13 @@ export const interactForActionAttemptPoll = async (
1920
const seam = await getSeam()
2021
const { action_attempt_id } = action_attempt
2122

22-
const updated_action_attempt = await seam.actionAttempts.get(
23-
{ action_attempt_id },
24-
{ waitForActionAttempt: { pollingInterval: 240, timeout: 10_000 } }
23+
const updated_action_attempt = await withLoading(
24+
"Polling action attempt...",
25+
() =>
26+
seam.actionAttempts.get(
27+
{ action_attempt_id },
28+
{ waitForActionAttempt: { pollingInterval: 240, timeout: 10_000 } }
29+
)
2530
)
2631

2732
console.dir(updated_action_attempt, { depth: null })

lib/interact-for-connected-account.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
33
import { getConfigStore } from "./get-config-store"
4+
import { withLoading } from "./util/with-loading"
45
export const interactForConnectedAccount = async () => {
56
const seam = await getSeam()
67

7-
const connected_accounts = await seam.connectedAccounts.list()
8+
const connected_accounts = await withLoading(
9+
"Fetching connected accounts...",
10+
() => seam.connectedAccounts.list()
11+
)
812

913
const { connectedAccountId } = await prompts({
1014
name: "connectedAccountId",

lib/interact-for-credential-pool.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
33
import { interactForAcsSystem } from "./interact-for-acs-system"
4+
import { withLoading } from "./util/with-loading"
45

56
export const interactForCredentialPool = async () => {
67
const seam = await getSeam()
@@ -9,9 +10,13 @@ export const interactForCredentialPool = async () => {
910
"What acs_system does the credential pool belong to?"
1011
)
1112

12-
const credentialPools = await seam.acs.credentialPools.list({
13-
acs_system_id,
14-
})
13+
const credentialPools = await withLoading(
14+
"Fetching ACS credential pools...",
15+
() =>
16+
seam.acs.credentialPools.list({
17+
acs_system_id,
18+
})
19+
)
1520

1621
const { credentialPoolId } = await prompts({
1722
name: "credentialPoolId",

lib/interact-for-device.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
33
import { getConfigStore } from "./get-config-store"
4+
import { withLoading } from "./util/with-loading"
45
export const interactForDevice = async () => {
56
const seam = await getSeam()
67

7-
const devices = await seam.devices.list()
8+
const devices = await withLoading("Fetching devices...", () =>
9+
seam.devices.list()
10+
)
811

912
const { deviceId } = await prompts({
1013
name: "deviceId",

lib/interact-for-user-identity.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import prompts from "prompts"
22
import { getSeam } from "./get-seam"
3+
import { withLoading } from "./util/with-loading"
34

45
export const interactForUserIdentity = async () => {
56
const seam = await getSeam()
67

7-
const uis = await seam.userIdentities.list()
8+
const uis = await withLoading("Fetching user identities...", () =>
9+
seam.userIdentities.list()
10+
)
811

912
const { userIdentityId } = await prompts({
1013
name: "userIdentityId",

lib/interact-for-workspace-id.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { getConfigStore } from "./get-config-store"
22
import prompts from "prompts"
33
import { getSeam, getSeamMultiWorkspace } from "./get-seam"
4+
import { withLoading } from "./util/with-loading"
45

56
export const interactForWorkspaceId = async () => {
67
const config = getConfigStore()
78
const seam = await getSeamMultiWorkspace()
89

9-
const workspaces = await seam.workspaces.list()
10+
const workspaces = await withLoading("Fetching workspaces...", () =>
11+
seam.workspaces.list()
12+
)
1013

1114
const { workspaceId } = await prompts({
1215
name: "workspaceId",

0 commit comments

Comments
 (0)