From bed6d65ffa6a3886d77d497463748983c822100d Mon Sep 17 00:00:00 2001 From: Yash Date: Wed, 3 Apr 2024 10:48:29 +0000 Subject: [PATCH] animation with framer motion --- apps/web/src/components/Main.tsx | 10 +- .../src/components/Sidebar/FilterCombobox.tsx | 266 +++++++++++++----- .../src/components/Sidebar/MemoriesBar.tsx | 2 +- apps/web/src/components/Sidebar/index.tsx | 81 ++++-- apps/web/src/components/ui/command.tsx | 4 +- apps/web/src/hooks/useViewport.ts | 5 +- 6 files changed, 271 insertions(+), 97 deletions(-) diff --git a/apps/web/src/components/Main.tsx b/apps/web/src/components/Main.tsx index b6ad3787..ef505db5 100644 --- a/apps/web/src/components/Main.tsx +++ b/apps/web/src/components/Main.tsx @@ -5,6 +5,7 @@ import { Textarea2 } from "./ui/textarea"; import { ArrowRight } from "lucide-react"; import { MemoryDrawer } from "./MemoryDrawer"; import useViewport from "@/hooks/useViewport"; +import { motion } from "framer-motion"; export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { const [value, setValue] = useState(""); @@ -24,10 +25,13 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { }, []); return ( -
+

+ Ask your Second brain +

{width <= 768 && } -
+ ); } diff --git a/apps/web/src/components/Sidebar/FilterCombobox.tsx b/apps/web/src/components/Sidebar/FilterCombobox.tsx index ade54711..d22e8d8c 100644 --- a/apps/web/src/components/Sidebar/FilterCombobox.tsx +++ b/apps/web/src/components/Sidebar/FilterCombobox.tsx @@ -19,6 +19,7 @@ import { PopoverTrigger, } from "@/components/ui/popover"; import { SpaceIcon } from "@/assets/Memories"; +import { AnimatePresence, LayoutGroup, motion } from "framer-motion"; const spaces = [ { @@ -33,6 +34,118 @@ const spaces = [ value: "3", label: "Cool Libraries", }, + { + value: "4", + label: "Cool People", + }, + { + value: "5", + label: "Cool Projects", + }, + { + value: "6", + label: "Cool Tools", + }, + { + value: "7", + label: "Cool Websites", + }, + { + value: "8", + label: "Cool Books", + }, + { + value: "9", + label: "Cool Videos", + }, + { + value: "10", + label: "Cool Podcasts", + }, + { + value: "11", + label: "Cool Articles", + }, + { + value: "12", + label: "Cool Blogs", + }, + { + value: "13", + label: "Cool News", + }, + { + value: "14", + label: "Cool Forums", + }, + { + value: "15", + label: "Cool Communities", + }, + { + value: "16", + label: "Cool Events", + }, + { + value: "17", + label: "Cool Jobs", + }, + { + value: "18", + label: "Cool Companies", + }, + { + value: "19", + label: "Cool Startups", + }, + { + value: "20", + label: "Cool Investors", + }, + { + value: "21", + label: "Cool Funds", + }, + { + value: "22", + label: "Cool Incubators", + }, + { + value: "23", + label: "Cool Accelerators", + }, + { + value: "24", + label: "Cool Hackathons", + }, + { + value: "25", + label: "Cool Conferences", + }, + { + value: "26", + label: "Cool Workshops", + }, + { + value: "27", + label: "Cool Seminars", + }, + { + value: "28", + label: "Cool Webinars", + }, + { + value: "29", + label: "Cool Courses", + }, + { + value: "30", + label: "Cool Bootcamps", + }, + { + value: "31", + label: "Cool Certifications", + }, ]; export interface Props extends React.ButtonHTMLAttributes {} @@ -41,69 +154,96 @@ export function FilterCombobox({ className, ...props }: Props) { const [open, setOpen] = React.useState(false); const [values, setValues] = React.useState([]); + const sortedSpaces = spaces.sort(({ value: a }, { value: b }) => + values.includes(a) && !values.includes(b) + ? -1 + : values.includes(b) && !values.includes(a) + ? 1 + : 0, + ); + + console.log(sortedSpaces, values); + return ( - - - - - - - spaces - .find((s) => s.value === val) - ?.label.toLowerCase() - .includes(search.toLowerCase().trim()) - ? 1 - : 0 - } - > - - - Nothing found - {/* bug: doesn't work on clicking with mouse only keyboard, weird */} - - {spaces.map((space) => ( - { - setValues((prev) => - prev.includes(val) - ? prev.filter((v) => v !== val) - : [...prev, val], - ); - }} - > - - {space.label} - {values.includes(space.value)} - - - ))} - - - - - + + + + + + + + + spaces + .find((s) => s.value === val) + ?.label.toLowerCase() + .includes(search.toLowerCase().trim()) + ? 1 + : 0 + } + > + + + + Nothing found + + {sortedSpaces.map((space) => ( + { + setValues((prev) => + prev.includes(val) + ? prev.filter((v) => v !== val) + : [...prev, val], + ); + }} + asChild + > + + + {space.label} + {values.includes(space.value)} + + + + ))} + + + + + + + + ); } diff --git a/apps/web/src/components/Sidebar/MemoriesBar.tsx b/apps/web/src/components/Sidebar/MemoriesBar.tsx index e2adcd94..e9f675a5 100644 --- a/apps/web/src/components/Sidebar/MemoriesBar.tsx +++ b/apps/web/src/components/Sidebar/MemoriesBar.tsx @@ -115,7 +115,7 @@ export function MemoriesBar() { export function Space({ title, description, content, id }: Space) { console.log(title, content.map((c) => c.image).reverse()); return ( -