-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(swc-plugins): Provide some UI (#55)
- Loading branch information
Showing
11 changed files
with
183 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "@/components/ui/select"; | ||
import { apiClient } from "@/lib/trpc/web-client"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
export default function Home() { | ||
const [runtimes] = apiClient.runtime.list.useSuspenseQuery(); | ||
|
||
const [selectedRuntime, setSelectedRuntime] = useState<bigint>(); | ||
|
||
return ( | ||
<div className="flex w-full max-w-md flex-col space-y-4"> | ||
<div className="flex space-x-4"> | ||
<Select onValueChange={(e) => setSelectedRuntime(BigInt(e))}> | ||
<SelectTrigger className="w-[180px]"> | ||
<SelectValue placeholder="Select runtime" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{runtimes.map((runtime) => ( | ||
<SelectItem | ||
key={runtime.id.toString()} | ||
value={runtime.id.toString()} | ||
> | ||
{runtime.name} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
|
||
{selectedRuntime && <VersionSelector runtimeId={selectedRuntime} />} | ||
</div> | ||
<div className="flex justify-center"> | ||
<Link href={`/versions/range`} passHref> | ||
<Button | ||
variant="secondary" | ||
size="default" | ||
className="whitespace-nowrap" | ||
> | ||
See all versions | ||
</Button> | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function VersionSelector({ runtimeId }: { runtimeId: bigint }) { | ||
const router = useRouter(); | ||
const versions = apiClient.runtime.listVersions.useQuery({ | ||
runtimeId, | ||
}); | ||
|
||
return ( | ||
<Select | ||
onValueChange={(e) => { | ||
const selected = versions.data?.find((v) => v.version === e); | ||
router.push(`/versions/range/${selected?.compatRangeId}`); | ||
}} | ||
> | ||
<SelectTrigger className="w-[120px]"> | ||
<SelectValue placeholder="Version" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{versions.data?.map((version) => ( | ||
<SelectItem key={version.version} value={version.version}> | ||
{version.version} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createCaller } from "@/lib/server"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function Page({ | ||
params: { version }, | ||
}: { | ||
params: { version: string }; | ||
}) { | ||
const api = await createCaller(); | ||
const compatRange = await api.compatRange.byCoreVersion({ | ||
version, | ||
}); | ||
|
||
if (compatRange) { | ||
return redirect(`/compat/range/${compatRange.id}`); | ||
} | ||
|
||
return <div>No compat range found for swc_core@{version}</div>; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use client"; | ||
|
||
import { ReactNode, useEffect, useState } from "react"; | ||
|
||
export const Dynamic = ({ children }: { children: ReactNode }) => { | ||
const [hasMounted, setHasMounted] = useState(false); | ||
|
||
useEffect(() => { | ||
setHasMounted(true); | ||
}, []); | ||
|
||
if (!hasMounted) { | ||
return null; | ||
} | ||
|
||
return <>{children} </>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { publicProcedure, router } from "@/lib/base"; | ||
import { db } from "@/lib/prisma"; | ||
import { z } from "zod"; | ||
|
||
export const runtimeRouter = router({ | ||
list: publicProcedure | ||
.input(z.void()) | ||
.output( | ||
z.array( | ||
z.object({ | ||
id: z.bigint(), | ||
name: z.string(), | ||
}) | ||
) | ||
) | ||
.query(async () => { | ||
const runtimes = await db.swcRuntime.findMany({ | ||
select: { | ||
id: true, | ||
name: true, | ||
}, | ||
}); | ||
|
||
return runtimes; | ||
}), | ||
|
||
listVersions: publicProcedure | ||
.input( | ||
z.object({ | ||
runtimeId: z.bigint(), | ||
}) | ||
) | ||
.output( | ||
z.array( | ||
z.object({ | ||
version: z.string(), | ||
compatRangeId: z.bigint(), | ||
}) | ||
) | ||
) | ||
.query(async ({ input: { runtimeId } }) => { | ||
const versions = await db.swcRuntimeVersion.findMany({ | ||
where: { | ||
runtimeId, | ||
}, | ||
select: { | ||
version: true, | ||
compatRangeId: true, | ||
}, | ||
}); | ||
|
||
return versions; | ||
}), | ||
}); |