@indietabletop/appkit 7.0.0 → 7.2.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AuthCard/AuthCard.tsx +35 -11
- package/lib/ShareButton/ShareButton.tsx +6 -1
- package/lib/store/store.ts +36 -8
- package/package.json +1 -1
|
@@ -6,19 +6,25 @@ import { IndieTabletopClubLogo } from "../IndieTabletopClubLogo.tsx";
|
|
|
6
6
|
import { LetterheadParagraph } from "../Letterhead/index.tsx";
|
|
7
7
|
import { button } from "../Letterhead/style.css.ts";
|
|
8
8
|
import { MiddotSeparated } from "../MiddotSeparated/MiddotSeparated.tsx";
|
|
9
|
+
import { useAppActions, useCurrentUser } from "../store/index.tsx";
|
|
9
10
|
import type { CurrentUser } from "../types.ts";
|
|
10
11
|
import { card } from "./style.css.ts";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* Primarily intended to be used within the sidenav.
|
|
14
|
+
* @deprecated Use {@link AuthCardV2}
|
|
16
15
|
*/
|
|
17
16
|
export function AuthCard(props: {
|
|
18
17
|
onLogout: () => void;
|
|
19
18
|
currentUser: CurrentUser | null;
|
|
19
|
+
description?: string;
|
|
20
20
|
}) {
|
|
21
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
currentUser,
|
|
23
|
+
onLogout,
|
|
24
|
+
|
|
25
|
+
// Remove this default once AuthCard v1 is migrated away.
|
|
26
|
+
description = "Enable backup & sync, access your pledge data, and more!",
|
|
27
|
+
} = props;
|
|
22
28
|
const { hrefs } = useAppConfig();
|
|
23
29
|
const align = !currentUser ? "center" : "start";
|
|
24
30
|
|
|
@@ -26,7 +32,7 @@ export function AuthCard(props: {
|
|
|
26
32
|
<div className={card.container({ align })}>
|
|
27
33
|
<IndieTabletopClubLogo className={card.logo({ align })} />
|
|
28
34
|
|
|
29
|
-
{currentUser ?
|
|
35
|
+
{currentUser ?
|
|
30
36
|
<>
|
|
31
37
|
<LetterheadParagraph>{currentUser.email}</LetterheadParagraph>
|
|
32
38
|
|
|
@@ -40,11 +46,8 @@ export function AuthCard(props: {
|
|
|
40
46
|
</Button>
|
|
41
47
|
</MiddotSeparated>
|
|
42
48
|
</>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
<LetterheadParagraph size="small">
|
|
46
|
-
Enable backup & sync, access your pledge data, and more!
|
|
47
|
-
</LetterheadParagraph>
|
|
49
|
+
: <>
|
|
50
|
+
<LetterheadParagraph size="small">{description}</LetterheadParagraph>
|
|
48
51
|
|
|
49
52
|
<Link href={hrefs.join()} className={button()}>
|
|
50
53
|
Join
|
|
@@ -58,7 +61,28 @@ export function AuthCard(props: {
|
|
|
58
61
|
{"."}
|
|
59
62
|
</LetterheadParagraph>
|
|
60
63
|
</>
|
|
61
|
-
|
|
64
|
+
}
|
|
62
65
|
</div>
|
|
63
66
|
);
|
|
64
67
|
}
|
|
68
|
+
|
|
69
|
+
export type AuthCardProps = {
|
|
70
|
+
/**
|
|
71
|
+
* A short description that explains why users should log in or join.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* "Enable backup & sync, access your pledge data, and more!"
|
|
75
|
+
*/
|
|
76
|
+
description: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Small, ITC-branded card that shows authentication status.
|
|
81
|
+
*
|
|
82
|
+
* Primarily intended to be used within the sidenav.
|
|
83
|
+
*/
|
|
84
|
+
export function AuthCardV2(props: AuthCardProps) {
|
|
85
|
+
const currentUser = useCurrentUser();
|
|
86
|
+
const { logout } = useAppActions();
|
|
87
|
+
return <AuthCard {...props} currentUser={currentUser} onLogout={logout} />;
|
|
88
|
+
}
|
|
@@ -2,7 +2,10 @@ import { Button, type ButtonProps } from "@ariakit/react";
|
|
|
2
2
|
import { useState, type ReactNode } from "react";
|
|
3
3
|
import { useRevertingState } from "../use-reverting-state.ts";
|
|
4
4
|
|
|
5
|
-
type AriakitButtonProps = Omit<
|
|
5
|
+
type AriakitButtonProps = Omit<
|
|
6
|
+
ButtonProps,
|
|
7
|
+
"children" | "onClick" | "value" | "type"
|
|
8
|
+
>;
|
|
6
9
|
|
|
7
10
|
export type CopyToClipboardButtonProps = AriakitButtonProps & {
|
|
8
11
|
value: string | null;
|
|
@@ -20,6 +23,7 @@ export function CopyToClipboardButton(props: CopyToClipboardButtonProps) {
|
|
|
20
23
|
<Button
|
|
21
24
|
{...buttonProps}
|
|
22
25
|
disabled={disabled || !value}
|
|
26
|
+
type="button"
|
|
23
27
|
onClick={async () => {
|
|
24
28
|
if (value) {
|
|
25
29
|
await navigator.clipboard.writeText(value);
|
|
@@ -54,6 +58,7 @@ export function WebShareButton(props: WebShareButtonProps) {
|
|
|
54
58
|
<Button
|
|
55
59
|
{...buttonProps}
|
|
56
60
|
disabled={disabled || !shareData || sharing}
|
|
61
|
+
type="button"
|
|
57
62
|
onClick={async () => {
|
|
58
63
|
if (shareData) {
|
|
59
64
|
try {
|
package/lib/store/store.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { number } from "superstruct";
|
|
1
|
+
import { nullable, number, object } from "superstruct";
|
|
2
2
|
import {
|
|
3
3
|
and,
|
|
4
4
|
assertEvent,
|
|
@@ -28,10 +28,17 @@ const safeStorage = createSafeStorage({
|
|
|
28
28
|
lastSuccessfulSyncTs: number(),
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const legacyStorage = createSafeStorage({
|
|
32
|
+
store: object({
|
|
33
|
+
currentUser: nullable(currentUser()),
|
|
34
|
+
sessionInfo: nullable(sessionInfo()),
|
|
35
|
+
lastSuccessfulSyncTs: nullable(number()),
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
type MemoryContext = Omit<MachineContext, SafeStorageKey<typeof safeStorage>>;
|
|
40
|
+
|
|
41
|
+
function createInMemoryContext(): MemoryContext {
|
|
35
42
|
return {
|
|
36
43
|
currentSync: null,
|
|
37
44
|
pushOnceIdle: false,
|
|
@@ -39,12 +46,33 @@ function createInMemoryContext(): Omit<
|
|
|
39
46
|
};
|
|
40
47
|
}
|
|
41
48
|
|
|
49
|
+
type PersistedContext = Pick<
|
|
50
|
+
MachineContext,
|
|
51
|
+
SafeStorageKey<typeof safeStorage>
|
|
52
|
+
>;
|
|
53
|
+
|
|
54
|
+
function getPersistedContext(): PersistedContext {
|
|
55
|
+
// Legacy store was used in the Hobgoblin app.
|
|
56
|
+
const legacyStore = legacyStorage.getItem("store");
|
|
57
|
+
|
|
58
|
+
// If legacy store existed in localStorage, we make sure to clean it up.
|
|
59
|
+
if (legacyStore) {
|
|
60
|
+
legacyStorage.clear();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
currentUser: legacyStore?.currentUser ?? safeStorage.getItem("currentUser"),
|
|
65
|
+
sessionInfo: legacyStore?.sessionInfo ?? safeStorage.getItem("sessionInfo"),
|
|
66
|
+
lastSuccessfulSyncTs:
|
|
67
|
+
legacyStore?.lastSuccessfulSyncTs ??
|
|
68
|
+
safeStorage.getItem("lastSuccessfulSyncTs"),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
42
72
|
function createInitialContext(): MachineContext {
|
|
43
73
|
return {
|
|
44
74
|
...createInMemoryContext(),
|
|
45
|
-
|
|
46
|
-
sessionInfo: safeStorage.getItem("sessionInfo"),
|
|
47
|
-
lastSuccessfulSyncTs: safeStorage.getItem("lastSuccessfulSyncTs"),
|
|
75
|
+
...getPersistedContext(),
|
|
48
76
|
};
|
|
49
77
|
}
|
|
50
78
|
|