Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Restore Space posting toasts and refine toast controls

Anand Baburajane840d7da419e
diff --git a/web/apps/space/src/components/ActionToast.tsx b/web/apps/space/src/components/ActionToast.tsx
index 6746661913..6e9c6fc90a 100644
--- a/web/apps/space/src/components/ActionToast.tsx
+++ b/web/apps/space/src/components/ActionToast.tsx
@@ -8,7 +8,7 @@ import { spaceTouchTargetSize } from "styles/touch-targets";
const green = "#08C225";
const textBase = spaceText;
-const toastHorizontalPadding = "12px";
+const toastHorizontalPadding = "16px";
export const spaceToastAutoDismissDurationMs = 1800;
const toastEnter = keyframes`
from {
@@ -89,11 +89,11 @@ export const SpaceActionToast: React.FC<SpaceActionToastProps> = ({
fontWeight: 650,
gap: "10px",
lineHeight: "20px",
- minHeight: 50,
+ minHeight: spaceTouchTargetSize,
pointerEvents: "auto",
pl: "10px",
pr: showCloseButton ? "6px" : "14px",
- py: "3px",
+ py: 0,
width: "100%",
}}
>
diff --git a/web/apps/space/src/components/PWAInstallPrompt.tsx b/web/apps/space/src/components/PWAInstallPrompt.tsx
index 7655d16170..6580a1d970 100644
--- a/web/apps/space/src/components/PWAInstallPrompt.tsx
+++ b/web/apps/space/src/components/PWAInstallPrompt.tsx
@@ -16,12 +16,11 @@ import { SpaceNotificationPermissionInstructions } from "components/Notification
import { useSpacePWAInstallPrompt } from "hooks/use-pwa-install-prompt";
import { useSpaceWebPushPrompt } from "hooks/use-web-push-prompt";
import React from "react";
+import { spaceToastActionButtonSx } from "styles/buttons";
import {
- spaceAppBackgroundColor,
spaceDialogBackground,
spaceOnAccent,
spaceSurface,
- spaceSurfaceHover,
spaceText,
spaceTextMuted,
} from "styles/colors";
@@ -209,7 +208,7 @@ export const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({
: undefined,
boxSizing: "border-box",
left: "50%",
- px: "12px",
+ px: "16px",
pointerEvents: "none",
position: "fixed",
top:
@@ -243,11 +242,11 @@ export const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({
fontWeight: 650,
gap: "10px",
lineHeight: "20px",
- minHeight: 50,
+ minHeight: spaceTouchTargetSize,
pointerEvents: hidden ? "none" : "auto",
pl: "10px",
pr: "6px",
- py: "3px",
+ py: 0,
width: "100%",
}}
>
@@ -284,33 +283,7 @@ export const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({
type="button"
disabled={actionDisabled}
onClick={onAction}
- sx={{
- alignItems: "center",
- bgcolor: "#FFFFFF",
- border: 0,
- borderRadius: "14px",
- color: spaceAppBackgroundColor,
- cursor: actionDisabled ? "default" : "pointer",
- display: "flex",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 13,
- fontWeight: 700,
- height: 34,
- justifyContent: "center",
- minWidth: 48,
- px: "17px",
- transition:
- "background-color 120ms ease, color 120ms ease",
- "&:disabled": {
- bgcolor: spaceSurfaceHover,
- color: spaceTextMuted,
- },
- "&:focus-visible": {
- outline: `2px solid ${spaceText}`,
- outlineOffset: 2,
- },
- "&:hover:not(:disabled)": { bgcolor: spaceText },
- }}
+ sx={spaceToastActionButtonSx}
>
{actionLabel}
</Box>
diff --git a/web/apps/space/src/components/PostComposer.tsx b/web/apps/space/src/components/PostComposer.tsx
index 12b055284d..128d6fff37 100644
--- a/web/apps/space/src/components/PostComposer.tsx
+++ b/web/apps/space/src/components/PostComposer.tsx
@@ -16,8 +16,6 @@ import {
spacePostPreviewImageForFile,
type SpaceDraftPostImage,
} from "utils/post-image";
-import { useSpaceRouter } from "utils/route-transitions";
-import { spaceRoutes } from "utils/routes";
interface PendingPostDraft {
error?: string;
@@ -41,7 +39,6 @@ const SpacePostComposer: React.FC<SpacePostComposerProps> = ({
onPublish,
profile,
}) => {
- const router = useSpaceRouter();
const publishedPreviewURLRef = React.useRef<string>(undefined);
const displayName =
profile.fullName.trim() || profile.username.trim() || "You";
@@ -134,9 +131,7 @@ const SpacePostComposer: React.FC<SpacePostComposerProps> = ({
}
onDraftPostExitStart={() => setIsDraftPostExiting(true)}
onDraftPostPublished={() => {
- void clearBrowserBackState("back").then(() =>
- router.push(spaceRoutes.home),
- );
+ void clearBrowserBackState("back");
}}
onPublishDraftPost={
draft.isPreviewPending || draft.error
diff --git a/web/apps/space/src/components/PostToast.tsx b/web/apps/space/src/components/PostToast.tsx
new file mode 100644
index 0000000000..bd618c9502
--- /dev/null
+++ b/web/apps/space/src/components/PostToast.tsx
@@ -0,0 +1,77 @@
+import { AlertCircleIcon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box } from "@mui/material";
+import { SpaceActionFeedbackIcon } from "components/ActionFeedback";
+import {
+ SpaceActionToast,
+ spaceToastAutoDismissDurationMs,
+} from "components/ActionToast";
+import React from "react";
+import { useSpaceAppState } from "state/app-state";
+import { spaceToastActionButtonSx } from "styles/buttons";
+import { useSpaceRouter } from "utils/route-transitions";
+import { spaceRoutes } from "utils/routes";
+
+const dangerColor = "#F63A3A";
+
+export const SpacePostToast: React.FC = () => {
+ const router = useSpaceRouter();
+ const { postPublication, setPostPublication } = useSpaceAppState();
+ const dismissPostPublishToast = React.useCallback(() => {
+ setPostPublication(null);
+ }, [setPostPublication]);
+
+ if (!postPublication) return null;
+
+ const phase = postPublication.phase;
+ const isPosting = phase == "posting";
+ const isFailed = phase == "failed";
+ const isPosted = phase == "posted";
+ return (
+ <SpaceActionToast
+ action={
+ isPosted && (
+ <Box
+ component="button"
+ type="button"
+ onClick={() => {
+ dismissPostPublishToast();
+ void router.push(
+ `${spaceRoutes.profile}?section=latest`,
+ undefined,
+ { scroll: false },
+ );
+ }}
+ sx={spaceToastActionButtonSx}
+ >
+ View post
+ </Box>
+ )
+ }
+ animateEntrance={isPosting}
+ autoDismissAfterMs={
+ isFailed ? spaceToastAutoDismissDurationMs : undefined
+ }
+ closeLabel="Dismiss post status"
+ icon={
+ isFailed ? (
+ <HugeiconsIcon
+ color={dangerColor}
+ icon={AlertCircleIcon}
+ size={20}
+ strokeWidth={1.8}
+ />
+ ) : (
+ <SpaceActionFeedbackIcon
+ phase={isPosting ? "busy" : "done"}
+ size={20}
+ />
+ )
+ }
+ message={isPosting ? "Posting..." : isFailed ? "Failed" : "Posted"}
+ onClose={dismissPostPublishToast}
+ showCloseButton={isPosted}
+ zIndex={1400}
+ />
+ );
+};
diff --git a/web/apps/space/src/pages/_app.tsx b/web/apps/space/src/pages/_app.tsx
index 4a54248bf9..f448127ffa 100644
--- a/web/apps/space/src/pages/_app.tsx
+++ b/web/apps/space/src/pages/_app.tsx
@@ -3,6 +3,7 @@ import "@fontsource/nunito/800.css";
import { CssBaseline } from "@mui/material";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { SpacePostComposerHost } from "components/PostComposer";
+import { SpacePostToast } from "components/PostToast";
import { SpaceRouteTransitionBoundary } from "components/RouteTransitionBoundary";
import "configure-zod";
import { CustomHead } from "ente-base/components/Head";
@@ -154,6 +155,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<SpaceAppStateProvider>
<Component {...pageProps} />
<SpacePostComposerHost />
+ <SpacePostToast />
</SpaceAppStateProvider>
</SpaceRouteTransitionBoundary>
</ThemeProvider>
diff --git a/web/apps/space/src/pages/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsx
index e68b34c9a3..28e677f3cb 100644
--- a/web/apps/space/src/pages/app/profile.tsx
+++ b/web/apps/space/src/pages/app/profile.tsx
@@ -132,9 +132,14 @@ const Page: React.FC = () => {
profile={profile}
showPostLoadingIndicator={showInitialPostLoadingIndicator}
onBack={() => void router.push(spaceRoutes.home)}
- onPostSubmitted={() => void router.push(spaceRoutes.home)}
onCreatePost={async (image, caption) => {
- await publishPost(image, caption);
+ const post = await publishPost(image, caption);
+ setPosts((currentPosts) => [
+ post,
+ ...currentPosts.filter(
+ (currentPost) => currentPost.postId != post.postId,
+ ),
+ ]);
}}
onDeletePost={async (postId) => {
const spaceId = profile.spaceId;
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 27025a2e8c..9728978053 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -503,7 +503,6 @@ interface ProfileScreenProps {
isStatsLoading?: boolean;
showPostLoadingIndicator?: boolean;
onBack?: () => void;
- onPostSubmitted?: () => void;
onAddFriend?: () => void;
onAddFriendForPostAction?: (intent: SpaceInviteIntent) => void;
onCreateSpace?: () => void;
@@ -545,7 +544,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
isPostsLoading = false,
isStatsLoading = false,
onBack,
- onPostSubmitted,
onAddFriend,
onAddFriendForPostAction,
onCreateSpace,
@@ -2161,9 +2159,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
}}
onDraftPostExitStart={() => setIsDraftPostExiting(true)}
onDraftPostPublished={() => {
- void clearSelectedPostHistory("back").then(() =>
- onPostSubmitted?.(),
- );
+ void clearSelectedPostHistory("back");
}}
onDeletePost={
isOwnerProfile ? deleteSelectedPost : undefined
diff --git a/web/apps/space/src/state/AppStateProvider.tsx b/web/apps/space/src/state/AppStateProvider.tsx
index 20e3b3eed9..9c338951e8 100644
--- a/web/apps/space/src/state/AppStateProvider.tsx
+++ b/web/apps/space/src/state/AppStateProvider.tsx
@@ -79,17 +79,6 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
[postPreviewUrl],
);
- useEffect(() => {
- if (postPublication?.phase != "failed") return;
-
- const timeoutID = window.setTimeout(() => {
- setPostPublication((current) =>
- current == postPublication ? null : current,
- );
- }, 2500);
- return () => window.clearTimeout(timeoutID);
- }, [postPublication]);
-
const publishPost = useCallback(
async (
image: Parameters<SpaceAppState["publishPost"]>[0],
diff --git a/web/apps/space/src/styles/buttons.ts b/web/apps/space/src/styles/buttons.ts
index 98f5715f66..a0b5e55fb4 100644
--- a/web/apps/space/src/styles/buttons.ts
+++ b/web/apps/space/src/styles/buttons.ts
@@ -1,8 +1,39 @@
-import { spaceOnAccent } from "styles/colors";
+import {
+ spaceAppBackgroundColor,
+ spaceOnAccent,
+ spaceSurfaceHover,
+ spaceText,
+ spaceTextMuted,
+} from "styles/colors";
import { spaceTouchTargetSize } from "styles/touch-targets";
const green = "#08C225";
+export const spaceToastActionButtonSx = {
+ alignItems: "center",
+ bgcolor: "#FFFFFF",
+ border: 0,
+ borderRadius: "14px",
+ color: spaceAppBackgroundColor,
+ cursor: "pointer",
+ display: "flex",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 700,
+ height: 30,
+ justifyContent: "center",
+ minWidth: 48,
+ px: "17px",
+ transition: "background-color 120ms ease, color 120ms ease",
+ "&:disabled": {
+ bgcolor: spaceSurfaceHover,
+ color: spaceTextMuted,
+ cursor: "default",
+ },
+ "&:focus-visible": { outline: `2px solid ${spaceText}`, outlineOffset: 2 },
+ "&:hover:not(:disabled)": { bgcolor: spaceText },
+} as const;
+
export const spaceEmptyStateButtonSx = {
alignItems: "center",
appearance: "none",