Skip to content

Commit

Permalink
refactor: moving data posts to variable
Browse files Browse the repository at this point in the history
  • Loading branch information
yurimutti committed Dec 15, 2024
1 parent d82d8b5 commit 288e145
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,26 @@ export const withProvider = function <T extends object>(
);

// Share Post
const handleShare = () => {
const handleShare = async () => {
if (!existingData.posts[0].id) {
return toast.show('No posts available to share', 'warning');
}

const postId = existingData.posts[0].id;
const origin = window.location.origin;
const previewPath = `${origin}/preview/${postId}`;
const previewPath = new URL(
`/preview/${postId}`,
window.location.origin
).toString();

try {
navigator.clipboard.writeText(previewPath);
if (!navigator.clipboard) {
throw new Error('Clipboard API not available');
}
await navigator.clipboard.writeText(previewPath);
return toast.show('Link copied to clipboard.', 'success');
} catch (err) {
toast.show('Failed to copy the link.', 'warning');
if (err instanceof Error)
toast.show(`Failed to copy the link. ${err.message}`, 'warning');
}
};

Expand Down Expand Up @@ -363,9 +373,7 @@ export const withProvider = function <T extends object>(
onClick={tagPersonOrCompany(
integration.id,
(newValue: string) =>
changeValue(index)(
val.content + newValue
)
changeValue(index)(val.content + newValue)
)}
>
Tag a company
Expand Down
11 changes: 7 additions & 4 deletions apps/frontend/src/components/preview/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ export const Preview = ({ id }: PreviewProps) => {
</main>
);

const post = data?.posts?.[0];
if (!post) return null;

return (
<IntegrationContext.Provider
value={{
date: dayjs(),
integration: data?.posts[0]?.integration,
integration: post.integration,
value: [
{
content: data?.posts[0]?.content,
id: data?.posts[0]?.id,
image: data?.posts[0]?.image,
content: post.content,
id: post.id,
image: post.image,
},
],
}}
Expand Down

0 comments on commit 288e145

Please sign in to comment.