@tscircuit/fake-snippets 0.0.70 → 0.0.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/generated-index.js +77 -3
- package/bun-tests/fake-snippets-api/routes/accounts/get.test.ts +53 -0
- package/dist/bundle.js +14 -3
- package/fake-snippets-api/routes/api/accounts/get.ts +16 -3
- package/index.html +3 -0
- package/package.json +1 -1
- package/src/ContextProviders.tsx +2 -0
- package/src/components/HeaderLogin.tsx +2 -2
- package/src/lib/populate-query-cache-with-ssr-data.ts +52 -0
- package/src/pages/dashboard.tsx +2 -2
- package/src/pages/landing.tsx +14 -3
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
|
|
2
2
|
import { z } from "zod"
|
|
3
|
-
import { accountSchema } from "fake-snippets-api/lib/db/schema"
|
|
3
|
+
import { Account, accountSchema } from "fake-snippets-api/lib/db/schema"
|
|
4
4
|
|
|
5
5
|
export default withRouteSpec({
|
|
6
|
-
methods: ["GET"],
|
|
6
|
+
methods: ["GET", "POST"],
|
|
7
7
|
auth: "session",
|
|
8
|
+
jsonBody: z.object({
|
|
9
|
+
github_username: z.string(),
|
|
10
|
+
}),
|
|
8
11
|
jsonResponse: z.object({
|
|
9
12
|
account: accountSchema,
|
|
10
13
|
}),
|
|
11
14
|
})(async (req, ctx) => {
|
|
12
|
-
|
|
15
|
+
let account: Account | undefined
|
|
16
|
+
|
|
17
|
+
if (req.method === "POST") {
|
|
18
|
+
const { github_username } = req.jsonBody
|
|
19
|
+
account = ctx.db.accounts.find(
|
|
20
|
+
(acc: Account) => acc.github_username === github_username,
|
|
21
|
+
)
|
|
22
|
+
} else {
|
|
23
|
+
account = ctx.db.getAccount(ctx.auth.account_id)
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
if (!account) {
|
|
14
27
|
return ctx.error(404, {
|
|
15
28
|
error_code: "account_not_found",
|
package/index.html
CHANGED
package/package.json
CHANGED
package/src/ContextProviders.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { useEffect } from "react"
|
|
|
4
4
|
import { useGlobalStore } from "./hooks/use-global-store"
|
|
5
5
|
import { posthog } from "./lib/posthog"
|
|
6
6
|
import { Toaster } from "react-hot-toast"
|
|
7
|
+
import { populateQueryCacheWithSSRData } from "./lib/populate-query-cache-with-ssr-data"
|
|
7
8
|
|
|
8
9
|
const staffGithubUsernames = [
|
|
9
10
|
"imrishabh18",
|
|
@@ -13,6 +14,7 @@ const staffGithubUsernames = [
|
|
|
13
14
|
]
|
|
14
15
|
|
|
15
16
|
const queryClient = new QueryClient()
|
|
17
|
+
populateQueryCacheWithSSRData(queryClient)
|
|
16
18
|
|
|
17
19
|
const isInternalGithubUser = (githubUsername?: string | null) => {
|
|
18
20
|
if (!githubUsername) return false
|
|
@@ -23,7 +23,7 @@ export const HeaderLogin = () => {
|
|
|
23
23
|
return (
|
|
24
24
|
<div className="flex items-center md:space-x-2 justify-end">
|
|
25
25
|
<Button onClick={() => signIn()} variant="ghost">
|
|
26
|
-
Log
|
|
26
|
+
Log In
|
|
27
27
|
</Button>
|
|
28
28
|
<Button onClick={() => signIn()}>Get Started</Button>
|
|
29
29
|
</div>
|
|
@@ -68,7 +68,7 @@ export const HeaderLogin = () => {
|
|
|
68
68
|
</DropdownMenuItem>
|
|
69
69
|
<DropdownMenuItem asChild onClick={() => setSession(null)}>
|
|
70
70
|
<a href="/" className="cursor-pointer">
|
|
71
|
-
Sign
|
|
71
|
+
Sign Out
|
|
72
72
|
</a>
|
|
73
73
|
</DropdownMenuItem>
|
|
74
74
|
</DropdownMenuContent>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { QueryClient } from "react-query"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Populates React Query cache with SSR data to prevent unnecessary API calls
|
|
5
|
+
* on initial page load. Should be called after QueryClient creation.
|
|
6
|
+
*/
|
|
7
|
+
export function populateQueryCacheWithSSRData(queryClient: QueryClient) {
|
|
8
|
+
if (typeof window === "undefined") return
|
|
9
|
+
|
|
10
|
+
const ssrPackage = (window as any).SSR_PACKAGE
|
|
11
|
+
const ssrPackageRelease = (window as any).SSR_PACKAGE_RELEASE
|
|
12
|
+
const ssrPackageFiles = (window as any).SSR_PACKAGE_FILES
|
|
13
|
+
|
|
14
|
+
if (ssrPackage) {
|
|
15
|
+
// Cache package data with all possible query keys
|
|
16
|
+
queryClient.setQueryData(["package", ssrPackage.package_id], ssrPackage)
|
|
17
|
+
queryClient.setQueryData(["package", ssrPackage.name], ssrPackage)
|
|
18
|
+
queryClient.setQueryData(["packages", ssrPackage.package_id], ssrPackage)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (ssrPackageRelease && ssrPackage) {
|
|
22
|
+
// Cache package release with various query patterns
|
|
23
|
+
queryClient.setQueryData(
|
|
24
|
+
[
|
|
25
|
+
"packageRelease",
|
|
26
|
+
{ package_id: ssrPackage.package_id, is_latest: true },
|
|
27
|
+
],
|
|
28
|
+
ssrPackageRelease,
|
|
29
|
+
)
|
|
30
|
+
queryClient.setQueryData(
|
|
31
|
+
["packageRelease", { package_name: ssrPackage.name, is_latest: true }],
|
|
32
|
+
ssrPackageRelease,
|
|
33
|
+
)
|
|
34
|
+
if (ssrPackageRelease.package_release_id) {
|
|
35
|
+
queryClient.setQueryData(
|
|
36
|
+
[
|
|
37
|
+
"packageRelease",
|
|
38
|
+
{ package_release_id: ssrPackageRelease.package_release_id },
|
|
39
|
+
],
|
|
40
|
+
ssrPackageRelease,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Cache package files if available
|
|
45
|
+
if (ssrPackageFiles && ssrPackageRelease.package_release_id) {
|
|
46
|
+
queryClient.setQueryData(
|
|
47
|
+
["packageFiles", ssrPackageRelease.package_release_id],
|
|
48
|
+
ssrPackageFiles,
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/pages/dashboard.tsx
CHANGED
|
@@ -94,10 +94,10 @@ export const DashboardPage = () => {
|
|
|
94
94
|
</h2>
|
|
95
95
|
|
|
96
96
|
<p className="text-gray-600 mb-6 text-center max-w-md text-sm sm:text-base">
|
|
97
|
-
Log in to access your dashboard and manage your
|
|
97
|
+
Log in to access your dashboard and manage your packages.
|
|
98
98
|
</p>
|
|
99
99
|
<Button onClick={() => signIn()} variant="outline">
|
|
100
|
-
Log
|
|
100
|
+
Log In
|
|
101
101
|
</Button>
|
|
102
102
|
</div>
|
|
103
103
|
) : (
|
package/src/pages/landing.tsx
CHANGED
|
@@ -60,16 +60,27 @@ export function LandingPage() {
|
|
|
60
60
|
</p>
|
|
61
61
|
</div>
|
|
62
62
|
<div className="flex flex-col items-center gap-2 min-[500px]:flex-row">
|
|
63
|
-
<a
|
|
64
|
-
|
|
63
|
+
<a
|
|
64
|
+
href="https://docs.tscircuit.com"
|
|
65
|
+
className="w-[70vw] min-[500px]:w-auto"
|
|
66
|
+
>
|
|
67
|
+
<Button
|
|
68
|
+
size="lg"
|
|
69
|
+
aria-label="Get started with TSCircuit"
|
|
70
|
+
className="w-full min-[500px]:w-auto"
|
|
71
|
+
>
|
|
65
72
|
Get Started
|
|
66
73
|
</Button>
|
|
67
74
|
</a>
|
|
68
|
-
<PrefetchPageLink
|
|
75
|
+
<PrefetchPageLink
|
|
76
|
+
href="/seveibar/usb-c-flashlight#3d"
|
|
77
|
+
className="w-[70vw] min-[500px]:w-auto"
|
|
78
|
+
>
|
|
69
79
|
<Button
|
|
70
80
|
size="lg"
|
|
71
81
|
variant="outline"
|
|
72
82
|
aria-label="Open online example of TSCircuit"
|
|
83
|
+
className="w-full min-[500px]:w-auto"
|
|
73
84
|
>
|
|
74
85
|
Open Online Example
|
|
75
86
|
</Button>
|