AIStoreHub Package Vault: Qdrant Vector Engine MCP
Package Slug: mcp-server-qdrant
Archetype: mcp_server
Upstream Repository: https://github.com/qdrant/qdrant
Workspace Files & Specifications (40 files)
- aistorehub.json (489 bytes)
{ "name": "Qdrant Vector Engine MCP", "slug": "mcp-server-qdrant", "version": "1.0.0", "type": "mcp_server", "description": "Model Context Protocol server providing vector similarity search and payload filtering across Qdrant vector databases.", "owner": "community", "repository": "catalog", "github_repo_url": "https://github.com/qdrant/qdrant", "tags": [ "mcp", "search", "vector", "rag", "qdrant" ], "imported_at": "2026-11-22T00:08:35.635Z" } - INSTRUCTIONS.md (445 bytes)
# Qdrant Vector Engine MCP (mcp-server-qdrant) **System Type:** mcp_server **Maintainer:** @community ## System Purpose & Directives Model Context Protocol server providing vector similarity search and payload filtering across Qdrant vector databases. ## Operational Directives 1. Read and analyze the user query carefully. 2. Utilize workspace tools to produce rigorous, reproducible results. 3. Verify and test all output before delivery.
- README.md (2102 bytes)
## How to interview using this template Open ONLY the `shared/` folder within VSCode and in the Extensions Marketplace find `CodeTogether Live`. Install it. Inside the extension, you'll have to click on 'Host New Session' and then 'Start'. You now have a link in your clipboard, which you should share with the candidate. Don't forget to run `npm run vite.dev` inside your editor terminal, since this is not currently possible from the browser editor (link) with the free version of the extension. The locally running server will display localhost:5173 as well as a the project within the network, which the user can access remotely to see the SPA in action, something like: `10.5.52.144:5173`. The candidate should be sharing their screen while they read and later approach the challenge! ## React Template(⚡️) ⚡️ A minimal React Vite starter template. ### Feature - ⚡️ Fast - Build tools based on vite. - 👻 Small - Based on the smallest runnable build. - 💄 Prettier - Integrated Prettier to help you format the code. - ✅ Safety - Https is enabled by default. - 😎 Reliable - Integrated eslint and commitlint. - 🤖 Intelligent - Integrated renovate to help you maintain the dependent version. ### Preview [](https://imgtu.com/i/qekup8) ### Getting Started ```bash npx degit lzm0x219/template-vite-react myapp cd myapp git init ``` #### Prerequisites - `npm` and/or `pnpm` should be installed. - `git` should be installed (recommended v2.4.11 or higher) #### Available scripts ##### `npm run vite.dev` Runs the app in development mode. Open https://localhost:5173 to view it in the browser. The page will automatically reload if you make changes to the code. You will see the build errors and lint warnings in the console. ##### `npm run vite.build` Builds the app for production to the `dist` folder. It correctly bundles React in production mode and optimizes the build for the best performance. The build is minified and the filenames include the hashes. Your app is ready to be deployed.
- shared/BEFORE_README.md (1988 bytes)
# README ## Welcome to the Qdrant Cloud UI challenge Hi there! 👋 Thanks for your availability and for joining us today in the upcoming technical challenge. This file is intended to give you serve as mental preparation and to provide a glimpse into the tasks we'll be working on in a few minutes. ## Preparation Once we start the video call, we'll be sharing a link to an online editor (choices are VSCode, Intellij and others), where we've setup a small SPA application that will serve as a playground, to implement some technical solutions to a JavaScript (with TypeScript) challenge - within a React application context. The problem will be shared in more detail within code comments, with a comprenhensive list of TODOs. The entry point for this challenge is the file `src/tracking.tsx`, which will contain the aforementioned details. ## Pair-coding The idea is that you'll share your screen while we pair-code in this challenge, you'll be the main editor on your side within your browser, and everything is setup to work productively: web dev server with hot module replacement (vite), typescript, eslint, jsx, and routing. Once the environment is run (`npm run vite.dev`), the challenge will start, and we will able to see the results in a second browser tab, one holds the editor and the other the SPA. ## Scope and context The user story goes as follows: our pages offer a cookie banner which appears flying over the bottom part of the viewport and it contains two action buttons: Reject and Accept. There are other action buttons across the application, which also need attention. You'll find all of the ones that are relevant by searching for the DOM attribute `data-tracking` in the relevant React components (`.jsx`). As you've probably guessed, we'd like to implement event tracking in the SPA, from clicks to navigation to other routes (though the former is the primary goal of this exercise). Thanks for participating and see you on the other side in a few!
- shared/eslint.config.js (817 bytes)
import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import hooksPlugin from "eslint-plugin-react-hooks"; export default tseslint.config( eslint.configs.recommended, ...tseslint.configs.strictTypeChecked, ...tseslint.configs.stylisticTypeChecked, { languageOptions: { parserOptions: { projectService: { allowDefaultProject: ["eslint.config.*"], }, }, }, plugins: { "react-hooks": hooksPlugin, }, rules: { ...hooksPlugin.configs.recommended.rules, "@typescript-eslint/consistent-type-definitions": "off", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-misused-promises": [ "error", { checksVoidReturn: false, }, ], }, }, ); - shared/index.html (375 bytes)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Qdrant Cloud</title> <link rel="shortcut icon" href=https://qdrant.tech/favicon/favicon.ico> </head> <body> <div id="root"></div> <script type="module" src="/src/main.tsx"></script> </body> </html> - shared/package.json (1534 bytes)
{ "name": "qdrant-ui-challenge", "version": "1.0.0", "type": "module", "scripts": { "build": "turbo vite.build", "dev": "turbo vite.dev", "lint": "tsc", "preview": "turbo vite.preview", "vite.build": "vite build", "vite.dev": "vite --host", "vite.preview": "vite preview" }, "lint-staged": { "*.{ts,tsx,js,cjs}": [ "prettier --write" ], "*.{md,html,css,json,yml}": "prettier --write", "package.json": "pnpm sort-package-json" }, "dependencies": { "@chakra-ui/icons": "^2.2.4", "@chakra-ui/react": "^2.10.2", "@emotion/react": "^11.13.3", "react": "18.3.1", "react-dom": "18.3.1", "react-router-dom": "6.27.0", "tilg": "0.1.1" }, "devDependencies": { "@eslint/js": "^9.12.0", "@total-typescript/ts-reset": "0.6.1", "@types/node": "20.16.11", "@types/react": "18.3.11", "@types/react-dom": "18.3.1", "@vitejs/plugin-react-swc": "3.7.1", "autoprefixer": "10.4.20", "eslint": "^9.12.0", "eslint-plugin-react-hooks": "^5.0.0", "lightningcss": "1.27.0", "lint-staged": "15.2.10", "postcss": "8.4.47", "prettier": "3.3.3", "prettier-plugin-packagejson": "2.5.3", "prettier-plugin-tailwindcss": "0.6.8", "sort-package-json": "2.10.1", "tailwindcss": "3.4.13", "turbo": "2.1.3", "typescript": "5.6.3", "typescript-eslint": "^8.9.0", "vite": "5.4.9", "vite-plugin-mkcert": "1.17.6", "vite-tsconfig-paths": "5.0.1" }, "packageManager": "[email protected]" } - shared/postcss.config.js (81 bytes)
export default { plugins: { tailwindcss: {}, autoprefixer: {}, }, }; - shared/README.md (794 bytes)
// TODO: implement onConsent to set a state in the app to remember the user's choice // 1. Then use this state to decide whether to track events or not. // 2. Then provide a trackEvent function that stores the tracked events in a queue, and flushes them when the user gives consent. // 3. Extra: deduplicate equal events that occur within 500ms (throttle) - this will help prevent RAGE clicks. # README Welcome again. Let's share a few goals for this exercise: - We'd like the solution to be idiomatic of React. - We'd like TypeScript types (we're in strict-mode) to be correct. - We'd like the solution to be reusable and maintenable. - We'd like for the solution to be elegant and right to the point. Your starting point is `src/tracking.tsx`, let's head over there and read some more...
- shared/src/App.tsx (484 bytes)
import { Outlet, ScrollRestoration } from "react-router-dom"; import { ChakraProvider, GlobalStyle } from "@chakra-ui/react"; // import useDebugRender from "tilg"; import { theme } from "./styles/theme"; import { CookieBanner } from "./components/CookieBanner"; export default function App() { // useDebugRender(); return ( <ChakraProvider theme={theme}> <GlobalStyle /> <Outlet /> <CookieBanner /> <ScrollRestoration /> </ChakraProvider> ); } - shared/src/components/Content.tsx (1925 bytes)
import { ArrowForwardIcon } from "@chakra-ui/icons"; import { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, Box, Button, Text, } from "@chakra-ui/react"; export const Content = () => { return ( <Box margin="0 auto" maxWidth="75%"> <Accordion variant="custom"> <AccordionItem> <AccordionButton> <Box as="span" flex="1" textAlign="left"> <Text fontSize="xl" fontWeight="medium" color="#f0f3fa"> Cloud-Native Scalability & High-Availability </Text> </Box> <AccordionIcon /> </AccordionButton> <AccordionPanel pb={4}> <Text fontSize="sm" color="#f0f3fa"> Enterprise-grade Managed Cloud. Vertical and horizontal scaling and zero-downtime upgrades. </Text> <Button colorScheme="red" size="sm" variant="link" data-tracking> Qdrant Cloud <ArrowForwardIcon /> </Button> </AccordionPanel> </AccordionItem> <AccordionItem> <Text> <AccordionButton> <Box as="span" flex="1" textAlign="left" fontWeight="medium"> <Text fontSize="xl" color="#f0f3fa"> Ease of Use & Simple Deployment </Text> </Box> <AccordionIcon /> </AccordionButton> </Text> <AccordionPanel pb={4}> <Text fontSize="sm"> Quick deployment in any environment with Docker and a lean API for easy integration, ideal for local testing. </Text> <Button colorScheme="red" size="sm" variant="link" data-tracking> Quick Start Guide <ArrowForwardIcon /> </Button> </AccordionPanel> </AccordionItem> </Accordion> </Box> ); }; - shared/src/components/CookieBanner.tsx (1541 bytes)
import { Alert, AlertDescription, Button, useToast, Wrap, WrapItem, Text, ToastId, } from "@chakra-ui/react"; import { useEffect } from "react"; export const CookieBanner = () => { const toast = useToast(); useEffect(() => { let toastId: ToastId; const id = setTimeout(() => { toastId = toast({ render: (_props) => ( <Alert status="warning" gap={2}> <AlertDescription flex="0 1 auto"> <Text fontSize="sm"> We use cookies to learn more about you. At any time you can delete or block cookies through your browser settings. </Text> </AlertDescription> <Wrap spacing={2} flex="1 0 auto"> <WrapItem> <Button variant="outline" colorScheme="yellow" size="xs" data-tracking > Reject </Button> </WrapItem> <WrapItem> <Button variant="solid" colorScheme="green" size="xs" data-tracking > Accept </Button> </WrapItem> </Wrap> </Alert> ), status: "info", duration: null, isClosable: true, }); }, 1000); return () => { clearTimeout(id); toast.close(toastId); }; }); return null; }; - shared/src/components/HeroHeader.tsx (1342 bytes)
import { Box, Button, Text } from "@chakra-ui/react"; export const HeroHeader = () => { return ( <Box paddingTop="2rem" position="relative" background="url(https://qdrant.tech/img/stars-pattern.png)" textAlign="center" > <Box display="flex" justifyContent="center" flexDirection="column" alignItems="center" gap="4" padding="4rem 0 0" textAlign="center" maxWidth="100%" width="100%" > <Text fontSize="4xl" fontWeight="semibold" color="#f0f3fa"> High-Performance Vector Search at Scale </Text> <Text fontSize="lg" fontWeight="medium" color="#8f98b2" marginBottom="8" > Powering the next generation of AI applications with advanced, open-source vector similarity search technology. </Text> <Button data-tracking>Get started</Button> </Box> <img style={{ margin: "0 auto", display: "block", width: "100%", maxWidth: "1200px", height: "auto", top: "-10vh", position: "relative", pointerEvents: "none", }} src="https://qdrant.tech/img/hero-home-illustration-x1.png" /> </Box> ); }; - shared/src/global.ts (32 bytes)
import "@/styles/tailwind.css";
- shared/src/main.tsx (608 bytes)
import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import { createBrowserRouter, RouterProvider } from "react-router-dom"; import routes from "@/routes"; import App from "@/App"; import "@/global"; const container = document.getElementById("root") as HTMLElement; const root = createRoot(container); const router = createBrowserRouter([ { path: "/", element: <App />, children: routes, errorElement: <div>error</div>, }, ]); root.render( <StrictMode> <RouterProvider router={router} fallbackElement={<div>loading...</div>} /> </StrictMode>, ); - shared/src/pages/404.tsx (64 bytes)
export default function Notfound() { return <div>404</div>; } - shared/src/pages/index.tsx (209 bytes)
import { Content } from "@/components/Content"; import { HeroHeader } from "@/components/HeroHeader"; export default function Index() { return ( <> <HeroHeader /> <Content /> </> ); } - shared/src/routes.tsx (472 bytes)
import { lazy, Suspense } from "react"; import { type RouteObject } from "react-router-dom"; const Index = lazy(() => import("@/pages/index")); const Notfound = lazy(() => import("@/pages/404")); export const routes: Array<RouteObject> = [ { index: true, element: ( <Suspense> <Index /> </Suspense> ), }, { path: "*", element: ( <Suspense> <Notfound /> </Suspense> ), }, ]; export default routes; - shared/src/styles/tailwind.css (59 bytes)
@tailwind base; @tailwind components; @tailwind utilities;
- shared/src/styles/theme.ts (1245 bytes)
/* eslint-disable @typescript-eslint/unbound-method */ import { accordionAnatomy } from "@chakra-ui/anatomy"; import { createMultiStyleConfigHelpers, extendTheme } from "@chakra-ui/react"; const { definePartsStyle, defineMultiStyleConfig } = createMultiStyleConfigHelpers(accordionAnatomy.keys); const custom = definePartsStyle({ // panel: { // borderColor: "gray.600", // background: "gray.800", // }, container: { borderColor: "gray.700", background: "#161e33", }, root: { padding: "1.5rem", color: "#8f98b2", borderColor: "gray.700", borderWidth: "1px", background: "#161e33", borderRadius: "10", boxShadow: "0 10px 20px rgba(22,30,51,.1),0 1px 2px rgba(22,30,51,.1)", }, // icon: { // borderColor: "gray.600", // background: "gray.600", // color: "gray.400", // }, }); export const accordionTheme = defineMultiStyleConfig({ variants: { custom } }); export const theme = extendTheme({ styles: { global: { "html, body": { backgroundColor: "#090e1a", color: "rgb(40, 50, 77)", padding: "0 0 3rem", }, a: { color: "rgb(220, 36, 76)", }, }, }, components: { Accordion: accordionTheme, }, }); - shared/src/tracking-callbacks.ts (870 bytes)
const dateFormatter = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "short", }); export const sendSuccess = ({ type, data, timestamp, }: { type: string; data: unknown; timestamp?: number; }) => { console.log( `[trackEvent] 🚀 Sending '${type}' event with data:`, data, timestamp ? ` (${dateFormatter.format(new Date(timestamp))})` : "", ); }; export const dedupSuccess = (args: unknown[]) => { console.log("[deduplicate] 🚫 Ignoring duplicate event", args); }; export const queuedSuccess = (props: { type: string; data: unknown }) => { console.log("[trackEvent] 🚦 Queued event", props); }; export const flushSuccess = () => { console.log("[trackEvent] 🎉 Flushed all events"); }; export const flushFailure = (error: unknown) => { console.log("[trackEvent] 🎉 Error flushing events", error); }; - shared/src/tracking.tsx (1934 bytes)
import { sendSuccess } from "./tracking-callbacks"; /* * For this task, you'll be implementing a tracking system that logs events to the console. * * The `trackEvent` function should accept an object with two properties: * `type` - a string that can be either "navigation" or "click" * `data` - an object with any data that should be logged * `timestamp` - an optional number that represents the time the event was created * The function returns a promise that resolves after 1 second (representing an API call) * After the promise resolves, the `sendSuccess` function should be called with the `type`, `data`, and `timestamp` properties * We hope these are self-explanatory, but we're happy to answer any questions you might have! * * The user story is: * * 1. As a user, I want to track events so that I can analyze user behavior. * * 2. Before sending any events to the server, user consent should be granted by the user * by clicking on "Accept", and otherwise I want to queue them up and send them all at once * when the user grants consent. * * 3. Optional: I want to deduplicate events that are sent within 500ms of each other (to prevent RAGE clicks). */ type TrackEventProps = { type: "navigation" | "click"; data: Record<string, unknown>; }; type TrackEventTimestampProps = TrackEventProps & { timestamp: number }; /* * We're going to use this function below, and all available types defined here. The types and function signature should not be changed. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars const trackEvent = (props: TrackEventTimestampProps) => { return new Promise<void>((resolve) => { setTimeout(() => { resolve(); }, 1000); }).then(() => { sendSuccess(props); }); }; // eslint-disable-next-line @typescript-eslint/no-unused-vars type Tracking = { trackEvent: (_: TrackEventProps) => void | Promise<void>; onConsent: () => void; }; - shared/tailwind.config.js (167 bytes)
/** @type {import('tailwindcss').Config} */ export default { content: ["./index.html", "./src/**/*.{css,ts,tsx}"], theme: { extend: {}, }, plugins: [], }; - shared/tsconfig.json (710 bytes)
{ "compilerOptions": { "baseUrl": "./", "target": "ESNext", "useDefineForClassFields": true, "lib": ["DOM", "DOM.Iterable", "ESNext"], "allowJs": false, "skipLibCheck": true, "esModuleInterop": false, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "module": "ESNext", "moduleResolution": "Node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "sourceMap": true, "types": ["vite/client", "@total-typescript/ts-reset"], "paths": { "@/*": ["./src/*"] } }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] } - shared/tsconfig.node.json (264 bytes)
{ "compilerOptions": { "composite": true, "target": "ESNext", "module": "ESNext", "skipLibCheck": true, "strictNullChecks": true, "moduleResolution": "Node", "allowSyntheticDefaultImports": true }, "include": ["vite.config.ts"] } - shared/turbo.json (135 bytes)
{ "$schema": "https://turbo.build/schema.json", "tasks": { "build": { "outputs": ["dist/**"] }, "lint": {} } } - shared/vite.config.ts (605 bytes)
import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import mkcert from "vite-plugin-mkcert"; import tsPaths from "vite-tsconfig-paths"; export default defineConfig({ server: { https: {}, port: 5173, }, plugins: [ react(), mkcert({ source: "coding", }), tsPaths(), ], build: { cssMinify: "lightningcss", rollupOptions: { output: { manualChunks: { "react-vendor": ["react", "react-dom", "react-router-dom"], }, }, }, }, optimizeDeps: { include: ["react/jsx-runtime"], }, }); - solution/App.tsx (588 bytes)
import { Outlet, ScrollRestoration } from "react-router-dom"; import { ChakraProvider, GlobalStyle } from "@chakra-ui/react"; import useDebugRender from "tilg"; import { TrackingProvider } from "./TrackingProvider"; import { theme } from "./styles/theme"; import { CookieBanner } from "./components/CookieBanner"; export default function App() { useDebugRender(); return ( <ChakraProvider theme={theme}> <GlobalStyle /> <TrackingProvider> <Outlet /> <CookieBanner /> </TrackingProvider> <ScrollRestoration /> </ChakraProvider> ); } - solution/components/Content.tsx (1925 bytes)
import { ArrowForwardIcon } from "@chakra-ui/icons"; import { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, Box, Button, Text, } from "@chakra-ui/react"; export const Content = () => { return ( <Box margin="0 auto" maxWidth="75%"> <Accordion variant="custom"> <AccordionItem> <AccordionButton> <Box as="span" flex="1" textAlign="left"> <Text fontSize="xl" fontWeight="medium" color="#f0f3fa"> Cloud-Native Scalability & High-Availability </Text> </Box> <AccordionIcon /> </AccordionButton> <AccordionPanel pb={4}> <Text fontSize="sm" color="#f0f3fa"> Enterprise-grade Managed Cloud. Vertical and horizontal scaling and zero-downtime upgrades. </Text> <Button colorScheme="red" size="sm" variant="link" data-tracking> Qdrant Cloud <ArrowForwardIcon /> </Button> </AccordionPanel> </AccordionItem> <AccordionItem> <Text> <AccordionButton> <Box as="span" flex="1" textAlign="left" fontWeight="medium"> <Text fontSize="xl" color="#f0f3fa"> Ease of Use & Simple Deployment </Text> </Box> <AccordionIcon /> </AccordionButton> </Text> <AccordionPanel pb={4}> <Text fontSize="sm"> Quick deployment in any environment with Docker and a lean API for easy integration, ideal for local testing. </Text> <Button colorScheme="red" size="sm" variant="link" data-tracking> Quick Start Guide <ArrowForwardIcon /> </Button> </AccordionPanel> </AccordionItem> </Accordion> </Box> ); }; - solution/components/CookieBanner.tsx (2201 bytes)
import { useTracking } from "@/TrackingProvider"; import { Alert, AlertDescription, Button, useToast, Wrap, WrapItem, Text, ToastId, } from "@chakra-ui/react"; import { useEffect } from "react"; export const CookieBanner = () => { const toast = useToast(); const { trackEvent, onConsent } = useTracking(); useEffect(() => { let toastId: ToastId; const id = setTimeout(() => { toastId = toast({ render: (_props) => ( <Alert status="warning" gap={2}> <AlertDescription flex="0 1 auto"> <Text fontSize="sm"> We use cookies to learn more about you. At any time you can delete or block cookies through your browser settings. </Text> </AlertDescription> <Wrap spacing={2} flex="1 0 auto"> <WrapItem> <Button data-tracking variant="outline" colorScheme="yellow" size="xs" onClick={() => { return trackEvent({ type: "click", data: { action: "reject-cookies" }, // timestamp: Date.now(), }); }} > Reject </Button> </WrapItem> <WrapItem> <Button data-tracking variant="solid" colorScheme="green" size="xs" onClick={() => { onConsent(); return trackEvent({ type: "click", data: { action: "accept-cookies" }, // timestamp: Date.now(), }); }} > Accept </Button> </WrapItem> </Wrap> </Alert> ), status: "info", duration: null, isClosable: true, }); }, 1000); return () => { clearTimeout(id); toast.close(toastId); }; }); return null; }; - solution/components/HeroHeader.tsx (1342 bytes)
import { Box, Button, Text } from "@chakra-ui/react"; export const HeroHeader = () => { return ( <Box paddingTop="2rem" position="relative" background="url(https://qdrant.tech/img/stars-pattern.png)" textAlign="center" > <Box display="flex" justifyContent="center" flexDirection="column" alignItems="center" gap="4" padding="4rem 0 0" textAlign="center" maxWidth="100%" width="100%" > <Text fontSize="4xl" fontWeight="semibold" color="#f0f3fa"> High-Performance Vector Search at Scale </Text> <Text fontSize="lg" fontWeight="medium" color="#8f98b2" marginBottom="8" > Powering the next generation of AI applications with advanced, open-source vector similarity search technology. </Text> <Button data-tracking>Get started</Button> </Box> <img style={{ margin: "0 auto", display: "block", width: "100%", maxWidth: "1200px", height: "auto", top: "-10vh", position: "relative", pointerEvents: "none", }} src="https://qdrant.tech/img/hero-home-illustration-x1.png" /> </Box> ); }; - solution/global.ts (32 bytes)
import "@/styles/tailwind.css";
- solution/main.tsx (608 bytes)
import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import { createBrowserRouter, RouterProvider } from "react-router-dom"; import routes from "@/routes"; import App from "@/App"; import "@/global"; const container = document.getElementById("root") as HTMLElement; const root = createRoot(container); const router = createBrowserRouter([ { path: "/", element: <App />, children: routes, errorElement: <div>error</div>, }, ]); root.render( <StrictMode> <RouterProvider router={router} fallbackElement={<div>loading...</div>} /> </StrictMode>, ); - solution/pages/404.tsx (64 bytes)
export default function Notfound() { return <div>404</div>; } - solution/pages/index.tsx (209 bytes)
import { Content } from "@/components/Content"; import { HeroHeader } from "@/components/HeroHeader"; export default function Index() { return ( <> <HeroHeader /> <Content /> </> ); } - solution/routes.tsx (472 bytes)
import { lazy, Suspense } from "react"; import { type RouteObject } from "react-router-dom"; const Index = lazy(() => import("@/pages/index")); const Notfound = lazy(() => import("@/pages/404")); export const routes: Array<RouteObject> = [ { index: true, element: ( <Suspense> <Index /> </Suspense> ), }, { path: "*", element: ( <Suspense> <Notfound /> </Suspense> ), }, ]; export default routes; - solution/styles/tailwind.css (59 bytes)
@tailwind base; @tailwind components; @tailwind utilities;
- solution/styles/theme.ts (1245 bytes)
/* eslint-disable @typescript-eslint/unbound-method */ import { accordionAnatomy } from "@chakra-ui/anatomy"; import { createMultiStyleConfigHelpers, extendTheme } from "@chakra-ui/react"; const { definePartsStyle, defineMultiStyleConfig } = createMultiStyleConfigHelpers(accordionAnatomy.keys); const custom = definePartsStyle({ // panel: { // borderColor: "gray.600", // background: "gray.800", // }, container: { borderColor: "gray.700", background: "#161e33", }, root: { padding: "1.5rem", color: "#8f98b2", borderColor: "gray.700", borderWidth: "1px", background: "#161e33", borderRadius: "10", boxShadow: "0 10px 20px rgba(22,30,51,.1),0 1px 2px rgba(22,30,51,.1)", }, // icon: { // borderColor: "gray.600", // background: "gray.600", // color: "gray.400", // }, }); export const accordionTheme = defineMultiStyleConfig({ variants: { custom } }); export const theme = extendTheme({ styles: { global: { "html, body": { backgroundColor: "#090e1a", color: "rgb(40, 50, 77)", padding: "0 0 3rem", }, a: { color: "rgb(220, 36, 76)", }, }, }, components: { Accordion: accordionTheme, }, }); - solution/tracking-callbacks.ts (870 bytes)
const dateFormatter = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "short", }); export const sendSuccess = ({ type, data, timestamp, }: { type: string; data: unknown; timestamp?: number; }) => { console.log( `[trackEvent] 🚀 Sending '${type}' event with data:`, data, timestamp ? ` (${dateFormatter.format(new Date(timestamp))})` : "", ); }; export const dedupSuccess = (args: unknown[]) => { console.log("[deduplicate] 🚫 Ignoring duplicate event", args); }; export const queuedSuccess = (props: { type: string; data: unknown }) => { console.log("[trackEvent] 🚦 Queued event", props); }; export const flushSuccess = () => { console.log("[trackEvent] 🎉 Flushed all events"); }; export const flushFailure = (error: unknown) => { console.log("[trackEvent] 🎉 Error flushing events", error); }; - solution/TrackingProvider.tsx (2792 bytes)
import { createContext, ReactNode, useContext, useEffect, useState, } from "react"; import { dedupSuccess, flushFailure, flushSuccess, queuedSuccess, sendSuccess, } from "./tracking-callbacks"; type TrackEventProps = { type: "navigation" | "click"; data: Record<string, unknown>; }; const trackEvent = (props: TrackEventProps & { timestamp?: number }) => { return new Promise<void>((resolve) => { setTimeout(() => { resolve(); }, 1000); }).then(() => { sendSuccess(props); }); }; const deduplicate = <TArgs extends unknown[], TReturn>( callback: (...args: TArgs) => TReturn, delay = 500 ) => { const cache = new Map<string, number>(); return (...args: TArgs) => { const key = JSON.stringify(args); const now = Date.now(); if (cache.has(key)) { const lastNow = cache.get(key)!; console.log("[deduplicate] 🕒 Last event was", now - lastNow, "ms ago"); if (delay > now - lastNow) { dedupSuccess(args); cache.set(key, now); return; } cache.delete(key); } cache.set(key, now); return callback(...args); }; }; type Tracking = { trackEvent: (_: TrackEventProps) => void | Promise<void>; onConsent: () => void; }; const TrackingContext = createContext<Tracking>({ trackEvent: () => undefined, onConsent: () => undefined, }); export const TrackingProvider = ({ children }: { children: ReactNode }) => { const [hasConsent, setHasConsent] = useState(false); const [{ maybeTrackEvent, flush }] = useState(() => { const queue = new Set<TrackEventProps>(); let didFlush = false; return { // flush: async () => { // for (const props of queue) { // await trackEvent(props); // } // didFlush = true; // }, flush: async () => { const promises: Promise<void>[] = []; for (const props of queue) { promises.push(trackEvent(props)); } await Promise.all(promises); didFlush = true; }, maybeTrackEvent: deduplicate((props: TrackEventProps) => { const propsWithTimestamp = { ...props, timestamp: Date.now() }; if (didFlush) { return trackEvent(propsWithTimestamp); } queue.add(propsWithTimestamp); queuedSuccess(props); }), }; }); useEffect(() => { if (hasConsent) { flush().then(flushSuccess).catch(flushFailure); } }, [flush, hasConsent]); return ( <TrackingContext.Provider value={{ trackEvent: maybeTrackEvent, onConsent() { setHasConsent(true); }, }} > {children} </TrackingContext.Provider> ); }; export const useTracking = () => { return useContext(TrackingContext); };