From e5e01bb7d482e2ce654f4d2efae155186f2806ed Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 25 Jun 2023 12:20:16 +0530 Subject: [PATCH] temporily removed notifications --- src/components/Notification.tsx | 167 ----------------------- src/components/TopBar.tsx | 4 +- src/components/layouts/DefaultLayout.tsx | 4 +- src/contexts/NotifyContext.tsx | 56 -------- src/pages/api/db/like.ts | 32 ++--- src/pages/api/db/unlike.ts | 10 +- src/pages/api/db/user.ts | 10 +- src/pages/api/route.ts | 10 +- src/pages/api/twitter/tweet/follow.ts | 24 ++-- src/pages/api/twitter/tweet/unfollow.ts | 24 ++-- src/pages/create.tsx | 8 +- src/pages/dash.tsx | 6 +- src/pages/home.tsx | 6 +- src/pages/mod.tsx | 7 +- src/pages/u/[username].tsx | 6 +- 15 files changed, 74 insertions(+), 300 deletions(-) delete mode 100644 src/components/Notification.tsx delete mode 100644 src/contexts/NotifyContext.tsx diff --git a/src/components/Notification.tsx b/src/components/Notification.tsx deleted file mode 100644 index a790a04..0000000 --- a/src/components/Notification.tsx +++ /dev/null @@ -1,167 +0,0 @@ -import { HeartIcon, UserAddIcon, UserRemoveIcon } from '@heroicons/react/solid'; -import { useNotifications } from '@novu/notification-center'; -import { Spinner } from 'flowbite-react'; -import { motion } from 'framer-motion'; -import Head from 'next/head'; -import React, { useEffect } from 'react'; -import { useNotifs } from '~/contexts/NotifyContext'; - -function timeDifference(current: Date, previous: Date) { - - var msPerMinute = 60 * 1000; - var msPerHour = msPerMinute * 60; - var msPerDay = msPerHour * 24; - var msPerMonth = msPerDay * 30; - var msPerYear = msPerDay * 365; - - var elapsed = current.valueOf() - previous.valueOf(); - - if (elapsed < msPerMinute) { - return Math.round(elapsed / 1000) + ` second${Math.round(elapsed / 1000) > 1 ? "s" : ""} ago`; - } - - else if (elapsed < msPerHour) { - return Math.round(elapsed / msPerMinute) + ` minute${Math.round(elapsed / msPerMinute) > 1 ? "s" : ""} ago`; - } - - else if (elapsed < msPerDay) { - return Math.round(elapsed / msPerHour) + ` hour${Math.round(elapsed / msPerHour) > 1 ? "s" : ""} ago`; - } - - else if (elapsed < msPerMonth) { - return 'approximately ' + Math.round(elapsed / msPerDay) + ` day${Math.round(elapsed / msPerDay) > 1 ? "s" : ""} ago`; - } - - else if (elapsed < msPerYear) { - return 'approximately ' + Math.round(elapsed / msPerMonth) + ` month${Math.round(elapsed / msPerMonth) > 1 ? "s" : ""} ago`; - } - - else { - return 'approximately ' + Math.round(elapsed / msPerYear) + ' years ago'; - } -} - - -const Notifications = () => { - - const { - notifications, - fetchNextPage, - hasNextPage, - } = useNotifications(); - - const [unseens, setUnseens] = React.useState(0); - const { readAll } = useNotifs(); - - const [nLoading, setNLoading] = React.useState(false); - - useEffect(() => { - - let tutol = 0; - for (const notif of notifications) { - if (!notif.seen) { - tutol++; - } - } - setUnseens(tutol); - readAll() - }, [notifications, readAll]) - - return ( -
-

- Notifications - {unseens > 0 &&
} - -
- {notifications?.map((notif, index) => { - - if (notif.cta.data.url) { - - return ( - -
-
-

- {notif.templateIdentifier === 'likedyourpost' && ( - - )} - {notif.templateIdentifier === 'followedyou' && ( - <> - { - notif.payload.what === "followed" ? ( - - ) : ( - - ) - } - - )} - {`${notif.content}`}
- {timeDifference((new Date), new Date(notif.createdAt))} -

-
- - ); - } else { - return ( - -
-
-

- {notif.templateIdentifier === 'likedyourpost' && ( - - )} - {notif.templateIdentifier === 'followedyou' && ( - <> - { - notif.payload.what === "followed" ? ( - - ) : ( - - ) - } - - )} - {`${notif.content}`}
- {timeDifference((new Date), new Date(notif.createdAt))} -

-
- - ) - } - })} - {hasNextPage && ( -
- -
- )} -
-

-
- ) -} - -export default Notifications; \ No newline at end of file diff --git a/src/components/TopBar.tsx b/src/components/TopBar.tsx index 9973054..9db2f5e 100644 --- a/src/components/TopBar.tsx +++ b/src/components/TopBar.tsx @@ -5,14 +5,14 @@ import logo_white from "~/../public/logo-white.png"; import logo_black from "~/../public/logo-black.png"; import { useRouter } from "next/router"; import { BellIcon } from "@heroicons/react/outline"; -import { useNotifs } from '~/contexts/NotifyContext'; +// import { useNotifs } from '~/contexts/NotifyContext'; import { useSession } from "next-auth/react"; function TopBar() { const [darkMode, setDarkMode] = useAtom(darkModeAtom); const router = useRouter(); - const { unseens } = useNotifs(); + // const { unseens } = useNotifs(); const { data: session } = useSession(); diff --git a/src/components/layouts/DefaultLayout.tsx b/src/components/layouts/DefaultLayout.tsx index 98a7992..5d62133 100644 --- a/src/components/layouts/DefaultLayout.tsx +++ b/src/components/layouts/DefaultLayout.tsx @@ -6,9 +6,9 @@ import { AnimatePresence, motion } from "framer-motion"; import { useHelp } from "~/contexts/HelpContext"; import Image from "next/image"; import logo_white from "~/../public/logo-white.png"; -import { NovuProvider } from "@novu/notification-center"; +// import { NovuProvider } from "@novu/notification-center"; import { useSession } from "next-auth/react"; -import NotifyProvder from "~/contexts/NotifyContext"; +// import NotifyProvder from "~/contexts/NotifyContext"; import { useRouter } from "next/router"; function DefaultLayout({ children }: { children: React.ReactNode }) { diff --git a/src/contexts/NotifyContext.tsx b/src/contexts/NotifyContext.tsx deleted file mode 100644 index df672ba..0000000 --- a/src/contexts/NotifyContext.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { useNotifications } from "@novu/notification-center"; -import { createContext, useContext, useEffect, useState } from "react"; - -interface Notify { - unseens: number; - readAll: () => void; -} - -const NotifyContext = createContext({ unseens: 0, readAll: () => { } }); - -const NotifyProvder = ({ children }: any) => { - - const { - notifications, - markAsSeen - } = useNotifications(); - - const [unseens, setUnseens] = useState(0); - - useEffect(() => { - let tutol = 0; - for (const notif of notifications) { - if (!notif.seen) { - tutol++; - } - } - setUnseens(tutol); - }, [notifications]) - - function read() { - - setUnseens(0); - - for (const notif of notifications) { - if (!notif.seen) { - markAsSeen(notif._id) - } - } - - } - return ( - - {children} - - ) -} - -export const useNotifs = () => { - const context = useContext(NotifyContext); - if (!context) { - throw new Error("useNotifs must be used within a NotifyProvder"); - } - return context; -} - -export default NotifyProvder; \ No newline at end of file diff --git a/src/pages/api/db/like.ts b/src/pages/api/db/like.ts index 2406721..b031118 100644 --- a/src/pages/api/db/like.ts +++ b/src/pages/api/db/like.ts @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next' import { Resp, Status } from '~/types/Request' import { getSession } from "next-auth/react"; import { prisma } from '~/db/client'; -import { Novu } from '@novu/node'; +// import { Novu } from '@novu/node'; interface Request extends NextApiRequest { query: { @@ -62,11 +62,11 @@ export default async function handler( } }) - const novu = new Novu(process.env.NOVU!); + // const novu = new Novu(process.env.NOVU!); - await novu.subscribers.identify(session.user.id!, { - firstName: session?.user.name, - }) + // await novu.subscribers.identify(session.user.id!, { + // firstName: session?.user.name, + // }) } const lessHaha = user.hahaCoins < 1 ? true : false; @@ -172,17 +172,17 @@ export default async function handler( } }) - const novu = new Novu(process.env.NOVU!); - - await novu.trigger('likedyourpost', { - to: { - subscriberId: authorId - }, - payload: { - who: `${session.user.id}`, - id: id - } - }); + // const novu = new Novu(process.env.NOVU!); + + // await novu.trigger('likedyourpost', { + // to: { + // subscriberId: authorId + // }, + // payload: { + // who: `${session.user.id}`, + // id: id + // } + // }); return res.status(200).json({ success: Status.Success, diff --git a/src/pages/api/db/unlike.ts b/src/pages/api/db/unlike.ts index 682020c..1c51879 100644 --- a/src/pages/api/db/unlike.ts +++ b/src/pages/api/db/unlike.ts @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next' import { Resp, Status } from '~/types/Request' import { getSession } from "next-auth/react"; import { prisma } from '~/db/client'; -import { Novu } from '@novu/node'; +// import { Novu } from '@novu/node'; interface Request extends NextApiRequest { query: { @@ -62,11 +62,11 @@ export default async function handler( } }) - const novu = new Novu(process.env.NOVU!); + // const novu = new Novu(process.env.NOVU!); - novu.subscribers.identify(session?.user.id!, { - firstName: session?.user.name, - }) + // novu.subscribers.identify(session?.user.id!, { + // firstName: session?.user.name, + // }) } diff --git a/src/pages/api/db/user.ts b/src/pages/api/db/user.ts index e507a25..c45ad68 100644 --- a/src/pages/api/db/user.ts +++ b/src/pages/api/db/user.ts @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { Resp, Status } from "~/types/Request"; import { getSession } from "next-auth/react"; import { prisma } from "~/db/client"; -import { Novu } from "@novu/node"; +// import { Novu } from "@novu/node"; type Request = NextApiRequest & { query: { @@ -62,11 +62,11 @@ export default async function handler( }, }); - const novu = new Novu(process.env.NOVU!); + // const novu = new Novu(process.env.NOVU!); - await novu.subscribers.identify(session?.user.username!, { - firstName: session?.user.name, - }) + // await novu.subscribers.identify(session?.user.username!, { + // firstName: session?.user.name, + // }) return res.status(200).json({ success: Status.Success, diff --git a/src/pages/api/route.ts b/src/pages/api/route.ts index cdd9b3d..afcdcd4 100644 --- a/src/pages/api/route.ts +++ b/src/pages/api/route.ts @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { Resp, Status } from "~/types/Request"; import { getSession } from "next-auth/react"; import { prisma } from "~/db/client"; -import { Novu } from "@novu/node"; +// import { Novu } from "@novu/node"; type Request = NextApiRequest & { query: { @@ -54,11 +54,11 @@ export default async function handler( }, }); - const novu = new Novu(process.env.NOVU!); + // const novu = new Novu(process.env.NOVU!); - novu.subscribers.identify(session?.user.id!, { - firstName: session?.user.name, - }) + // novu.subscribers.identify(session?.user.id!, { + // firstName: session?.user.name, + // }) return res.status(200).json({ success: Status.Success, diff --git a/src/pages/api/twitter/tweet/follow.ts b/src/pages/api/twitter/tweet/follow.ts index 441911c..0e85104 100644 --- a/src/pages/api/twitter/tweet/follow.ts +++ b/src/pages/api/twitter/tweet/follow.ts @@ -2,8 +2,8 @@ import type { NextApiRequest, NextApiResponse } from 'next' import { Resp, Status } from '~/types/Request' import { getSession } from "next-auth/react"; -import { TwitterApi } from 'twitter-api-v2'; -import { Novu } from '@novu/node'; +// import { TwitterApi } from 'twitter-api-v2'; +// import { Novu } from '@novu/node'; interface Request extends NextApiRequest { query: { @@ -38,17 +38,17 @@ export default async function handler( try { - const novu = new Novu(process.env.NOVU!); + // const novu = new Novu(process.env.NOVU!); - await novu.trigger("followedyou", { - to: { - subscriberId: username, - }, - payload: { - who: `${session.user.id}`, - what: "followed" - } - }) + // await novu.trigger("followedyou", { + // to: { + // subscriberId: username, + // }, + // payload: { + // who: `${session.user.id}`, + // what: "followed" + // } + // }) res.status(200).json({ success: Status.Success, diff --git a/src/pages/api/twitter/tweet/unfollow.ts b/src/pages/api/twitter/tweet/unfollow.ts index 07d16fd..f604915 100644 --- a/src/pages/api/twitter/tweet/unfollow.ts +++ b/src/pages/api/twitter/tweet/unfollow.ts @@ -2,8 +2,8 @@ import type { NextApiRequest, NextApiResponse } from 'next' import { Resp, Status } from '~/types/Request'; import { getSession } from "next-auth/react"; -import { TwitterApi } from 'twitter-api-v2'; -import { Novu } from '@novu/node'; +// import { TwitterApi } from 'twitter-api-v2'; +// import { Novu } from '@novu/node'; interface Request extends NextApiRequest { query: { @@ -38,16 +38,16 @@ export default async function handler( // TODO: Unfollow in database here try { - const novu = new Novu(process.env.NOVU!); - await novu.trigger("followedyou", { - to: { - subscriberId: username, - }, - payload: { - who: `${session.user.id}`, - what: "unfollowed" - } - }) + // const novu = new Novu(process.env.NOVU!); + // await novu.trigger("followedyou", { + // to: { + // subscriberId: username, + // }, + // payload: { + // who: `${session.user.id}`, + // what: "unfollowed" + // } + // }) res.status(200).json({ success: Status.Success, diff --git a/src/pages/create.tsx b/src/pages/create.tsx index 2b0a5a2..a8ee631 100644 --- a/src/pages/create.tsx +++ b/src/pages/create.tsx @@ -9,13 +9,13 @@ import NextPageWithLayout from "~/types/NextPageWithLayout"; import Create from "~/components/Create"; import { Status } from "~/types/Request"; import Head from "next/head"; -import { useNotifs } from '~/contexts/NotifyContext'; +// import { useNotifs } from '~/contexts/NotifyContext'; const CreatePage: NextPageWithLayout = () => { const { data: session } = useSession(); const [activeTab, setActiveTab] = useState(0); - const { unseens } = useNotifs(); + // const { unseens } = useNotifs(); const [status, setStatus] = useState(""); const [image, setImage] = useState(null); @@ -87,9 +87,7 @@ const CreatePage: NextPageWithLayout = () => { <> - { - `${ unseens > 0 ? (unseens > 9 ? "(9+) " : `(${unseens}) `) : " "} Create | LMFAO.tech` - } + Create | LMFAO.tech
diff --git a/src/pages/dash.tsx b/src/pages/dash.tsx index 6110ef7..bac1d8d 100644 --- a/src/pages/dash.tsx +++ b/src/pages/dash.tsx @@ -7,19 +7,19 @@ import NotFeedPage from "~/components/layouts/NotFeedPage"; import Head from "next/head"; import NextPageWithLayout from "~/types/NextPageWithLayout"; import { ChartBarIcon, HeartIcon, SparklesIcon } from "@heroicons/react/solid"; -import { useNotifs } from "~/contexts/NotifyContext"; +// import { useNotifs } from "~/contexts/NotifyContext"; import { BeakerIcon } from "@heroicons/react/outline"; const dash: NextPageWithLayout = () => { // eslint-disable-next-line react-hooks/rules-of-hooks - const { unseens } = useNotifs(); + // const { unseens } = useNotifs(); return (
{ - `${unseens > 0 ? (unseens > 9 ? "(9+) " : `(${unseens}) `) : " "} Dashboard | LMFAO.tech` + `Dashboard | LMFAO.tech` } diff --git a/src/pages/home.tsx b/src/pages/home.tsx index 633c850..2444468 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -7,11 +7,11 @@ import usePostFeed from "~/hooks/usePostFeed"; import FeedPage from "~/components/layouts/FeedPage"; import { Spinner } from "flowbite-react"; import NextPageWithLayout from "~/types/NextPageWithLayout"; -import { useNotifs } from "~/contexts/NotifyContext"; +// import { useNotifs } from "~/contexts/NotifyContext"; const Home: NextPageWithLayout = () => { const [last, setLast] = useState(0); - const { unseens } = useNotifs(); + // const { unseens } = useNotifs(); let { memes, @@ -42,7 +42,7 @@ const Home: NextPageWithLayout = () => { - {`${unseens > 0 ? (unseens > 9 ? "(9+) " : `(${unseens}) `) : " "} Home | LMFAO.tech`} + Home | LMFAO.tech diff --git a/src/pages/mod.tsx b/src/pages/mod.tsx index 68141fe..4ddffc4 100644 --- a/src/pages/mod.tsx +++ b/src/pages/mod.tsx @@ -8,13 +8,13 @@ import FeedPage from "~/components/layouts/FeedPage"; import { Spinner } from "flowbite-react"; import NextPageWithLayout from "~/types/NextPageWithLayout"; import { useHaha } from "~/contexts/HahaContext"; -import { useNotifs } from '~/contexts/NotifyContext'; +// import { useNotifs } from '~/contexts/NotifyContext'; const Moderation: NextPageWithLayout = () => { const { coins, deletePost, follow, like, likes, mod } = useHaha(); const [last, setLastTweet] = useState(0); - const { unseens } = useNotifs(); + // const { unseens } = useNotifs(); let { memes, @@ -50,8 +50,7 @@ const Moderation: NextPageWithLayout = () => { <> - {`${unseens > 0 ? (unseens > 9 ? "(9+) " : `(${unseens}) `) : " "} LMFAO.tech`} - + LMFAO.tech
diff --git a/src/pages/u/[username].tsx b/src/pages/u/[username].tsx index 6993e9a..befd7a6 100644 --- a/src/pages/u/[username].tsx +++ b/src/pages/u/[username].tsx @@ -15,7 +15,7 @@ import usePostFeed from "~/hooks/usePostFeed"; import Post from "~/types/Post"; import FeedPost from "~/components/FeedPost"; import { Status } from "../../types/Request"; -import { useNotifs } from '~/contexts/NotifyContext'; +// import { useNotifs } from '~/contexts/NotifyContext'; function UserProfile({ u, user }: any) { const router = useRouter(); @@ -32,7 +32,7 @@ function UserProfile({ u, user }: any) { }); const observer = useRef(); - const { unseens } = useNotifs(); + // const { unseens } = useNotifs(); const lastMemeRef = useCallback( (node: any) => { @@ -57,7 +57,7 @@ function UserProfile({ u, user }: any) { return (
- {`${unseens > 0 ? (unseens > 9 ? "(9+) " : `(${unseens}) `) : " "} @${user.name} | LMFAO.tech`} + {`@${user.name} | LMFAO.tech`}