Skip to content

Commit cc45f57

Browse files
authored
Many View Package Page Improvements, launch as main view package page (#790)
* remove useless placeholder images (not used) * init pcb view * add pcb view tab support, production filepath matching parity * correctly show files in their directories * wip directory browsing * allow browsing into directories * wip progress towards file selection * add edit file links * add bom and 3d views * fix time ago, fix a lot of placeholder data * redesign download button * route to view package page * code dropdown improvement * add tab saving via hash * type fixes
1 parent 85ccfd2 commit cc45f57

38 files changed

Lines changed: 728 additions & 484 deletions

bun.lock

Lines changed: 43 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fake-snippets-api/lib/package_file/get-package-file-id-from-file-descriptor.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NotFoundError } from "winterspec/middleware"
22
import * as ZT from "../db/schema"
3+
import { normalizeProjectFilePath } from "fake-snippets-api/utils/normalizeProjectFilePath"
34
export const getPackageFileIdFromFileDescriptor = async (
45
descriptor:
56
| { package_file_id: string }
@@ -26,7 +27,8 @@ export const getPackageFileIdFromFileDescriptor = async (
2627
const packageFile = ctx.db.packageFiles.find(
2728
(pf: ZT.PackageFile) =>
2829
pf.package_release_id === package_release_id &&
29-
pf.file_path === file_path,
30+
normalizeProjectFilePath(pf.file_path) ===
31+
normalizeProjectFilePath(file_path),
3032
)
3133

3234
if (!packageFile) {
@@ -68,7 +70,8 @@ export const getPackageFileIdFromFileDescriptor = async (
6870
const packageFile = ctx.db.packageFiles.find(
6971
(pf: ZT.PackageFile) =>
7072
pf.package_release_id === packageRelease.package_release_id &&
71-
pf.file_path === file_path,
73+
normalizeProjectFilePath(pf.file_path) ===
74+
normalizeProjectFilePath(file_path),
7275
)
7376

7477
if (!packageFile) {
@@ -109,7 +112,8 @@ export const getPackageFileIdFromFileDescriptor = async (
109112
const packageFile = ctx.db.packageFiles.find(
110113
(pf: ZT.PackageFile) =>
111114
pf.package_release_id === packageRelease.package_release_id &&
112-
pf.file_path === file_path,
115+
normalizeProjectFilePath(pf.file_path) ===
116+
normalizeProjectFilePath(file_path),
113117
)
114118

115119
if (!packageFile) {
@@ -154,7 +158,8 @@ export const getPackageFileIdFromFileDescriptor = async (
154158
const packageFile = ctx.db.packageFiles.find(
155159
(pf: ZT.PackageFile) =>
156160
pf.package_release_id === packageRelease.package_release_id &&
157-
pf.file_path === file_path,
161+
normalizeProjectFilePath(pf.file_path) ===
162+
normalizeProjectFilePath(file_path),
158163
)
159164

160165
if (!packageFile) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const RESTRICTED_DIRS = ["/node_modules/", "/dist/", "/.git/"]
2+
3+
/**
4+
* A normalized project path always starts with "./" and never ends with a slash.
5+
* It has no backwards slashes and no double slashes. It does not go to parent
6+
* directories. It is not a directory (must have a file extension)
7+
*
8+
* GOOD:
9+
* - src/index.ts
10+
* - README.md
11+
*
12+
* BAD:
13+
* - ./README.md
14+
* - ./src/index.ts
15+
* - src\index.ts
16+
* - ../README.md
17+
* - ./src/
18+
* - ./src
19+
*
20+
* Additionally, throw on directories that should never be included, e.g.
21+
* - node_modules
22+
* - dist
23+
* - .git
24+
*/
25+
export const normalizeProjectFilePathAndValidate = (rawPath: string) => {
26+
const normalizedPath = normalizeProjectFilePath(rawPath)
27+
28+
if (normalizedPath.includes("../")) {
29+
throw new Error(
30+
"Invalid project file path. Parent directories are not allowed.",
31+
)
32+
}
33+
34+
if (RESTRICTED_DIRS.some((dir) => normalizedPath.includes(dir))) {
35+
throw new Error(
36+
`Invalid project file path. Restricted directories (${RESTRICTED_DIRS.map(
37+
(rd) => rd.slice(1, -1),
38+
).join(", ")}) are not allowed.`,
39+
)
40+
}
41+
42+
if (!normalizedPath.includes(".")) {
43+
throw new Error(
44+
`Invalid project file path. Must have a file extension. Given "${rawPath}"`,
45+
)
46+
}
47+
48+
return normalizedPath
49+
}
50+
51+
export const normalizeProjectFilePath = (rawPath: string) => {
52+
let normalizedPath = rawPath.trim() // Remove leading/trailing whitespace
53+
normalizedPath = normalizedPath.replace(/\/+/g, "/") // Replace multiple consecutive slashes with a single slash
54+
normalizedPath = normalizedPath.replace(/^\.\//, "") // Remove leading "./"
55+
normalizedPath = normalizedPath.replace(/\/$/, "") // Remove trailing slash
56+
normalizedPath = normalizedPath.replace(/\\/g, "/") // Replace backslashes with forward slashes
57+
normalizedPath = normalizedPath.replace(/^\//, "") // Remove leading "/"
58+
59+
return normalizedPath
60+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"country-list": "^2.3.0",
9191
"date-fns": "^4.1.0",
9292
"dsn-converter": "^0.0.60",
93-
"easyeda": "^0.0.62",
93+
"easyeda": "^0.0.129",
9494
"embla-carousel-react": "^8.3.0",
9595
"extract-codefence": "^0.0.4",
9696
"fflate": "^0.8.2",
@@ -112,6 +112,7 @@
112112
"react-helmet": "^6.1.0",
113113
"react-helmet-async": "^2.0.5",
114114
"react-hook-form": "^7.53.0",
115+
"react-hot-toast": "^2.5.2",
115116
"react-intersection-observer": "^9.14.1",
116117
"react-query": "^3.39.3",
117118
"react-resizable-panels": "^2.1.3",
@@ -135,7 +136,7 @@
135136
"@playwright/test": "^1.48.0",
136137
"@tscircuit/core": "^0.0.356",
137138
"@tscircuit/prompt-benchmarks": "^0.0.28",
138-
"@tscircuit/runframe": "^0.0.270",
139+
"@tscircuit/runframe": "^0.0.304",
139140
"@types/babel__standalone": "^7.1.7",
140141
"@types/bun": "^1.1.10",
141142
"@types/country-list": "^2.1.4",

public/placeholder-logo.png

-958 Bytes
Binary file not shown.

public/placeholder-logo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/placeholder-user.jpg

-2.55 KB
Binary file not shown.

public/placeholder.jpg

-1.56 KB
Binary file not shown.

public/placeholder.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/App.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ function App() {
120120
<Route path="/preview" component={PreviewPage} />
121121
<Route path="/dev-login" component={DevLoginPage} />
122122
<Route path="/:username" component={UserProfilePage} />
123-
<Route path="/:author/:snippetName" component={ViewSnippetPage} />
123+
<Route path="/:author/:packageName" component={ViewPackagePage} />
124+
<Route
125+
path="/snippets/:author/:snippetName"
126+
component={ViewSnippetPage}
127+
/>
124128
</Switch>
125129
</Suspense>
126130
<Toaster />

0 commit comments

Comments
 (0)