Skip to content

Commit

Permalink
Merge pull request #13 from tscircuit/format-repo
Browse files Browse the repository at this point in the history
Format Repo, add vercel rewrites, minor fixes
  • Loading branch information
seveibar authored Oct 5, 2024
2 parents b4a922f + 27fce5a commit 9185738
Show file tree
Hide file tree
Showing 58 changed files with 245 additions and 202 deletions.
2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"lib": "@/lib",
"hooks": "@/hooks"
}
}
}
28 changes: 21 additions & 7 deletions fake-snippets-api/lib/db/db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { createStore, type StoreApi } from "zustand/vanilla"
import { immer } from "zustand/middleware/immer"
import { hoist, type HoistedStoreApi } from "zustand-hoist"

import { databaseSchema, Snippet, Session, LoginPage, Account, type DatabaseSchema } from "./schema.ts"
import {
databaseSchema,
Snippet,
Session,
LoginPage,
Account,
type DatabaseSchema,
} from "./schema.ts"
import { combine } from "zustand/middleware"

export const createDatabase = () => {
Expand Down Expand Up @@ -89,12 +96,16 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
}))
return newSession
},
getSessions: ({ account_id, is_cli_session }: { account_id: string, is_cli_session?: boolean }): Session[] => {
getSessions: ({
account_id,
is_cli_session,
}: { account_id: string; is_cli_session?: boolean }): Session[] => {
const state = get()
return state.sessions.filter(
(session) =>
session.account_id === account_id &&
(is_cli_session === undefined || session.is_cli_session === is_cli_session)
(session) =>
session.account_id === account_id &&
(is_cli_session === undefined ||
session.is_cli_session === is_cli_session),
)
},
createLoginPage: (): LoginPage => {
Expand All @@ -115,10 +126,13 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
const state = get()
return state.loginPages.find((lp) => lp.login_page_id === login_page_id)
},
updateLoginPage: (login_page_id: string, updates: Partial<LoginPage>): void => {
updateLoginPage: (
login_page_id: string,
updates: Partial<LoginPage>,
): void => {
set((state) => ({
loginPages: state.loginPages.map((lp) =>
lp.login_page_id === login_page_id ? { ...lp, ...updates } : lp
lp.login_page_id === login_page_id ? { ...lp, ...updates } : lp,
),
}))
},
Expand Down
2 changes: 0 additions & 2 deletions fake-snippets-api/lib/middleware/with-session-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const withSessionAuth: Middleware<

const token = req.headers.get("authorization")?.split("Bearer ")?.[1]

console.log("token", token)

if (!token) {
return ctx.error(401, {
error_code: "no_token",
Expand Down
4 changes: 3 additions & 1 deletion fake-snippets-api/routes/api/snippets/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default withRouteSpec({
jsonBody: z.any().optional(),
jsonResponse: z.object({
ok: z.boolean(),
snippet: snippetSchema.extend({ snippet_type: z.enum(["board", "package", "model", "footprint"]) }),
snippet: snippetSchema.extend({
snippet_type: z.enum(["board", "package", "model", "footprint"]),
}),
}),
})(async (req, ctx) => {
const { snippet_id, name, owner_name, unscoped_name } = req.commonParams
Expand Down
2 changes: 1 addition & 1 deletion fake-snippets-api/tests/fixtures/get-test-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getTestServer = async (): Promise<TestFixture> => {
})

afterEach(async () => {
if (server && typeof server.stop === 'function') {
if (server && typeof server.stop === "function") {
await server.stop()
}
// Here you might want to add logic to drop the test database
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build": "bun run build:fake-api && tsc -b && vite build",
"preview": "vite preview",
"format": "biome format --write .",
"lint": "biome check .",
"lint": "biome format .",
"build:fake-api": "winterspec bundle -o dist/bundle.js"
},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions src/components/HeaderDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button } from "@/components/ui/button";
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { ChevronDown } from "lucide-react";
} from "@/components/ui/dropdown-menu"
import { ChevronDown } from "lucide-react"

export default function HeaderDropdown() {
const blankTemplates = [
Expand All @@ -17,7 +17,7 @@ export default function HeaderDropdown() {
},
{ name: "Blank 3D Model", type: "model", badgeColor: "bg-purple-500 " },
{ name: "Blank Footprint", type: "footprint", badgeColor: "bg-pink-500 " },
];
]

return (
<DropdownMenu>
Expand Down Expand Up @@ -46,5 +46,5 @@ export default function HeaderDropdown() {
))}
</DropdownMenuContent>
</DropdownMenu>
);
)
}
19 changes: 12 additions & 7 deletions src/components/LandingHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import {
Bot,
} from "lucide-react"
import { CreateNewSnippetHero } from "./CreateNewSnippetHero"
import { Link } from "wouter"
import { Link, useLocation } from "wouter"
import { TypeBadge } from "./TypeBadge"

export const LandingHero = () => {
const [, setLocation] = useLocation()
return (
<div className="p-6">
<CreateNewSnippetHero />
Expand Down Expand Up @@ -63,7 +64,7 @@ export const LandingHero = () => {

<div className="grid grid-cols-4 gap-4">
<div>
<Link href="/quickstart?template=blank-circuit-board">
<Link href="/editor?template=blank-circuit-board">
<Button className="w-full justify-between mb-2 px-2">
Create new <TypeBadge type="board" className="ml-2" />
</Button>
Expand All @@ -74,7 +75,7 @@ export const LandingHero = () => {
</p>
</div>
<div>
<Link href="/quickstart?template=blank-circuit-module">
<Link href="/editor?template=blank-circuit-module">
<Button className="w-full justify-between mb-2 px-2">
Create new <TypeBadge type="package" className="ml-2" />
</Button>
Expand All @@ -85,7 +86,7 @@ export const LandingHero = () => {
</p>
</div>
<div>
<Link href="/quickstart?template=blank-footprint">
<Link href="/editor?template=blank-footprint">
<Button className="w-full justify-between mb-2 px-2">
Create new <TypeBadge type="footprint" className="ml-2" />
</Button>
Expand All @@ -96,7 +97,7 @@ export const LandingHero = () => {
</p>
</div>
<div>
<Link href="/quickstart?template=blank-3d-model">
<Link href="/editor?template=blank-3d-model">
<Button className="w-full justify-between mb-2 px-2">
Create new <TypeBadge type="model" className="ml-2" />
</Button>
Expand All @@ -106,8 +107,12 @@ export const LandingHero = () => {
</p>
</div>
</div>
<Button variant="outline" className="mt-4">
<span className="mr-2">📄</span> View more templates
<Button
onClick={() => setLocation("/quickstart")}
variant="outline"
className="mt-4"
>
<span className="mr-2">📄</span> More Templates
</Button>
</div>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/ViewSnippetSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export default function ViewSnippetSidebar({
<div className="space-y-1">
<div className="text-xs font-medium">Copy import code</div>
<div className="text-[0.5em] p-2 rounded-sm bg-blue-50 border border-blue-200 cursor-pointer font-mono whitespace-nowrap overflow-hidden text-ellipsis">
import CircuitModule from "@tsci/{snippet?.owner_name}.{snippet?.unscoped_name}"
import CircuitModule from "@tsci/{snippet?.owner_name}.
{snippet?.unscoped_name}"
</div>
</div>
<div className="space-y-1">
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const AccordionTrigger = React.forwardRef<
ref={ref}
className={cn(
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
className
className,
)}
{...props}
>
Expand Down
10 changes: 5 additions & 5 deletions src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AlertDialogOverlay = React.forwardRef<
<AlertDialogPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
className,
)}
{...props}
ref={ref}
Expand All @@ -35,7 +35,7 @@ const AlertDialogContent = React.forwardRef<
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-slate-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-slate-800 dark:bg-slate-950",
className
className,
)}
{...props}
/>
Expand All @@ -50,7 +50,7 @@ const AlertDialogHeader = ({
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className
className,
)}
{...props}
/>
Expand All @@ -64,7 +64,7 @@ const AlertDialogFooter = ({
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
className,
)}
{...props}
/>
Expand Down Expand Up @@ -117,7 +117,7 @@ const AlertDialogCancel = React.forwardRef<
className={cn(
buttonVariants({ variant: "outline" }),
"mt-2 sm:mt-0",
className
className,
)}
{...props}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const alertVariants = cva(
defaultVariants: {
variant: "default",
},
}
},
)

const Alert = React.forwardRef<
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Avatar = React.forwardRef<
ref={ref}
className={cn(
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
className
className,
)}
{...props}
/>
Expand All @@ -38,7 +38,7 @@ const AvatarFallback = React.forwardRef<
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800",
className
className,
)}
{...props}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const badgeVariants = cva(
defaultVariants: {
variant: "default",
},
}
},
)

export interface BadgeProps
Expand Down
7 changes: 5 additions & 2 deletions src/components/ui/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const BreadcrumbList = React.forwardRef<
ref={ref}
className={cn(
"flex flex-wrap items-center gap-1.5 break-words text-sm text-slate-500 sm:gap-2.5 dark:text-slate-400",
className
className,
)}
{...props}
/>
Expand Down Expand Up @@ -50,7 +50,10 @@ const BreadcrumbLink = React.forwardRef<
return (
<Comp
ref={ref}
className={cn("transition-colors hover:text-slate-950 dark:hover:text-slate-50", className)}
className={cn(
"transition-colors hover:text-slate-950 dark:hover:text-slate-50",
className,
)}
{...props}
/>
)
Expand Down
7 changes: 4 additions & 3 deletions src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const buttonVariants = cva(
"border border-slate-200 bg-white shadow-sm hover:bg-slate-100 hover:text-slate-900 dark:border-slate-800 dark:bg-slate-950 dark:hover:bg-slate-800 dark:hover:text-slate-50",
secondary:
"bg-slate-100 text-slate-900 shadow-sm hover:bg-slate-100/80 dark:bg-slate-800 dark:text-slate-50 dark:hover:bg-slate-800/80",
ghost: "hover:bg-slate-100 hover:text-slate-900 dark:hover:bg-slate-800 dark:hover:text-slate-50",
ghost:
"hover:bg-slate-100 hover:text-slate-900 dark:hover:bg-slate-800 dark:hover:text-slate-50",
link: "text-slate-900 underline-offset-4 hover:underline dark:text-slate-50",
},
size: {
Expand All @@ -31,7 +32,7 @@ const buttonVariants = cva(
variant: "default",
size: "default",
},
}
},
)

export interface ButtonProps
Expand All @@ -50,7 +51,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
{...props}
/>
)
}
},
)
Button.displayName = "Button"

Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Card = React.forwardRef<
ref={ref}
className={cn(
"rounded-xl border border-slate-200 bg-white text-slate-950 shadow dark:border-slate-800 dark:bg-slate-950 dark:text-slate-50",
className
className,
)}
{...props}
/>
Expand Down
Loading

0 comments on commit 9185738

Please sign in to comment.