@tscircuit/fake-snippets 0.0.119 → 0.0.120

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.
@@ -1,46 +1,50 @@
1
- import { useState } from "react"
1
+ import { useEffect, useState } from "react"
2
2
 
3
3
  interface UsePreviewImagesProps {
4
- packageName?: string
5
- fsMapHash?: string
4
+ cadPreviewUrl?: string | null
5
+ pcbPreviewUrl?: string | null
6
+ schematicPreviewUrl?: string | null
6
7
  }
7
8
 
8
9
  export function usePreviewImages({
9
- packageName,
10
- fsMapHash,
10
+ cadPreviewUrl,
11
+ pcbPreviewUrl,
12
+ schematicPreviewUrl,
11
13
  }: UsePreviewImagesProps) {
12
14
  const [imageStatus, setImageStatus] = useState<
13
15
  Record<string, "loading" | "loaded" | "error">
14
16
  >({
15
- "3d": "loading",
16
- pcb: "loading",
17
- schematic: "loading",
17
+ "3d": cadPreviewUrl ? "loading" : "error",
18
+ pcb: pcbPreviewUrl ? "loading" : "error",
19
+ schematic: schematicPreviewUrl ? "loading" : "error",
18
20
  })
19
21
 
22
+ useEffect(() => {
23
+ setImageStatus({
24
+ "3d": cadPreviewUrl ? "loading" : "error",
25
+ pcb: pcbPreviewUrl ? "loading" : "error",
26
+ schematic: schematicPreviewUrl ? "loading" : "error",
27
+ })
28
+ }, [cadPreviewUrl, pcbPreviewUrl, schematicPreviewUrl])
29
+
20
30
  const views = [
21
31
  {
22
32
  id: "3d",
23
33
  label: "3D View",
24
34
  backgroundClass: "bg-gray-100",
25
- imageUrl: packageName
26
- ? `https://api.tscircuit.com/packages/images/${packageName}/3d.png?fs_sha=${fsMapHash}`
27
- : undefined,
35
+ imageUrl: cadPreviewUrl ?? undefined,
28
36
  },
29
37
  {
30
38
  id: "pcb",
31
39
  label: "PCB View",
32
40
  backgroundClass: "bg-black",
33
- imageUrl: packageName
34
- ? `https://api.tscircuit.com/packages/images/${packageName}/pcb.png?fs_sha=${fsMapHash}`
35
- : undefined,
41
+ imageUrl: pcbPreviewUrl ?? undefined,
36
42
  },
37
43
  {
38
44
  id: "schematic",
39
45
  label: "Schematic View",
40
46
  backgroundClass: "bg-[#F5F1ED]",
41
- imageUrl: packageName
42
- ? `https://api.tscircuit.com/packages/images/${packageName}/schematic.png?fs_sha=${fsMapHash}`
43
- : undefined,
47
+ imageUrl: schematicPreviewUrl ?? undefined,
44
48
  },
45
49
  ]
46
50
 
@@ -59,6 +63,7 @@ export function usePreviewImages({
59
63
  }
60
64
 
61
65
  const availableViews = views
66
+ .filter((view) => Boolean(view.imageUrl))
62
67
  .map((view) => ({
63
68
  ...view,
64
69
  status: imageStatus[view.id],
@@ -88,6 +88,14 @@ export function useUpdatePackageFilesMutation({
88
88
  }
89
89
  }
90
90
  }
91
+
92
+ if (!currentPackage) {
93
+ await axios.post("/package_releases/update", {
94
+ package_name_with_version: newPackage.package_name_with_version,
95
+ ready_to_build: true,
96
+ })
97
+ }
98
+
91
99
  return updatedFilesCount
92
100
  },
93
101
  onSuccess: (updatedFilesCount) => {
@@ -0,0 +1,15 @@
1
+ import { Package } from "fake-snippets-api/lib/db/schema"
2
+
3
+ export const getPackagePreviewImageUrl = (
4
+ pkg: Package,
5
+ view: "pcb" | "schematic" | "3d" = "pcb",
6
+ ) => {
7
+ switch (view) {
8
+ case "schematic":
9
+ return pkg.latest_sch_preview_image_url
10
+ case "3d":
11
+ return pkg.latest_cad_preview_image_url
12
+ default:
13
+ return pkg.latest_pcb_preview_image_url
14
+ }
15
+ }
@@ -168,7 +168,6 @@ export const DashboardPage = () => {
168
168
  <PackageCard
169
169
  key={pkg.package_id}
170
170
  pkg={pkg}
171
- baseUrl={baseUrl}
172
171
  isCurrentUserPackage={
173
172
  pkg.owner_github_username === currentUser
174
173
  }
@@ -8,6 +8,11 @@ export const EditorPage = () => {
8
8
  const { packageInfo: pkg, error } = useCurrentPackageInfo()
9
9
 
10
10
  const projectUrl = pkg ? `https://tscircuit.com/${pkg.name}` : undefined
11
+ const previewImageUrl =
12
+ pkg?.latest_pcb_preview_image_url ??
13
+ pkg?.latest_sch_preview_image_url ??
14
+ pkg?.latest_cad_preview_image_url ??
15
+ undefined
11
16
 
12
17
  return (
13
18
  <div className="overflow-x-hidden">
@@ -21,15 +26,13 @@ export const EditorPage = () => {
21
26
  property="og:title"
22
27
  content={`${pkg.unscoped_name} - tscircuit`}
23
28
  />
24
- <meta
25
- property="og:image"
26
- content={`https://api.tscircuit.com/packages/images/${pkg.owner_github_username}/${pkg.unscoped_name}/pcb.png?fs_sha=${pkg.latest_package_release_fs_sha}`}
27
- />
28
- <meta name="twitter:card" content="summary_large_image" />
29
- <meta
30
- name="twitter:image"
31
- content={`https://api.tscircuit.com/packages/images/${pkg.owner_github_username}/${pkg.unscoped_name}/pcb.png?fs_sha=${pkg.latest_package_release_fs_sha}`}
32
- />
29
+ {previewImageUrl && (
30
+ <>
31
+ <meta property="og:image" content={previewImageUrl} />
32
+ <meta name="twitter:card" content="summary_large_image" />
33
+ <meta name="twitter:image" content={previewImageUrl} />
34
+ </>
35
+ )}
33
36
  </>
34
37
  )}
35
38
  </Helmet>
@@ -150,7 +150,6 @@ export const OrganizationProfilePageContent = ({
150
150
  <PackageCard
151
151
  key={pkg.package_id}
152
152
  pkg={pkg}
153
- baseUrl={baseUrl}
154
153
  showOwner={false}
155
154
  isCurrentUserPackage={isCurrentUserOrganization}
156
155
  />
@@ -12,6 +12,12 @@ export const EditorPage = () => {
12
12
  /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/,
13
13
  )
14
14
 
15
+ const previewImageUrl =
16
+ pkg?.latest_pcb_preview_image_url ??
17
+ pkg?.latest_sch_preview_image_url ??
18
+ pkg?.latest_cad_preview_image_url ??
19
+ undefined
20
+
15
21
  return (
16
22
  <div className="flex flex-col h-screen overflow-x-hidden">
17
23
  <Helmet>
@@ -22,15 +28,13 @@ export const EditorPage = () => {
22
28
  property="og:title"
23
29
  content={`${pkg.unscoped_name} - tscircuit`}
24
30
  />
25
- <meta
26
- property="og:image"
27
- content={`https://api.tscircuit.com/packages/images/${pkg.owner_github_username}/${pkg.unscoped_name}/pcb.png?fs_sha=${pkg.latest_package_release_fs_sha}`}
28
- />
29
- <meta name="twitter:card" content="summary_large_image" />
30
- <meta
31
- name="twitter:image"
32
- content={`https://api.tscircuit.com/packages/images/${pkg.owner_github_username}/${pkg.unscoped_name}/pcb.png?fs_sha=${pkg.latest_package_release_fs_sha}`}
33
- />
31
+ {previewImageUrl && (
32
+ <>
33
+ <meta property="og:image" content={previewImageUrl} />
34
+ <meta name="twitter:card" content="summary_large_image" />
35
+ <meta name="twitter:image" content={previewImageUrl} />
36
+ </>
37
+ )}
34
38
  </>
35
39
  )}
36
40
  </Helmet>
@@ -281,7 +281,6 @@ export const UserProfilePage = () => {
281
281
  <PackageCard
282
282
  key={pkg.package_id}
283
283
  pkg={pkg}
284
- baseUrl={baseUrl}
285
284
  showOwner={activeTab === "starred"}
286
285
  isCurrentUserPackage={
287
286
  isCurrentUserProfile && activeTab === "all"