Skip to content

Commit

Permalink
fix: placeholder bg for site image on login (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Dec 2, 2024
1 parent 6b7a2f5 commit d01b855
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/features/auth/login/login/Login.module.css

This file was deleted.

17 changes: 3 additions & 14 deletions src/features/auth/login/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ import { getLoginErrorMessage, isLemmyError } from "#/helpers/lemmyErrors";
import { loginSuccess } from "#/helpers/toastMessages";
import useAppToast from "#/helpers/useAppToast";
import { VOYAGER_TERMS } from "#/helpers/voyager";
import { buildBaseLemmyUrl, getImageSrc } from "#/services/lemmy";
import { buildBaseLemmyUrl } from "#/services/lemmy";
import { useAppDispatch, useAppSelector } from "#/store";

import { getInstanceFromHandle } from "../../authSelectors";
import { addGuestInstance, login } from "../../authSlice";
import lemmyLogo from "../lemmyLogo.svg";
import LoginAvatarImg from "./LoginAvatarImg";
import Totp from "./Totp";

import styles from "./Login.module.css";

interface LoginProps {
url: string;
siteIcon: string | undefined;
Expand Down Expand Up @@ -164,16 +162,7 @@ export default function Login({ url, siteIcon }: LoginProps) {
>
<IonChip outline>
<IonAvatar>
<img
className={styles.siteIconImg}
src={
siteIcon
? getImageSrc(siteIcon, {
size: 24,
})
: lemmyLogo
}
/>
<LoginAvatarImg src={siteIcon} />
</IonAvatar>
<IonLabel>{url}</IonLabel>
</IonChip>
Expand Down
7 changes: 7 additions & 0 deletions src/features/auth/login/login/LoginAvatarImg.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.img {
object-fit: contain;
}

.loading {
background-color: rgba(var(--ion-text-color-rgb, 0, 0, 0), 0.07);
}
30 changes: 30 additions & 0 deletions src/features/auth/login/login/LoginAvatarImg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useState } from "react";

import { cx } from "#/helpers/css";
import { getImageSrc } from "#/services/lemmy";

import lemmyLogo from "../lemmyLogo.svg";

import styles from "./LoginAvatarImg.module.css";

interface LoginAvatarImgProps {
src: string | undefined;
}

export default function LoginAvatarImg({ src }: LoginAvatarImgProps) {
const [loaded, setLoaded] = useState(false);

return (
<img
className={cx(styles.img, !loaded && styles.loading)}
src={
src
? getImageSrc(src, {
size: 24,
})
: lemmyLogo
}
onLoad={() => setLoaded(true)}
/>
);
}

0 comments on commit d01b855

Please sign in to comment.