From 3c35f9bd9a1abbbb9e84b3fafc4832f2f6aa3a6d Mon Sep 17 00:00:00 2001
From: DIYgod
Date: Wed, 2 Nov 2022 04:27:20 +0000
Subject: [PATCH] feat: follow all button
---
src/models/site.model.ts | 21 ++++++++++++++
src/pages/index.tsx | 61 ++++++++++++++++++++++++++++++++++++++++
src/queries/site.ts | 30 ++++++++++++++++++++
3 files changed, 112 insertions(+)
diff --git a/src/models/site.model.ts b/src/models/site.model.ts
index 23ab8e38..605e2639 100644
--- a/src/models/site.model.ts
+++ b/src/models/site.model.ts
@@ -8,6 +8,7 @@ import { createClient } from "@urql/core"
import axios from "axios"
import { indexer } from "~/queries/crossbell"
import type { LinkEntity, NoteEntity } from "crossbell.js"
+import type { Contract } from "crossbell.js"
export const checkSubdomain = async ({
subdomain,
@@ -109,6 +110,7 @@ export const getSites = async (input: string[]) => {
characters( where: { handle: { in: $identities } }, orderBy: [{ updatedAt: desc }], take: $limit ) {
handle
updatedAt
+ characterId
notes {
updatedAt
}
@@ -344,6 +346,25 @@ export async function subscribeToSite(
)
}
+export async function subscribeToSites(
+ input: {
+ user: Profile
+ sites: {
+ characterId: string
+ }[]
+ },
+ contract?: Contract,
+) {
+ if (input.user.metadata?.proof) {
+ return contract?.linkCharactersInBatch(
+ input.user.metadata.proof,
+ input.sites.map((s) => s.characterId).filter((c) => c) as any,
+ [],
+ "follow",
+ )
+ }
+}
+
export async function unsubscribeFromSite(
input: {
userId: string
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 83ba49ce..223271d3 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -20,6 +20,8 @@ import { prefetchGetSites } from "~/queries/site.server"
import { useGetSites } from "~/queries/site"
import showcase from "../../showcase.json"
import { CharacterCard } from "~/components/common/CharacterCard"
+import { useGetUserSites, useSubscribeToSites } from "~/queries/site"
+import { SITE_URL } from "~/lib/env"
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const queryClient = new QueryClient()
@@ -108,6 +110,52 @@ export default function Home({ region }: { region: string | null }) {
},
]
+ const [followProgress, setFollowProgress] = useState