Skip to content

Commit d4cd919

Browse files
authored
Polish sidebar update and relay cards (#1009)
1 parent 1a37ee3 commit d4cd919

37 files changed

Lines changed: 2078 additions & 333 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default defineConfig({
6262
"**/integration.spec.ts",
6363
"**/profile.spec.ts",
6464
"**/sidebar.spec.ts",
65+
"**/sidebar-relay-card.spec.ts",
6566
"**/tokens.spec.ts",
6667
"**/persona-env-vars.spec.ts",
6768
"**/mesh-compute.spec.ts",

‎desktop/public/pow/LICENSE.txt‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Emerge Tools, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎desktop/public/pow/plop.m4a‎

16.9 KB
Binary file not shown.
20.7 KB
Loading
26.7 KB
Loading
32.1 KB
Loading
19 KB
Loading
8.83 KB
Loading

‎desktop/src/app/AppShell.tsx‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ export function AppShell() {
219219
const channelsQuery = useChannelsQuery();
220220
const { refetch: refetchChannels } = channelsQuery;
221221
const channels = channelsQuery.data ?? [];
222+
const channelsErrorMessage =
223+
channelsQuery.error instanceof Error
224+
? channelsQuery.error.message
225+
: undefined;
222226
const memberChannels = React.useMemo(
223227
() => channels.filter((channel) => channel.isMember),
224228
[channels],
@@ -775,11 +779,7 @@ export function AppShell() {
775779
activeWorkspace={workspacesHook.activeWorkspace}
776780
channels={sidebarChannels}
777781
currentPubkey={identityQuery.data?.pubkey}
778-
errorMessage={
779-
channelsQuery.error instanceof Error
780-
? channelsQuery.error.message
781-
: undefined
782-
}
782+
errorMessage={channelsErrorMessage}
783783
fallbackDisplayName={identityQuery.data?.displayName}
784784
homeBadgeCount={homeBadgeCount}
785785
isAddWorkspaceOpen={isAddWorkspaceOpen}
@@ -911,7 +911,9 @@ export function AppShell() {
911911
className="min-h-0 min-w-0 overflow-hidden"
912912
style={chromeCssVarDefaults}
913913
>
914-
<ConnectionBanner />
914+
<ConnectionBanner
915+
errorMessage={channelsErrorMessage}
916+
/>
915917
<Outlet />
916918
</SidebarInset>
917919
</MainInsetProvider>

‎desktop/src/features/onboarding/ui/ProfileStep.tsx‎

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as React from "react";
2+
import { toast } from "sonner";
23

4+
import { SidebarRelayConnectionCompactCard } from "@/features/sidebar/ui/SidebarRelayConnectionCard";
5+
import { useReconnectRelay } from "@/shared/api/useReconnectRelay";
36
import { cn } from "@/shared/lib/cn";
7+
import { isRelayUnreachableError } from "@/shared/lib/relayError";
48
import { Button } from "@/shared/ui/button";
59
import { Spinner } from "@/shared/ui/spinner";
610
import {
@@ -17,11 +21,131 @@ type ProfileStepProps = {
1721
state: ProfileStepState;
1822
};
1923

20-
function ErrorBanner({ message }: { message: string | null }) {
24+
const ONBOARDING_CONNECTIVITY_SUCCESS_AUTO_DISMISS_MS = 2_500;
25+
26+
function OnboardingRelayConnectionErrorCard({
27+
isSaving,
28+
message,
29+
}: {
30+
isSaving: boolean;
31+
message: string;
32+
}) {
33+
const { isPending: isReconnectPending, reconnect } = useReconnectRelay();
34+
const [dismissedErrorMessage, setDismissedErrorMessage] = React.useState<
35+
string | null
36+
>(null);
37+
const [isReconnectActionPending, setIsReconnectActionPending] =
38+
React.useState(false);
39+
const [hasSuccess, setHasSuccess] = React.useState(false);
40+
const reconnectActionPendingRef = React.useRef(false);
41+
const successTimeoutRef = React.useRef<number | null>(null);
42+
const wasSavingRef = React.useRef(isSaving);
43+
const isActionPending = isReconnectActionPending || isReconnectPending;
44+
45+
React.useEffect(() => {
46+
return () => {
47+
if (successTimeoutRef.current !== null) {
48+
window.clearTimeout(successTimeoutRef.current);
49+
}
50+
};
51+
}, []);
52+
53+
React.useEffect(() => {
54+
if (isSaving && !wasSavingRef.current) {
55+
if (successTimeoutRef.current !== null) {
56+
window.clearTimeout(successTimeoutRef.current);
57+
successTimeoutRef.current = null;
58+
}
59+
setDismissedErrorMessage(null);
60+
setHasSuccess(false);
61+
}
62+
wasSavingRef.current = isSaving;
63+
}, [isSaving]);
64+
65+
const markSuccess = React.useCallback(() => {
66+
setHasSuccess(true);
67+
if (successTimeoutRef.current !== null) {
68+
window.clearTimeout(successTimeoutRef.current);
69+
}
70+
successTimeoutRef.current = window.setTimeout(() => {
71+
successTimeoutRef.current = null;
72+
setDismissedErrorMessage(message);
73+
}, ONBOARDING_CONNECTIVITY_SUCCESS_AUTO_DISMISS_MS);
74+
}, [message]);
75+
76+
const runConnectivityAction = React.useCallback(
77+
(runAction: () => Promise<boolean | undefined>) => {
78+
if (reconnectActionPendingRef.current) {
79+
return;
80+
}
81+
82+
reconnectActionPendingRef.current = true;
83+
setIsReconnectActionPending(true);
84+
setHasSuccess(false);
85+
void Promise.resolve()
86+
.then(runAction)
87+
.then((didReconnect) => {
88+
if (didReconnect !== false) {
89+
markSuccess();
90+
}
91+
})
92+
.catch((error) => {
93+
const detail = error instanceof Error ? error.message : String(error);
94+
toast.error(`Could not reconnect to the relay. ${detail}`);
95+
})
96+
.finally(() => {
97+
reconnectActionPendingRef.current = false;
98+
setIsReconnectActionPending(false);
99+
});
100+
},
101+
[markSuccess],
102+
);
103+
104+
const handleReconnectRelay = React.useCallback(() => {
105+
runConnectivityAction(reconnect);
106+
}, [reconnect, runConnectivityAction]);
107+
108+
if (dismissedErrorMessage === message) {
109+
return null;
110+
}
111+
112+
return (
113+
<div className="fixed bottom-4 left-4 z-50 w-[calc(100vw-2rem)] text-left sm:bottom-6 sm:left-6 sm:w-[22rem]">
114+
<SidebarRelayConnectionCompactCard
115+
actionTestId="onboarding-reconnect-relay"
116+
isActionDisabled={isActionPending}
117+
isConnected={hasSuccess}
118+
isReconnectPending={isActionPending}
119+
onDismiss={() => setDismissedErrorMessage(message)}
120+
onReconnect={handleReconnectRelay}
121+
surface="secondary"
122+
testId="onboarding-relay-reconnect-card"
123+
/>
124+
</div>
125+
);
126+
}
127+
128+
function ErrorBanner({
129+
isSaving,
130+
message,
131+
}: {
132+
isSaving: boolean;
133+
message: string | null;
134+
}) {
21135
if (!message) {
22136
return null;
23137
}
24138

139+
if (isRelayUnreachableError(message)) {
140+
return (
141+
<OnboardingRelayConnectionErrorCard
142+
isSaving={isSaving}
143+
key={message}
144+
message={message}
145+
/>
146+
);
147+
}
148+
25149
return (
26150
<p className="mt-4 rounded-md border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive">
27151
{message}
@@ -117,7 +241,7 @@ export function ProfileStep({
117241
</label>
118242

119243
{saveRecovery.errorMessage ? (
120-
<ErrorBanner message={saveRecovery.errorMessage} />
244+
<ErrorBanner isSaving={isSaving} message={saveRecovery.errorMessage} />
121245
) : null}
122246

123247
<div className="mt-12 flex w-full max-w-[500px] flex-col gap-3">

0 commit comments

Comments
 (0)