Skip to content

Commit

Permalink
Allow previewing community banner image (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Apr 13, 2024
1 parent a54bb29 commit 8c6e7e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/features/post/inFeed/large/media/LargeFeedMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export default function LargeFeedMedia({
blur,
className,
style: baseStyle,
defaultAspectRatio,
...props
}: PostGalleryImgProps & { blur: boolean }) {
}: PostGalleryImgProps & { blur?: boolean; defaultAspectRatio?: number }) {
const dispatch = useAppDispatch();
const [mediaRef, currentAspectRatio] = useMediaLoadObserver(src);

Expand Down Expand Up @@ -59,6 +60,7 @@ export default function LargeFeedMedia({
className={className}
style={baseStyle}
state={placeholderState}
defaultAspectRatio={defaultAspectRatio}
>
<StyledPostMedia
{...props}
Expand Down
7 changes: 5 additions & 2 deletions src/features/post/inFeed/large/media/MediaPlaceholder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IonIcon } from "@ionic/react";
import { HTMLAttributes } from "react";
import { imageOutline } from "ionicons/icons";

const PlaceholderContainer = styled.div`
const PlaceholderContainer = styled.div<{ defaultAspectRatio: number }>`
display: flex;
background: var(--lightroom-bg);
Expand All @@ -14,7 +14,7 @@ const PlaceholderContainer = styled.div`
align-items: center;
justify-content: center;
aspect-ratio: 1.2;
aspect-ratio: ${({ defaultAspectRatio }) => defaultAspectRatio};
position: relative;
${StyledPostMedia} {
Expand All @@ -38,13 +38,15 @@ type State = "loading" | "loaded" | "error" | "custom";

interface MediaPlaceholderProps extends HTMLAttributes<HTMLDivElement> {
state: State;
defaultAspectRatio?: number;
children?: React.ReactNode;
}

export default function MediaPlaceholder({
state,
className,
children,
defaultAspectRatio = 1.2,
...rest
}: MediaPlaceholderProps) {
function renderIcon() {
Expand All @@ -62,6 +64,7 @@ export default function MediaPlaceholder({
return (
<PlaceholderContainer
className={cx(className, state !== "loaded" && "not-loaded")}
defaultAspectRatio={defaultAspectRatio}
{...rest}
>
{children}
Expand Down
11 changes: 9 additions & 2 deletions src/features/sidebar/internal/GenericSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import React from "react";
import Markdown from "../../shared/markdown/Markdown";
import SidebarCounts from "./SidebarCounts";
import SidebarOwners from "./SidebarOwners";
import LargeFeedMedia from "../../post/inFeed/large/media/LargeFeedMedia";

const Container = styled.div`
line-height: 1.5;
`;

const BannerImg = styled.img`
const BannerImg = styled(LargeFeedMedia)`
margin-top: calc(var(--padding-top) * -1);
margin-left: calc(var(--padding-start) * -1);
margin-right: calc(var(--padding-end) * -1);
Expand Down Expand Up @@ -44,7 +45,13 @@ export default function GenericSidebar({
return (
<>
<Container className="ion-padding-start ion-padding-end ion-padding-top">
{banner && <BannerImg src={banner} alt={`Banner for ${name}`} />}
{banner && (
<BannerImg
src={banner}
alt={`Banner for ${name}`}
defaultAspectRatio={2.5}
/>
)}
<Markdown id={id}>{sidebar}</Markdown>
<SidebarCounts counts={counts} />
{extraBadges}
Expand Down

0 comments on commit 8c6e7e4

Please sign in to comment.