Skip to content

Commit

Permalink
chore: solvro/config compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
kguzek committed Dec 18, 2024
1 parent 393c265 commit 1fd94d9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/app/news/components/post-attachments.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use client";

import { Button } from "@/components/ui/button";
import { FacebookAttachment } from "@/lib/types";
import Image from "next/image";
import { useState } from "react";

import { Button } from "@/components/ui/button";
import type { FacebookAttachment } from "@/lib/types";

function PostAttachment({ attachment }: { attachment: FacebookAttachment }) {
const [showSubAttachments, setShowSubAttachments] = useState(false);
const hasSubAttachments = attachment.subattachments?.data != null;
Expand All @@ -20,14 +21,15 @@ function PostAttachment({ attachment }: { attachment: FacebookAttachment }) {
className="my-4"
width={800}
height={0}
// width={attachment.media.image.width}
// height={attachment.media.image.height}
/>
)}
{hasSubAttachments && (
{/* @solvro/config forced me into doing !! on a boolean */}
{!!hasSubAttachments && (
<Button
className="order-2 ml-3 hover:text-primary"
onClick={() => setShowSubAttachments((old) => !old)}
onClick={() => {
setShowSubAttachments((old) => !old);
}}
>
{showSubAttachments ? "Mniej" : "Więcej"} zdjęć
</Button>
Expand All @@ -41,7 +43,7 @@ export function PostAttachments({
}: {
attachments: FacebookAttachment[];
}) {
return attachments.map((attachment, idx) => (
<PostAttachment attachment={attachment} key={`post-attachment-${idx}`} />
return attachments.map((attachment) => (
<PostAttachment attachment={attachment} key={attachment.media.image.src} />
));
}
6 changes: 4 additions & 2 deletions src/app/news/components/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ export function Post({
</div>
</div>
<p className="whitespace-pre-line border-t-2 pt-2">
{(post.message == null || post.message.trim() === "") && (
{(post.message ?? "") || (
<i className="italic text-slate-400">empty post</i>
)}
</p>
<div className="flex flex-wrap justify-center md:justify-start">
<PostAttachments attachments={post.attachments?.data ?? []} />
{post.permalink_url && <ShareButton link={post.permalink_url} />}
{post.permalink_url.length > 0 && (
<ShareButton link={post.permalink_url} />
)}
</div>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/news/components/share-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export function ShareButton({ link }: { link: string }) {
async function handleClick() {
setClicked(true);
if ("clipboard" in navigator && "writeText" in navigator.clipboard) {
setCopyingFailed(true);
} else {
await navigator.clipboard.writeText(link);
} else {
setCopyingFailed(true);
}
setTimeout(() => {
setClicked(false);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const buttonVariants = cva(
default:
"rounded-md text-sm h-8 px-3 md:rounded-xs md:border-2 md:text-base md:h-10 md:px-4 border-2 border-primary hover:text-primary bg-primary text-primary-foreground hover:bg-primary/90",
destructive:
"px-3 border-2 border-destructive bg-destructive text-destructive-foreground hover:bg-destructive/90",
"h-10 px-3 border-2 border-destructive bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline:
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface FacebookAttachment {
src: string;
};
};
subattachments: FacebookAttachments;
subattachments?: FacebookAttachments;
}

/** A Facebook post as returned by the Facebook API. */
Expand Down

0 comments on commit 1fd94d9

Please sign in to comment.