Skip to content

armgit / ente

Public Imported from GitHub
0

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

Improve space photo posting flow

Anand Baburajan964c359570a6
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 312d2145bc..d4b92951ec 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -7,6 +7,7 @@ import {
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box } from "@mui/material";
+import { SpaceActionFeedbackIcon } from "components/SpaceActionFeedback";
import {
SpaceFileViewer,
type SpaceLiker,
@@ -446,7 +447,7 @@ const FeedItem: React.FC<FeedItemProps> = ({
gridTemplateColumns: isOwnPost
? "minmax(0, 1fr)"
: "minmax(0, 1fr) auto",
- minHeight: isOwnPost ? undefined : feedLikeActionSize,
+ minHeight: feedLikeActionSize,
mt: "8px",
pl: "4px",
pr: 0,
@@ -675,6 +676,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
const [selectedViewer, setSelectedViewer] =
useState<SelectedHomeViewer | null>(null);
const [postPhotoError, setPostPhotoError] = useState<string>();
+ const [isPostPhotoPreparing, setIsPostPhotoPreparing] = useState(false);
const postInputRef = React.useRef<HTMLInputElement | null>(null);
const localPostObjectUrlsRef = React.useRef<Set<string>>(new Set());
const selectedPhotoFriendID = selectedViewer?.photo.friendID;
@@ -695,7 +697,11 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
URL.revokeObjectURL(objectUrl);
localPostObjectUrlsRef.current.delete(objectUrl);
}, []);
- const openPostPhotoPicker = () => postInputRef.current?.click();
+ const openPostPhotoPicker = () => {
+ if (isPostPhotoPreparing) return;
+
+ postInputRef.current?.click();
+ };
const openFeedPhoto = (
photo: SpaceViewerPhoto,
initialScreen: SpaceViewerInitialScreen = "photo",
@@ -758,11 +764,16 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
event.target.value = "";
if (!file) return;
+ setIsPostPhotoPreparing(true);
setPostPhotoError(undefined);
- void prepareSelectedPostPhoto(file).catch((error: unknown) => {
- console.error("Failed to prepare post photo", error);
- setPostPhotoError(spacePostImageErrorMessage(error));
- });
+ void prepareSelectedPostPhoto(file)
+ .catch((error: unknown) => {
+ console.error("Failed to prepare post photo", error);
+ setPostPhotoError(spacePostImageErrorMessage(error));
+ })
+ .finally(() => {
+ setIsPostPhotoPreparing(false);
+ });
};
React.useEffect(
@@ -822,7 +833,12 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
<Box
component="button"
type="button"
- aria-label="Post photo"
+ aria-label={
+ isPostPhotoPreparing
+ ? "Preparing photo"
+ : "Post photo"
+ }
+ disabled={isPostPhotoPreparing}
onClick={openPostPhotoPicker}
sx={{
appearance: "none",
@@ -831,7 +847,9 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
border: 0,
boxSizing: "border-box",
color: textBase,
- cursor: "pointer",
+ cursor: isPostPhotoPreparing
+ ? "default"
+ : "pointer",
display: "flex",
fontSize: 0,
height: headerActionSize,
@@ -850,10 +868,16 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
},
}}
>
- <HugeiconsIcon
- icon={AddSquareIcon}
+ <SpaceActionFeedbackIcon
+ phase={isPostPhotoPreparing ? "busy" : null}
size={headerAddIconSize}
- strokeWidth={1.8}
+ idleIcon={
+ <HugeiconsIcon
+ icon={AddSquareIcon}
+ size={headerAddIconSize}
+ strokeWidth={1.8}
+ />
+ }
/>
</Box>
<Box
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 3552834a9a..f085811963 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -7,6 +7,7 @@ import {
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Menu, MenuItem } from "@mui/material";
+import { SpaceActionFeedbackIcon } from "components/SpaceActionFeedback";
import {
SpaceFileViewer,
type SpaceLiker,
@@ -181,6 +182,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const [selectedPost, setSelectedPost] =
useState<SelectedProfilePost | null>(null);
const [postPhotoError, setPostPhotoError] = useState<string>();
+ const [isPostPhotoPreparing, setIsPostPhotoPreparing] = useState(false);
const [deletedPostIDs, setDeletedPostIDs] = useState<Set<string>>(
() => new Set(),
);
@@ -240,7 +242,11 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
URL.revokeObjectURL(objectUrl);
localPostObjectUrlsRef.current.delete(objectUrl);
}, []);
- const openPostPhotoPicker = () => postInputRef.current?.click();
+ const openPostPhotoPicker = () => {
+ if (isPostPhotoPreparing) return;
+
+ postInputRef.current?.click();
+ };
const closeSelectedPost = () => {
const localObjectUrl = selectedPost?.localObjectUrl;
setSelectedPost(null);
@@ -294,11 +300,16 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
event.target.value = "";
if (!file) return;
+ setIsPostPhotoPreparing(true);
setPostPhotoError(undefined);
- void prepareSelectedPostPhoto(file).catch((error: unknown) => {
- console.error("Failed to prepare post photo", error);
- setPostPhotoError(spacePostImageErrorMessage(error));
- });
+ void prepareSelectedPostPhoto(file)
+ .catch((error: unknown) => {
+ console.error("Failed to prepare post photo", error);
+ setPostPhotoError(spacePostImageErrorMessage(error));
+ })
+ .finally(() => {
+ setIsPostPhotoPreparing(false);
+ });
};
const copyProfileURL = async () => {
@@ -1208,7 +1219,12 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
<Box
component="button"
type="button"
- aria-label="Post photo"
+ aria-label={
+ isPostPhotoPreparing
+ ? "Preparing photo"
+ : "Post photo"
+ }
+ disabled={isPostPhotoPreparing}
onClick={openPostPhotoPicker}
sx={{
appearance: "none",
@@ -1217,7 +1233,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
border: 0,
boxSizing: "border-box",
color: textBase,
- cursor: "pointer",
+ cursor: isPostPhotoPreparing
+ ? "default"
+ : "pointer",
display: "flex",
fontSize: 0,
height: 32,
@@ -1237,10 +1255,20 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
},
}}
>
- <HugeiconsIcon
- icon={AddSquareIcon}
+ <SpaceActionFeedbackIcon
+ phase={
+ isPostPhotoPreparing
+ ? "busy"
+ : null
+ }
size={28}
- strokeWidth={1.8}
+ idleIcon={
+ <HugeiconsIcon
+ icon={AddSquareIcon}
+ size={28}
+ strokeWidth={1.8}
+ />
+ }
/>
</Box>
)}
diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.ts
index 4a5eeb3d3c..66797f4dd6 100644
--- a/web/apps/space/src/services/space.ts
+++ b/web/apps/space/src/services/space.ts
@@ -292,6 +292,18 @@ const maxSpaceMediaCacheEntries = 128;
const spaceMediaURLCache = new Map<string, Promise<string>>();
const spaceFriendsCache = new Map<string, Promise<FriendProfile[]>>();
+const trimSpaceMediaURLCache = () => {
+ while (spaceMediaURLCache.size > maxSpaceMediaCacheEntries) {
+ const oldest = spaceMediaURLCache.entries().next().value;
+ if (!oldest) break;
+ spaceMediaURLCache.delete(oldest[0]);
+ void oldest[1].then(
+ (url) => URL.revokeObjectURL(url),
+ () => undefined,
+ );
+ }
+};
+
const cachedBlobURL = (
key: string,
load: () => Promise<Uint8Array>,
@@ -311,20 +323,16 @@ const cachedBlobURL = (
throw error;
});
spaceMediaURLCache.set(key, promise);
-
- while (spaceMediaURLCache.size > maxSpaceMediaCacheEntries) {
- const oldest = spaceMediaURLCache.entries().next().value;
- if (!oldest) break;
- spaceMediaURLCache.delete(oldest[0]);
- void oldest[1].then(
- (url) => URL.revokeObjectURL(url),
- () => undefined,
- );
- }
+ trimSpaceMediaURLCache();
return promise;
};
+const rememberCachedBlobURL = (key: string, url: string) => {
+ spaceMediaURLCache.set(key, Promise.resolve(url));
+ trimSpaceMediaURLCache();
+};
+
export const clearSpaceMediaURLCache = () => {
for (const promise of spaceMediaURLCache.values()) {
void promise.then(
@@ -422,6 +430,17 @@ const accountPostAssetURL = (
object.mediaType,
);
+const cacheAccountPostAssetURL = (
+ post: SpacePostResponse,
+ object: SpacePostObject,
+ blob: Blob,
+) => {
+ const key = ["post", post.spaceId, object.objectKey].join(":");
+ if (spaceMediaURLCache.has(key)) return;
+
+ rememberCachedBlobURL(key, URL.createObjectURL(blob));
+};
+
const accountPostAssetURLByPostId = (
ctx: SpaceAccountCtxHandle,
spaceId: string,
@@ -863,6 +882,8 @@ export const createCurrentPhotoPost = async ({
normalizedHeight,
file.type || null,
)) as SpacePostResponse;
+ const object = firstObject(created);
+ if (object) cacheAccountPostAssetURL(created, object, file);
return await postFromAccountPost(ctx, created);
} finally {
releaseCurrentSpaceContext(ctx);