From a960c2d299ca7223002472fdcd86749c5f0b2d9b Mon Sep 17 00:00:00 2001 From: Dhravya Shah Date: Sat, 20 Jul 2024 23:02:17 -0500 Subject: telegram bot link in dashboared --- apps/web/app/(dash)/home/page.tsx | 333 ++++++++++++++++++++------------------ 1 file changed, 177 insertions(+), 156 deletions(-) diff --git a/apps/web/app/(dash)/home/page.tsx b/apps/web/app/(dash)/home/page.tsx index 3d999e6b..0133cb44 100644 --- a/apps/web/app/(dash)/home/page.tsx +++ b/apps/web/app/(dash)/home/page.tsx @@ -1,164 +1,185 @@ -"use client"; - -import React, { useEffect, useState } from "react"; -import QueryInput from "./queryinput"; -import { getSessionAuthToken, getSpaces } from "@/app/actions/fetchers"; -import { redirect, useRouter } from "next/navigation"; -import { createChatThread, linkTelegramToUser } from "@/app/actions/doers"; -import { toast } from "sonner"; -import { motion } from "framer-motion"; -import { ChromeIcon, GithubIcon, TwitterIcon } from "lucide-react"; -import Link from "next/link"; -import { homeSearchParamsCache } from "@/lib/searchParams"; -import History from "./history"; +'use client'; + +import React, { useEffect, useState } from 'react'; +import QueryInput from './queryinput'; +import { getSessionAuthToken, getSpaces } from '@/app/actions/fetchers'; +import { redirect, useRouter } from 'next/navigation'; +import { createChatThread, linkTelegramToUser } from '@/app/actions/doers'; +import { toast } from 'sonner'; +import { motion } from 'framer-motion'; +import { ChromeIcon, GithubIcon, TwitterIcon } from 'lucide-react'; +import Link from 'next/link'; +import { homeSearchParamsCache } from '@/lib/searchParams'; +import History from './history'; const slap = { - initial: { - opacity: 0, - scale: 1.1, - }, - whileInView: { opacity: 1, scale: 1 }, - transition: { - duration: 0.5, - ease: "easeInOut", - }, - viewport: { once: true }, + initial: { + opacity: 0, + scale: 1.1, + }, + whileInView: { opacity: 1, scale: 1 }, + transition: { + duration: 0.5, + ease: 'easeInOut', + }, + viewport: { once: true }, }; function Page({ searchParams }: { searchParams: Record }) { - // TODO: use this to show a welcome page/modal - const firstTime = searchParams.firstTime === "true"; - - const query = searchParams.q || ""; - - if (firstTime) { - redirect("/onboarding"); - } - - const [queryPresent, setQueryPresent] = useState(false); - - const [telegramUser, setTelegramUser] = useState( - searchParams.telegramUser as string, - ); - const [extensionInstalled, setExtensionInstalled] = useState< - string | undefined - >(searchParams.extension as string); - - const { push } = useRouter(); - - const [spaces, setSpaces] = useState<{ id: number; name: string }[]>([]); - - useEffect(() => { - if (telegramUser) { - const linkTelegram = async () => { - const response = await linkTelegramToUser(telegramUser); - - if (response.success) { - toast.success("Your telegram has been linked successfully."); - } else { - toast.error("Failed to link telegram. Please try again."); - } - }; - - linkTelegram(); - } - - if (extensionInstalled) { - toast.success("Extension installed successfully"); - } - - getSpaces().then((res) => { - if (res.success && res.data) { - setSpaces(res.data); - return; - } - // TODO: HANDLE ERROR - }); - - getSessionAuthToken().then((token) => { - if (typeof window === "undefined") return; - window.postMessage({ token: token.data }, "*"); - }); - }, [telegramUser]); - - return ( -
- {/* all content goes here */} - {/*
hi {firstTime ? 'first time' : ''}
*/} - - - Ask your{" "} - - supermemory - - - -
- { - if (q.length === 0) { - toast.error("Query is required"); - return; - } - - const threadid = await createChatThread(q); - - if (!threadid.success || !threadid.data) { - toast.error("Failed to create chat thread"); - return; - } - - push( - `/chat/${threadid.data}?spaces=${JSON.stringify(spaces)}&q=${q}`, - ); - }} - initialSpaces={spaces} - /> - - -
- -
-
- - - Install extension - - - - Bug report - - - - Twitter - -
-
-
- ); + // TODO: use this to show a welcome page/modal + const firstTime = searchParams.firstTime === 'true'; + + const query = searchParams.q || ''; + + if (firstTime) { + redirect('/onboarding'); + } + + const [queryPresent, setQueryPresent] = useState(false); + + const [telegramUser, setTelegramUser] = useState( + searchParams.telegramUser as string, + ); + const [extensionInstalled, setExtensionInstalled] = useState< + string | undefined + >(searchParams.extension as string); + + const { push } = useRouter(); + + const [spaces, setSpaces] = useState<{ id: number; name: string }[]>([]); + + useEffect(() => { + if (telegramUser) { + const linkTelegram = async () => { + const response = await linkTelegramToUser(telegramUser); + + if (response.success) { + toast.success('Your telegram has been linked successfully.'); + } else { + toast.error('Failed to link telegram. Please try again.'); + } + }; + + linkTelegram(); + } + + if (extensionInstalled) { + toast.success('Extension installed successfully'); + } + + getSpaces().then((res) => { + if (res.success && res.data) { + setSpaces(res.data); + return; + } + // TODO: HANDLE ERROR + }); + + getSessionAuthToken().then((token) => { + if (typeof window === 'undefined') return; + window.postMessage({ token: token.data }, '*'); + }); + }, [telegramUser]); + + return ( +
+ {/* all content goes here */} + {/*
hi {firstTime ? 'first time' : ''}
*/} + + + Ask your{' '} + + supermemory + + + +
+ { + if (q.length === 0) { + toast.error('Query is required'); + return; + } + + const threadid = await createChatThread(q); + + if (!threadid.success || !threadid.data) { + toast.error('Failed to create chat thread'); + return; + } + + push( + `/chat/${threadid.data}?spaces=${JSON.stringify(spaces)}&q=${q}`, + ); + }} + initialSpaces={spaces} + /> + + +
+ +
+
+ + + Install extension + + + + Bug report + + + + Twitter + + + + + + + Telegram bot + +
+
+
+ ); } export default Page; -- cgit v1.2.3