Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/components/ArticleActions.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TRPCClientError } from "@trpc/client";
import { useContext, useEffect, useState, type FC } from "react";
import { useContext, useEffect, useState, FC } from "react";
import { toast } from "react-toastify";
import { Bookmarkplus, Comment, Dots, Heart, Share } from "~/svgs";
import Bookmarked from "~/svgs/Bookmarked";
import type { Article } from "~/types";
import { api } from "~/utils/api";
import { C, type ContextValue } from "~/utils/context";
import { C, ContextValue } from "~/utils/context";

const ArticleActions: FC<{
article: Article;
Expand Down Expand Up @@ -57,9 +57,27 @@ const ArticleActions: FC<{
}
};

const shareArticle = () => {
if ('share' in navigator) {
navigator.share({
title: 'Share this article',
text: 'Check out this article',
url: window.location.href,
})
.then(() => {
console.log('Shared successfully');
})
.catch((error) => {
console.error('Error sharing:', error);
});
} else {
console.error('Web Share API not supported');
}
};

return (
<div className="sticky bottom-4 left-0 flex w-full items-center justify-center gap-2 px-4 py-4">
<div className="mx-auto flex items-center justify-between gap-2 rounded-full border border-border-light bg-light-bg px-4 py-1 dark:border-border dark:bg-primary-light sm:w-max">
<div className="relative mx-auto flex items-center justify-between gap-2 rounded-full border border-border-light bg-light-bg px-4 py-1 dark:border-border dark:bg-primary-light sm:w-max">
<button
aria-label="icon"
role="button"
Expand Down Expand Up @@ -117,6 +135,7 @@ const ArticleActions: FC<{
aria-label="icon"
role="button"
className="flex items-center gap-2 rounded-full p-2 text-gray-700 hover:bg-text-secondary dark:text-text-secondary dark:hover:bg-border"
onClick={shareArticle}
>
<div className="flex items-center justify-center gap-2">
<Share className="h-5 w-5 fill-none stroke-border dark:stroke-text-primary md:h-6 md:w-6" />
Expand Down