@tscircuit/fake-snippets 0.0.73 → 0.0.74

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.
@@ -2,7 +2,6 @@ import type { Package } from "fake-snippets-api/lib/db/schema"
2
2
  import { useMutation } from "react-query"
3
3
  import { useAxios } from "./use-axios"
4
4
  import { useGlobalStore } from "./use-global-store"
5
- import { useUrlParams } from "./use-url-params"
6
5
 
7
6
  export const useCreatePackageMutation = ({
8
7
  onSuccess,
@@ -42,13 +41,7 @@ export const useCreatePackageMutation = ({
42
41
  },
43
42
  {
44
43
  onSuccess: (pkg: Package) => {
45
- const url = new URL(window.location.href)
46
- url.searchParams.set("package_id", pkg.package_id)
47
- url.searchParams.delete("template")
48
- url.searchParams.delete("should_create_package")
49
- window.history.pushState({}, "", url.toString())
50
44
  onSuccess?.(pkg)
51
- window.dispatchEvent(new Event("popstate"))
52
45
  },
53
46
  onError: (error: any) => {
54
47
  console.error("Error creating package:", error)
@@ -0,0 +1,28 @@
1
+ import { useParams } from "wouter"
2
+ import { useCurrentPackageId } from "./use-current-package-id"
3
+ import { useUrlParams } from "./use-url-params"
4
+ import { usePackageRelease } from "./use-package-release"
5
+
6
+ export const useCurrentPackageRelease = () => {
7
+ const { packageId } = useCurrentPackageId()
8
+ const urlParams = useUrlParams()
9
+ const { author, packageName } = useParams()
10
+
11
+ const version = urlParams.version
12
+ const releaseId = urlParams.package_release_id
13
+
14
+ let query: Parameters<typeof usePackageRelease>[0] | null = null
15
+
16
+ if (releaseId) {
17
+ query = { package_release_id: releaseId }
18
+ } else if (version && author && packageName) {
19
+ query = { package_name_with_version: `${author}/${packageName}@${version}` }
20
+ } else if (author && packageName) {
21
+ query = { package_name: `${author}/${packageName}`, is_latest: true }
22
+ } else if (packageId) {
23
+ query = { package_id: packageId, is_latest: true }
24
+ }
25
+
26
+ const { data: packageRelease, ...rest } = usePackageRelease(query)
27
+ return { packageRelease, ...rest }
28
+ }
@@ -91,7 +91,31 @@ export function useFileManagement({
91
91
  })
92
92
  },
93
93
  })
94
- const createPackageMutation = useCreatePackageMutation()
94
+ const createPackageMutation = useCreatePackageMutation({
95
+ onSuccess: (newPackage) => {
96
+ createRelease(
97
+ {
98
+ package_name_with_version: `${newPackage.name}@latest`,
99
+ },
100
+ {
101
+ onSuccess: () => {
102
+ updatePackageFilesMutation.mutate({
103
+ package_name_with_version: `${newPackage.name}@latest`,
104
+ ...newPackage,
105
+ })
106
+ const url = new URL(window.location.href)
107
+ url.searchParams.set("package_id", newPackage.package_id)
108
+ url.searchParams.delete("template")
109
+ url.searchParams.delete("should_create_package")
110
+ window.history.pushState({}, "", url.toString())
111
+ window.dispatchEvent(new Event("popstate"))
112
+ updateLastUpdated()
113
+ setInitialFiles([...localFiles])
114
+ },
115
+ },
116
+ )
117
+ },
118
+ })
95
119
 
96
120
  useEffect(() => {
97
121
  if (!currentPackage || isLoadingPackageFilesWithContent) {
@@ -204,29 +228,10 @@ export function useFileManagement({
204
228
  return
205
229
  }
206
230
 
207
- const newPackage = await createPackageMutation.mutateAsync({
231
+ await createPackageMutation.mutateAsync({
208
232
  name: `${loggedInUser?.github_username}/${generateRandomPackageName()}`,
209
233
  is_private: isPrivate,
210
234
  })
211
-
212
- if (newPackage) {
213
- createRelease(
214
- {
215
- package_name_with_version: `${newPackage.name}@latest`,
216
- },
217
- {
218
- onSuccess: () => {
219
- updatePackageFilesMutation.mutate({
220
- package_name_with_version: `${newPackage.name}@latest`,
221
- ...newPackage,
222
- })
223
- updateLastUpdated()
224
- setInitialFiles([...localFiles])
225
- },
226
- },
227
- )
228
- }
229
- updateLastUpdated()
230
235
  }
231
236
 
232
237
  const saveFiles = () => {
@@ -6,7 +6,7 @@ import { Helmet } from "react-helmet-async"
6
6
  import { useCurrentPackageId } from "@/hooks/use-current-package-id"
7
7
  import { NotFound } from "@/components/NotFound"
8
8
  import { ErrorOutline } from "@/components/ErrorOutline"
9
- import { DeploymentDetailsPage } from "@/components/PackageBuildsPage/DeploymentDetailsPage"
9
+ import { PackageBuildDetailsPage } from "@/components/PackageBuildsPage/PackageBuildDetailsPage"
10
10
 
11
11
  export const EditorPage = () => {
12
12
  const { packageId } = useCurrentPackageId()
@@ -26,7 +26,7 @@ export const EditorPage = () => {
26
26
  )}
27
27
  </Helmet>
28
28
  <Header />
29
- <DeploymentDetailsPage />
29
+ <PackageBuildDetailsPage />
30
30
  <Footer />
31
31
  </div>
32
32
  )