tangled
alpha
login
or
join now
ansxor.ca
/
pdsls
forked from
pds.ls/pdsls
0
fork
atom
atmosphere explorer
0
fork
atom
overview
issues
pulls
pipelines
browser history in car explorer
handle.invalid
1 month ago
5e49244f
595be972
verified
This commit was signed with the committer's
known signature
.
handle.invalid
SSH Key Fingerprint:
SHA256:mBrT4x0JdzLpbVR95g1hjI1aaErfC02kmLRkPXwsYCk=
+55
-4
1 changed file
expand all
collapse all
unified
split
src
views
car
explore.tsx
+55
-4
src/views/car/explore.tsx
···
5
5
import { fromStream, isCommit } from "@atcute/repo";
6
6
import * as TID from "@atcute/tid";
7
7
import { Title } from "@solidjs/meta";
8
8
+
import { useLocation, useNavigate } from "@solidjs/router";
8
9
import {
9
10
createEffect,
10
11
createMemo,
···
33
34
WelcomeView,
34
35
} from "./shared.jsx";
35
36
37
37
+
const viewToHash = (view: View): string => {
38
38
+
switch (view.type) {
39
39
+
case "repo":
40
40
+
return "";
41
41
+
case "collection":
42
42
+
return `#${view.collection.name}`;
43
43
+
case "record":
44
44
+
return `#${view.collection.name}/${view.record.key}`;
45
45
+
}
46
46
+
};
47
47
+
48
48
+
const hashToView = (hash: string, archive: Archive): View => {
49
49
+
if (!hash || hash === "#") return { type: "repo" };
50
50
+
51
51
+
const raw = hash.startsWith("#") ? hash.slice(1) : hash;
52
52
+
const slashIdx = raw.indexOf("/");
53
53
+
54
54
+
if (slashIdx === -1) {
55
55
+
const collection = archive.entries.find((e) => e.name === raw);
56
56
+
if (collection) return { type: "collection", collection };
57
57
+
return { type: "repo" };
58
58
+
}
59
59
+
60
60
+
const collectionName = raw.slice(0, slashIdx);
61
61
+
const recordKey = raw.slice(slashIdx + 1);
62
62
+
const collection = archive.entries.find((e) => e.name === collectionName);
63
63
+
if (collection) {
64
64
+
const record = collection.entries.find((r) => r.key === recordKey);
65
65
+
if (record) return { type: "record", collection, record };
66
66
+
return { type: "collection", collection };
67
67
+
}
68
68
+
69
69
+
return { type: "repo" };
70
70
+
};
71
71
+
36
72
export const ExploreToolView = () => {
73
73
+
const location = useLocation();
74
74
+
const navigate = useNavigate();
75
75
+
37
76
const [archive, setArchive] = createSignal<Archive | null>(null);
38
77
const [loading, setLoading] = createSignal(false);
39
78
const [progress, setProgress] = createSignal(0);
40
79
const [error, setError] = createSignal<string>();
41
41
-
const [view, setView] = createSignal<View>({ type: "repo" });
80
80
+
81
81
+
const view = createMemo((): View => {
82
82
+
const arch = archive();
83
83
+
if (!arch) return { type: "repo" };
84
84
+
return hashToView(location.hash, arch);
85
85
+
});
86
86
+
87
87
+
const navigateToView = (newView: View) => {
88
88
+
const hash = viewToHash(newView);
89
89
+
navigate(`${location.pathname}${hash}`);
90
90
+
};
42
91
43
92
const parseCarFile = async (file: File) => {
44
93
setLoading(true);
···
121
170
}
122
171
123
172
setArchive(result);
124
124
-
setView({ type: "repo" });
173
173
+
if (location.hash) navigate(location.pathname, { replace: true });
125
174
} catch (err) {
126
175
console.error("Failed to parse CAR file:", err);
127
176
setError(err instanceof Error ? err.message : "Failed to parse CAR file");
···
135
184
136
185
const reset = () => {
137
186
setArchive(null);
138
138
-
setView({ type: "repo" });
139
187
setError(undefined);
188
188
+
if (location.hash) navigate(location.pathname, { replace: true });
140
189
};
141
190
142
191
return (
···
157
206
/>
158
207
}
159
208
>
160
160
-
{(arch) => <ExploreView archive={arch()} view={view} setView={setView} onClose={reset} />}
209
209
+
{(arch) => (
210
210
+
<ExploreView archive={arch()} view={view} setView={navigateToView} onClose={reset} />
211
211
+
)}
161
212
</Show>
162
213
</>
163
214
);