diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx index 562e1155..c9761621 100644 --- a/src/components/dashboard/DashboardLayout.tsx +++ b/src/components/dashboard/DashboardLayout.tsx @@ -11,8 +11,7 @@ import { UniLink } from "../ui/UniLink" import { DashboardSidebar } from "./DashboardSidebar" import { useAccountSites } from "~/queries/site" import { ConnectButton } from "~/components/common/ConnectButton" -import { useGetNotifications, useGetSite, useIsOperators } from "~/queries/site" -import { getStorage } from "~/lib/storage" +import { useGetSite, useIsOperators } from "~/queries/site" import { toGateway } from "~/lib/ipfs-parser" import { Avatar } from "~/components/ui/Avatar" import { @@ -38,30 +37,11 @@ export function DashboardLayout({ const userSite = useAccountSites() - const notifications = useGetNotifications({ - siteCId: site.data?.metadata?.proof, - }) - const isOperator = useIsOperators({ characterId: +(site.data?.metadata?.proof || 0), operator: address, }) - const notificationCreatedAt = - getStorage(`notification-${subdomain}`)?.createdAt || 0 - - const [notificationCount, setNotificationCount] = useState(0) - - useEffect(() => { - if (notifications.data && subdomain) { - const count = notifications.data.filter( - (notification: any) => - +new Date(notification.createdAt) > +new Date(notificationCreatedAt), - ).length - setNotificationCount(count) - } - }, [notifications.data, subdomain, notificationCreatedAt]) - useEffect(() => { if (ssrReady && !isConnected) { router.push("/") diff --git a/src/components/site/SiteHeader.tsx b/src/components/site/SiteHeader.tsx index 3fd04b54..6ecbb01d 100644 --- a/src/components/site/SiteHeader.tsx +++ b/src/components/site/SiteHeader.tsx @@ -62,7 +62,7 @@ export const SiteHeader: React.FC<{ { text: "View on blockchain explorer", icon: , - url: `${CSB_SCAN}/address/${site?.metadata?.owner}/transactions`, + url: `${CSB_SCAN}/address/${site?.metadata?.owner}`, }, { text: "JSON Feed", diff --git a/src/models/site.model.ts b/src/models/site.model.ts index 31fe7564..fb62734a 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -454,47 +454,6 @@ export async function unsubscribeFromSite( ) } -export async function getNotifications(input: { siteCId: string }) { - const [subscriptions, notes] = await Promise.all([ - indexer.getBacklinksOfCharacter(input.siteCId, { - limit: 100, - }), - indexer.getNotes({ - toCharacterId: input.siteCId, - limit: 100, - includeCharacter: true, - }), - ]) - - return [ - ...(subscriptions.list.map( - ( - item: LinkEntity & { - type?: "backlinks" - }, - ) => { - item.type = "backlinks" - return item - }, - ) as any), - ] - .concat( - notes.list.map( - ( - item: NoteEntity & { - type?: "notes" - }, - ) => { - item.type = "notes" - return item - }, - ), - ) - .sort((a, b) => { - return b.createdAt > a.createdAt ? 1 : -1 - }) -} - const xLogOperatorPermissions: CharacterOperatorPermission[] = [ CharacterOperatorPermission.SET_NOTE_URI, CharacterOperatorPermission.DELETE_NOTE, diff --git a/src/pages/_site/[site]/feed/notifications.tsx b/src/pages/_site/[site]/feed/notifications.tsx deleted file mode 100644 index 34a3eda5..00000000 --- a/src/pages/_site/[site]/feed/notifications.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import { GetServerSideProps } from "next" -import { fetchGetSite, fetchGetNotifications } from "~/queries/site.server" -import { getSiteLink } from "~/lib/helpers" -import { QueryClient } from "@tanstack/react-query" -import { renderPageContent } from "~/markdown" - -export const getServerSideProps: GetServerSideProps = async (ctx) => { - const queryClient = new QueryClient() - ctx.res.setHeader("Content-Type", "application/feed+json; charset=utf-8") - ctx.res.setHeader("Access-Control-Allow-Methods", "GET") - ctx.res.setHeader("Access-Control-Allow-Origin", "*") - const domainOrSubdomain = ctx.params!.site as string - - const site = await fetchGetSite(domainOrSubdomain, queryClient) - const notifications = await fetchGetNotifications( - { - siteCId: site?.metadata?.proof, - }, - queryClient, - ) - - const link = getSiteLink({ - subdomain: site.username || "", - }) - ctx.res.write( - JSON.stringify({ - version: "https://jsonfeed.org/version/1.1", - title: "Notifications on " + site.name, - description: site.description, - icon: link + site.avatars?.[0], - home_page_url: link, - feed_url: `${link}/feed/notifications`, - items: notifications - ?.map((notification: any) => { - let key = "" - let character - let message = "" - let url = "" - - switch (notification.type) { - case "notes": - if ( - !notification.toNote.metadata?.content?.sources?.includes( - "xlog", - ) - ) { - return null - } - key = - "notes" + notification.characterId + "-" + notification.noteId - character = notification?.character - message = "commented on" - url = `${link}/${ - notification.toNote?.metadata?.content?.attributes?.find( - (attribute: any) => attribute.trait_type === "xlog_slug", - )?.value || - notification.toNote?.characterId + - "-" + - notification.toNote?.noteId - }` - break - case "backlinks": - key = "backlinks" + notification.fromCharacter.handle - character = notification.fromCharacter - message = "follows you" - url = link - break - } - - return { - id: key, - title: `${ - character.metadata?.content?.name - ? character.metadata?.content?.name - : `@${character.handle}` - } ${message} ${ - notification.toNote?.metadata?.content?.title || "" - }`, - content_html: renderPageContent( - notification.metadata?.content?.content, - ).contentHTML, - url: url, - date_published: notification.createdAt, - date_modified: notification.updatedAt, - } - }) - .filter((item: any) => item), - }), - ) - ctx.res.end() - - return { - props: {}, - } -} - -const SiteFeed: React.FC = () => null - -export default SiteFeed diff --git a/src/pages/dashboard/[subdomain]/notifications.tsx b/src/pages/dashboard/[subdomain]/notifications.tsx deleted file mode 100644 index eeba3ab9..00000000 --- a/src/pages/dashboard/[subdomain]/notifications.tsx +++ /dev/null @@ -1,183 +0,0 @@ -import { useRouter } from "next/router" -import { DashboardLayout } from "~/components/dashboard/DashboardLayout" -import { DashboardMain } from "~/components/dashboard/DashboardMain" -import { UniLink } from "~/components/ui/UniLink" -import { getSiteLink } from "~/lib/helpers" -import { useGetNotifications, useGetSite } from "~/queries/site" -import { CharacterFloatCard } from "~/components/common/CharacterFloatCard" -import { Avatar } from "~/components/ui/Avatar" -import dayjs from "~/lib/date" -import { BlockchainIcon } from "~/components/icons/BlockchainIcon" -import { CSB_SCAN } from "~/lib/env" -import { PageContent } from "~/components/common/PageContent" -import { useEffect, useMemo, useState } from "react" -import { setStorage, getStorage } from "~/lib/storage" - -export default function SubdomainIndex() { - const router = useRouter() - const subdomain = router.query.subdomain as string - - const site = useGetSite(subdomain) - - const notifications = useGetNotifications({ - siteCId: site.data?.metadata?.proof, - }) - - const [lastNotificationCreated, setLastNotificationCreated] = useState(0) - - useMemo(() => { - if (subdomain && !lastNotificationCreated) { - setLastNotificationCreated( - +new Date(getStorage(`notification-${subdomain}`)?.createdAt || 1), - ) - } - }, [subdomain]) - - useEffect(() => { - if (notifications.data?.[0].createdAt && subdomain) { - setStorage(`notification-${subdomain}`, { - createdAt: notifications.data[0].createdAt, - }) - } - }, [notifications.data, subdomain]) - - return ( - - -

Notifications

-

- Subscribing the{" "} - - notifications feed - {" "} - via RSS Reader is a great way to get notified in a timely manner. -

-
-
- {notifications.data?.map((notification) => { - let key = "" - let character - let message = "" - - switch (notification.type) { - case "notes": - if ( - !notification.toNote.metadata?.content?.sources?.includes( - "xlog", - ) - ) { - return null - } - key = - "notes" + - notification.characterId + - "-" + - notification.noteId - character = notification?.character - message = "commented on" - break - case "backlinks": - key = "backlinks" + notification.fromCharacter.handle - character = notification.fromCharacter - message = "follows you" - break - } - - return ( -
-
- {+new Date(notification.createdAt) > - +new Date(lastNotificationCreated) && ( -
- New -
- )} -
- -
- - - -
-
-
-
-
- - {character?.metadata?.content?.name || - character?.handle} - {" "} - {message}{" "} - - attribute.trait_type === "xlog_slug", - )?.value || - notification.toNote?.characterId + - "-" + - notification.toNote?.noteId - }`} - > - {notification.toNote?.metadata?.content?.title} - {" "} - ·{" "} - {dayjs - .duration( - dayjs(notification?.createdAt).diff( - dayjs(), - "minute", - ), - "minute", - ) - .humanize()}{" "} - ago ·{" "} - - - -
- -
-
-
- ) - })} -
-
-
-
- ) -} diff --git a/src/queries/site.server.ts b/src/queries/site.server.ts index db015bda..256bdc1d 100644 --- a/src/queries/site.server.ts +++ b/src/queries/site.server.ts @@ -48,20 +48,3 @@ export const prefetchGetSites = async ( return cacheGet(key, () => siteModel.getSites(input)) }) } - -export const fetchGetNotifications = async ( - data: { siteCId?: string }, - queryClient: QueryClient, -) => { - const key = ["getNotifications", data] - if (!data.siteCId) { - return null - } - return await queryClient.fetchQuery(key, async () => { - return cacheGet(key, () => - siteModel.getNotifications({ - siteCId: data.siteCId!, - }), - ) - }) -} diff --git a/src/queries/site.ts b/src/queries/site.ts index 8644f064..788f8379 100644 --- a/src/queries/site.ts +++ b/src/queries/site.ts @@ -194,17 +194,6 @@ export function useUnsubscribeFromSite() { }) } -export const useGetNotifications = (data: { siteCId?: string }) => { - return useQuery(["getNotifications", data], async () => { - if (!data.siteCId) { - return null - } - return siteModel.getNotifications({ - siteCId: data.siteCId, - }) - }) -} - export const useGetOperators = ( data: Parameters[0], ) => {