@@ -20,11 +20,13 @@ import {
2020} from "@/client/components/Tooltip" ;
2121import { useTheme } from "@/client/contexts/theme" ;
2222import { defaultCode } from "@/client/snippets" ;
23+ import { examples } from "@/examples" ;
2324import type {
2425ParameterWithSource ,
2526PreviewOutput ,
2627WorkspaceOwner ,
2728} from "@/gen/types" ;
29+ import { mockUsers } from "@/owner" ;
2830import { rpc } from "@/utils/rpc" ;
2931import {
3032type WasmLoadState ,
@@ -36,7 +38,6 @@ import { MoonIcon, ShareIcon, SunIcon, SunMoonIcon } from "lucide-react";
3638import { type FC , useEffect , useMemo , useRef , useState } from "react" ;
3739import { type LoaderFunctionArgs , useLoaderData } from "react-router" ;
3840import { useDebouncedValue } from "./hooks/debounce" ;
39- import { mockUsers } from "@/owner" ;
4041
4142/**
4243 * Load the shared code if present.
@@ -67,7 +68,9 @@ export const App = () => {
6768return "loading" ;
6869} ) ;
6970const loadedCode = useLoaderData < typeof loader > ( ) ;
70- const [ code , setCode ] = useState ( loadedCode ?? defaultCode ) ;
71+ const [ code , setCode ] = useState (
72+ loadedCode ?? window . EXAMPLE_CODE ?? defaultCode ,
73+ ) ;
7174const [ debouncedCode , isDebouncing ] = useDebouncedValue ( code , 1000 ) ;
7275const [ parameterValues , setParameterValues ] = useState <
7376Record < string , string >
@@ -203,14 +206,7 @@ export const App = () => {
203206>
204207Docs
205208</ a >
206- < a
207- href = "https://coder.com"
208- target = "_blank"
209- rel = "noreferrer"
210- className = "font-light text-content-secondary text-sm hover:text-content-primary"
211- >
212- Support
213- </ a >
209+ < ExampleSelector />
214210< ThemeSelector />
215211</ div >
216212</ nav >
@@ -330,3 +326,31 @@ const ShareButton: FC<ShareButtonProps> = ({ code }) => {
330326</ Tooltip >
331327) ;
332328} ;
329+
330+ const ExampleSelector : FC = ( ) => {
331+ return (
332+ < DropdownMenu >
333+ < DropdownMenuTrigger className = "font-light text-content-secondary text-sm hover:text-content-primary" >
334+ Examples
335+ </ DropdownMenuTrigger >
336+
337+ < DropdownMenuPortal >
338+ < DropdownMenuContent >
339+ { examples . map ( ( { title, slug } ) => {
340+ const params = new URLSearchParams ( ) ;
341+ params . append ( "example" , slug ) ;
342+
343+ const href = `${ window . location . origin } /parameters?${ params . toString ( ) } ` ;
344+ return (
345+ < DropdownMenuItem key = { slug } asChild = { true } >
346+ < a href = { href } target = "_blank" rel = "noreferrer" >
347+ { title }
348+ </ a >
349+ </ DropdownMenuItem >
350+ ) ;
351+ } ) }
352+ </ DropdownMenuContent >
353+ </ DropdownMenuPortal >
354+ </ DropdownMenu >
355+ ) ;
356+ } ;
0 commit comments