Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refine Space poke animation, avatar loading, and tile layout

Anand Baburajanf8113e7a8d75
diff --git a/web/apps/space/src/components/FriendQuickActionsDialog.tsx b/web/apps/space/src/components/FriendQuickActionsDialog.tsx
index 57ecacf178..d5926488bd 100644
--- a/web/apps/space/src/components/FriendQuickActionsDialog.tsx
+++ b/web/apps/space/src/components/FriendQuickActionsDialog.tsx
@@ -58,7 +58,7 @@ export const FriendQuickActionsDialog: React.FC<
React.useEffect(() => {
if (pokePhase != "done") return;
- const timeout = window.setTimeout(() => setPokePhase(null), 650);
+ const timeout = window.setTimeout(() => setPokePhase(null), 2100);
return () => window.clearTimeout(timeout);
}, [pokePhase]);
@@ -291,16 +291,20 @@ export const FriendQuickActionsDialog: React.FC<
justifyContent: "center",
width: 24,
animation: action.active
- ? "spacePokeJab 550ms ease-in-out"
+ ? "spacePokeJab 2000ms ease-in-out"
: "none",
"@keyframes spacePokeJab": {
"0%, 100%": {
transform:
"translate(0, 0) rotate(0deg) scale(1)",
},
- "50%": {
+ "27.5%, 52%, 73.75%": {
transform:
- "translate(28px, -36px) rotate(-40deg) scale(2.25)",
+ "translate(20px, -80px) rotate(-40deg) scale(3)",
+ },
+ "41%, 63%": {
+ transform:
+ "translate(36px, -94px) rotate(-40deg) scale(3)",
},
},
"@media (prefers-reduced-motion: reduce)": {
diff --git a/web/apps/space/src/components/HomeHeader.tsx b/web/apps/space/src/components/HomeHeader.tsx
index 4126a62c00..dacf0521e9 100644
--- a/web/apps/space/src/components/HomeHeader.tsx
+++ b/web/apps/space/src/components/HomeHeader.tsx
@@ -4,6 +4,7 @@ import { Box, Skeleton } from "@mui/material";
import { SpaceAvatarImage } from "components/AvatarImage";
import React from "react";
import type { SetupProfile } from "screens/SetupProfileScreen";
+import { useSpaceAppState } from "state/app-state";
import { spaceAppBackgroundColor, spaceText } from "styles/colors";
import { spaceTouchTargetSize } from "styles/touch-targets";
@@ -131,33 +132,7 @@ export const SpaceHomeHeader: React.FC<SpaceHomeHeaderProps> = ({
width: headerAvatarSize,
}}
>
- {profile && (profile.avatarUrl || !profile.avatarObjectID) ? (
- <Box
- key={profile.avatarUrl ?? "default-avatar"}
- sx={{
- ...avatarFadeSx,
- borderRadius: "50%",
- filter: profile.avatarUrl
- ? undefined
- : "brightness(0.9)",
- height: headerAvatarImageSize,
- overflow: "hidden",
- width: headerAvatarImageSize,
- }}
- >
- <SpaceAvatarImage src={profile.avatarUrl} />
- </Box>
- ) : (
- <Skeleton
- variant="circular"
- sx={{
- bgcolor: mediaPlaceholderColor,
- height: headerAvatarImageSize,
- transform: "none",
- width: headerAvatarImageSize,
- }}
- />
- )}
+ <SpaceHomeHeaderAvatar profile={profile} />
</Box>
</Box>
<Box
@@ -262,3 +237,36 @@ export const SpaceHomeHeader: React.FC<SpaceHomeHeaderProps> = ({
</Box>
</Box>
);
+
+const SpaceHomeHeaderAvatar: React.FC<{ profile: SetupProfile | null }> = ({
+ profile,
+}) => {
+ const { cachedProfileAvatarUrl } = useSpaceAppState();
+ const avatarUrl = profile ? profile.avatarUrl : cachedProfileAvatarUrl;
+
+ return avatarUrl || (profile && !profile.avatarObjectID) ? (
+ <Box
+ key={avatarUrl ?? "default-avatar"}
+ sx={{
+ ...avatarFadeSx,
+ borderRadius: "50%",
+ filter: avatarUrl ? undefined : "brightness(0.9)",
+ height: headerAvatarImageSize,
+ overflow: "hidden",
+ width: headerAvatarImageSize,
+ }}
+ >
+ <SpaceAvatarImage src={avatarUrl} />
+ </Box>
+ ) : (
+ <Skeleton
+ variant="circular"
+ sx={{
+ bgcolor: mediaPlaceholderColor,
+ height: headerAvatarImageSize,
+ transform: "none",
+ width: headerAvatarImageSize,
+ }}
+ />
+ );
+};
diff --git a/web/apps/space/src/state/AppStateProvider.tsx b/web/apps/space/src/state/AppStateProvider.tsx
index 44725a0145..e469de52a3 100644
--- a/web/apps/space/src/state/AppStateProvider.tsx
+++ b/web/apps/space/src/state/AppStateProvider.tsx
@@ -39,6 +39,8 @@ import { prepareSpacePostImageFromEdit } from "utils/post-image";
export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
children,
}) => {
+ const [cachedProfileAvatarUrl, setCachedProfileAvatarUrl] =
+ useState<string>();
const [friends, setFriends] = useState(initialFriends);
const [isLiveSignupVerification, setIsLiveSignupVerification] =
useState(false);
@@ -113,6 +115,7 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
);
const applyProfile = useCallback((nextProfile: SetupProfile | null) => {
+ setCachedProfileAvatarUrl(undefined);
const previousAvatarURL = avatarURLRef.current;
if (previousAvatarURL && previousAvatarURL != nextProfile?.avatarUrl) {
URL.revokeObjectURL(previousAvatarURL);
@@ -220,7 +223,12 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
try {
const [nextProfile, cachedAvatar] = await Promise.all([
loadExistingSpaceProfile({ force: true }),
- loadCachedCurrentSpaceAvatar(),
+ loadCachedCurrentSpaceAvatar().then((cachedAvatar) => {
+ if (profileLoadGenerationRef.current == generation) {
+ setCachedProfileAvatarUrl(cachedAvatar?.avatarUrl);
+ }
+ return cachedAvatar;
+ }),
]);
if (profileLoadGenerationRef.current == generation) {
const hydratedProfile =
@@ -287,6 +295,7 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
const value = useMemo<SpaceAppState>(
() => ({
+ cachedProfileAvatarUrl,
friends,
isLiveSignupVerification,
onboardingEntrySource,
@@ -318,6 +327,7 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({
signupEmail,
}),
[
+ cachedProfileAvatarUrl,
friends,
isLiveSignupVerification,
onboardingEntrySource,
diff --git a/web/apps/space/src/state/app-state.tsx b/web/apps/space/src/state/app-state.tsx
index 8e3ada11b4..fb436e552c 100644
--- a/web/apps/space/src/state/app-state.tsx
+++ b/web/apps/space/src/state/app-state.tsx
@@ -22,6 +22,7 @@ export interface RefreshSpaceProfileOptions {
}
export interface SpaceAppState {
+ cachedProfileAvatarUrl?: string;
friends: FriendProfile[];
isLiveSignupVerification: boolean;
onboardingEntrySource: OnboardingEntrySource;
diff --git a/web/apps/space/src/utils/home-tile-layout.ts b/web/apps/space/src/utils/home-tile-layout.ts
index 6b9702d803..0fbdbf7d88 100644
--- a/web/apps/space/src/utils/home-tile-layout.ts
+++ b/web/apps/space/src/utils/home-tile-layout.ts
@@ -43,26 +43,26 @@ const tileSlotsForCount = (count: number) => {
}
if (count == 3) {
return {
- columns: 1,
- rows: 3,
+ columns: 2,
+ rows: 2,
slots: [
- { column: 0, row: 0 },
+ { column: 0.5, row: 0 },
{ column: 0, row: 1 },
- { column: 0, row: 2 },
+ { column: 1, row: 1 },
],
};
}
const columns = 2;
const rows = Math.ceil(count / columns);
- const singleTileRow = count % columns ? rows - 1 : -1;
+ const stagger = count % columns ? 0.5 : 0;
const slots: TileSlot[] = [];
- for (let row = 0; row < rows; row++) {
- if (row == singleTileRow) {
- slots.push({ column: 0.5, row });
- } else {
- slots.push({ column: 0, row }, { column: 1, row });
- }
+ for (let index = 0; index < count; index++) {
+ const column = index % columns;
+ slots.push({
+ column,
+ row: Math.floor(index / columns) + column * stagger,
+ });
}
return { columns, rows, slots };
};
@@ -107,24 +107,20 @@ export const homeTilePlacements = (
}
const { columns, rows, slots } = tileSlotsForCount(count);
- const rowOffsets = [0];
- for (let row = 1; row < rows; row++) {
- rowOffsets.push(rowOffsets[row - 1]! + 1.1);
- }
const layout = layoutDimensions(columns, rows);
const availableHeight = Math.max(0, canvasHeight - 2 * verticalInset);
const size = Math.min(
canvasWidth / layout.width,
availableHeight / layout.height,
);
- const horizontalStep = size * (1 + tileGapRatio);
- const renderedWidth = size + horizontalStep * (columns - 1);
+ const tileStep = size * (1 + tileGapRatio);
+ const renderedWidth = size + tileStep * (columns - 1);
const renderedHeight = size * layout.height;
const originX = (canvasWidth - renderedWidth) / 2;
const originY = (canvasHeight - renderedHeight) / 2;
return slots.map(({ column, row }) => ({
size,
- x: originX + column * horizontalStep,
- y: originY + rowOffsets[row]! * size,
+ x: originX + column * tileStep,
+ y: originY + row * tileStep,
}));
};