From a6be88deabe2efaa30af7d4b0037dce4ccdca230 Mon Sep 17 00:00:00 2001 From: codetorso Date: Thu, 18 Jul 2024 16:33:17 +0530 Subject: refactor /home --- apps/web/app/(dash)/home/heading.tsx | 48 +++++++++++++++++++ apps/web/app/(dash)/home/headingVariants.ts | 50 ++++++++++++++++++++ apps/web/app/(dash)/home/homeVariants.ts | 50 -------------------- apps/web/app/(dash)/home/page.tsx | 71 ++++++----------------------- 4 files changed, 112 insertions(+), 107 deletions(-) create mode 100644 apps/web/app/(dash)/home/heading.tsx create mode 100644 apps/web/app/(dash)/home/headingVariants.ts delete mode 100644 apps/web/app/(dash)/home/homeVariants.ts (limited to 'apps') diff --git a/apps/web/app/(dash)/home/heading.tsx b/apps/web/app/(dash)/home/heading.tsx new file mode 100644 index 00000000..1a120684 --- /dev/null +++ b/apps/web/app/(dash)/home/heading.tsx @@ -0,0 +1,48 @@ +import { useEffect, useState } from "react"; +import { headings } from "./headingVariants"; +import { motion } from "framer-motion"; + +const slap = { + initial: { + opacity: 0, + scale: 1.1, + }, + whileInView: { opacity: 1, scale: 1 }, + transition: { + duration: 0.5, + ease: "easeInOut", + }, + viewport: { once: true }, +}; + +export function Heading() { + const [showHeading, setShowHeading] = useState(0); + + useEffect(()=> { + setShowHeading(Math.floor(Math.random() * headings.length)); + }) + return ( + + {headings[showHeading]!.map((v, i) => { + return ( + + {v.content} + + ); + })} + + ); +} \ No newline at end of file diff --git a/apps/web/app/(dash)/home/headingVariants.ts b/apps/web/app/(dash)/home/headingVariants.ts new file mode 100644 index 00000000..578b87c4 --- /dev/null +++ b/apps/web/app/(dash)/home/headingVariants.ts @@ -0,0 +1,50 @@ +export const headings = [ + [ + { + type: "text", + content: "Unlock your", + }, + { + type: "highlighted", + content: " digital brain", + }, + ], + [ + { + type: "text", + content: "Save", + }, + { + type: "highlighted", + content: " everything.", + }, + { + type: "text", + content: " Connect", + }, + { + type: "highlighted", + content: " anything.", + }, + ], + [ + { + type: "text", + content: "Turn your bookmarks into", + }, + { + type: "highlighted", + content: " insights.", + }, + ], + [ + { + type: "text", + content: "The smart way to use your", + }, + { + type: "highlighted", + content: " digital treasure.", + }, + ], +]; diff --git a/apps/web/app/(dash)/home/homeVariants.ts b/apps/web/app/(dash)/home/homeVariants.ts deleted file mode 100644 index 1b44bab9..00000000 --- a/apps/web/app/(dash)/home/homeVariants.ts +++ /dev/null @@ -1,50 +0,0 @@ -export const variants = [ - [ - { - type: "text", - content: "Unlock your", - }, - { - type: "highlighted", - content: " digital brain", - }, - ], - [ - { - type: "text", - content: "Save", - }, - { - type: "highlighted", - content: " everything.", - }, - { - type: "text", - content: " Connect", - }, - { - type: "highlighted", - content: " anything.", - }, - ], - [ - { - type: "text", - content: "Turn your bookmarks into", - }, - { - type: "highlighted", - content: " insights.", - }, - ], - [ - { - type: "text", - content: "The smart way to use your", - }, - { - type: "highlighted", - content: " digital treasure.", - }, - ], -]; diff --git a/apps/web/app/(dash)/home/page.tsx b/apps/web/app/(dash)/home/page.tsx index 7ef8e65d..68a14d53 100644 --- a/apps/web/app/(dash)/home/page.tsx +++ b/apps/web/app/(dash)/home/page.tsx @@ -6,20 +6,16 @@ import { getSessionAuthToken, getSpaces } from "@/app/actions/fetchers"; import { useRouter } from "next/navigation"; import { createChatThread, linkTelegramToUser } from "@/app/actions/doers"; import { toast } from "sonner"; -import { motion } from "framer-motion"; -import { variants } from "./homeVariants"; - -const slap = { - initial: { - opacity: 0, - scale: 1.1, - }, - whileInView: { opacity: 1, scale: 1 }, - transition: { - duration: 0.5, - ease: "easeInOut", - }, - viewport: { once: true }, +import { Heading } from "./heading"; + +const linkTelegram = async (telegramUser: string) => { + 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."); + } }; function Page({ @@ -27,9 +23,6 @@ function Page({ }: { searchParams: Record; }) { - // TODO: use this to show a welcome page/modal - // const { firstTime } = homeSearchParamsCache.parse(searchParams); - const [telegramUser, setTelegramUser] = useState( searchParams.telegramUser as string, ); @@ -41,27 +34,18 @@ function Page({ const [spaces, setSpaces] = useState<{ id: number; name: string }[]>([]); - const [showVariant, setShowVariant] = useState(0); useEffect(() => { + // telegram bot 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(); + linkTelegram(telegramUser); } if (extensionInstalled) { toast.success("Extension installed successfully"); } + // fetch spaces getSpaces().then((res) => { if (res.success && res.data) { setSpaces(res.data); @@ -70,8 +54,6 @@ function Page({ // TODO: HANDLE ERROR }); - setShowVariant(Math.floor(Math.random() * variants.length)); - getSessionAuthToken().then((token) => { if (typeof window === "undefined") return; window.postMessage({ token: token.data }, "*"); @@ -80,32 +62,7 @@ function Page({ return (
- {/* all content goes here */} - {/*
hi {firstTime ? 'first time' : ''}
*/} - - - {variants[showVariant]!.map((v, i) => { - return ( - - {v.content} - - ); - })} - - +
{ -- cgit v1.2.3