Skip to content

Commit

Permalink
share buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
shakhzodkudratov committed Oct 24, 2024
1 parent 924eced commit d6a700b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 14 deletions.
49 changes: 44 additions & 5 deletions components/article-footer.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import Giscus from '@giscus/react';
import { IconEye, IconThumbDown, IconThumbUp } from '@tabler/icons-react';
import {
IconBrandFacebook,
IconBrandLinkedin,
IconBrandTelegram,
IconBrandX,
IconEye,
IconMail,
IconThumbDown,
IconThumbUp,
} from '@tabler/icons-react';
import { useLocalStorage } from '@uidotdev/usehooks';
import axios from 'axios';
import { useRouter } from 'next/router';
import { useTheme } from 'nextra-theme-docs';
import { useConfig, useTheme } from 'nextra-theme-docs';
import React from 'react';

import { useMutation, useQuery, useQueryClient } from 'react-query';
import {
EmailShareButton,
FacebookShareButton,
LinkedinShareButton,
TelegramShareButton,
TwitterShareButton,
} from 'react-share';

import type { Post } from 'pages/api/logic';

const SHARE_BUTTONS = [
{ Button: FacebookShareButton, Icon: IconBrandFacebook },
{ Button: TwitterShareButton, Icon: IconBrandX },
{ Button: TelegramShareButton, Icon: IconBrandTelegram },
{ Button: LinkedinShareButton, Icon: IconBrandLinkedin },
{ Button: EmailShareButton, Icon: IconMail },
] as const;

const Button: React.FC<
{
children: React.ReactNode;
Expand All @@ -21,7 +44,7 @@ const Button: React.FC<
className={[
'border-2 p-1 rounded hover:disabled:opacity-50 hover:disabled:cursor-not-allowed transition-all',
isActive
? 'border-blue-500 text-blue-500'
? 'border-green-500 text-green-500'
: 'border-black/40 dark:border-white/20',
].join(' ')}
{...props}
Expand All @@ -37,6 +60,7 @@ const ArticleFooter = () => {

// eslint-disable-next-line react-hooks/rules-of-hooks
const { theme } = useTheme();
const { title } = useConfig();

const [localStatus, setLocalStatus] = useLocalStorage<
'liked' | 'disliked' | null
Expand Down Expand Up @@ -84,13 +108,14 @@ const ArticleFooter = () => {

return (
<>
<div className="flex gap-2 mb-2">
<div className="flex gap-2 mb-2 items-start">
<div className="flex flex-col items-center w-8">
<div className="p-1 border-2 border-transparent">
<IconEye stroke={2} />
</div>
<span>{post?.views ?? 0}</span>
</div>
<div className="w-2" />
<div className="flex flex-col items-center w-8">
<Button
isActive={localStatus == 'liked'}
Expand All @@ -111,6 +136,20 @@ const ArticleFooter = () => {
</Button>
<span>{post?.dislikes ?? 0}</span>
</div>
<div className="w-2" />
{SHARE_BUTTONS.map(({ Button, Icon }) => (
<Button
url={window.location.href}
className={[
'w-9 h-9 flex items-center justify-center border-2 border-black/40 dark:border-white/20 p-1 rounded transition-all',
'hover:border-green-500 hover:dark:border-green-500 hover:text-green-500',
].join(' ')}
resetButtonStyle={false}
title={title}
>
<Icon stroke={2} />
</Button>
))}
</div>
<Giscus
key={theme}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-dropzone": "^14.2.3",
"react-medium-image-zoom": "^5.2.10",
"react-query": "^3.39.3",
"react-share": "^5.1.0",
"redoc": "^2.1.3",
"sharp": "^0.31.3",
"styled-components": "^5.3.11",
Expand Down
70 changes: 61 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d6a700b

Please sign in to comment.