tangled
alpha
login
or
join now
hotsocket.fyi
/
domlink
0
fork
atom
https://domlink.deployments.hotsocket.fyi/
0
fork
atom
overview
issues
pulls
pipelines
oh god its git happening
hotsocket.fyi
6 months ago
d31d933c
926afe84
+92
1 changed file
expand all
collapse all
unified
split
src
windows
tangled
issuesearch.ts
+92
src/windows/tangled/issuesearch.ts
···
1
1
+
// rewrite of @/issuesearch.ts to be a self-contained class that can be shoved into a window easily
2
2
+
3
3
+
import { Column, Container, Node, Input, Link, Row, Table, TableCell, TableRow, Button } from "@/domlink.ts";
4
4
+
import { ListRecords } from "@/support/atproto.ts";
5
5
+
import { getUriRecord, resolveMiniDoc } from "@/support/slingshot.ts";
6
6
+
import { Issue, Repo, RepoRecord } from "@/support/tangled.ts";
7
7
+
import * as Constellation from "@/support/constellation.ts";
8
8
+
import { timeout } from "@/extras.ts";
9
9
+
10
10
+
export class IssueSearch extends Column {
11
11
+
repoInput = new Input();
12
12
+
searchInput = new Input();
13
13
+
searchRow = new Row().with("Search: ", this.searchInput).style(s=>s.display="none");
14
14
+
renderOut: Node = new Container().with("<nothing yet>");
15
15
+
repoInfo: RepoRecord = {} as RepoRecord;
16
16
+
issues: Issue[] = [];
17
17
+
constructor() {
18
18
+
super();
19
19
+
this.class("IssueSearch");
20
20
+
this.with(
21
21
+
new Row().with("Repo: ", this.repoInput, new Button("Get", async ()=>{await this.getIssues(this.repoInput.value);})),
22
22
+
this.searchRow,
23
23
+
this.renderOut
24
24
+
);
25
25
+
this.searchInput.watch((search)=>{
26
26
+
if (this.issues.length > 0) {
27
27
+
this.render(this.issues.filter((issue)=>{
28
28
+
return issue.issueId == Number(search) ||
29
29
+
search.split(" ").every((word)=> (
30
30
+
issue.owner.toLowerCase().includes(word) ||
31
31
+
issue.title.toLowerCase().includes(word) ||
32
32
+
issue.body.toLowerCase().includes(word)))
33
33
+
}));
34
34
+
}
35
35
+
});
36
36
+
}
37
37
+
async getIssues(repo: string) {
38
38
+
this.repoInfo = IssueSearch.parseRepoInfo(repo);
39
39
+
const doc = await resolveMiniDoc(this.repoInfo.owner);
40
40
+
const ownedRepos = await ListRecords<Repo>(doc.did, "sh.tangled.repo", doc.pds);
41
41
+
const repoRecord = ownedRepos.records.find(x=>x.value.name == this.repoInfo.name)!;
42
42
+
const links = await Constellation.getLinks(repoRecord.uri, "sh.tangled.repo.issue", ".repo");
43
43
+
this.issues = (await Promise.all(links.map(link => {
44
44
+
try {
45
45
+
return timeout(2000, getUriRecord<Issue>(link));
46
46
+
} catch {
47
47
+
return null;
48
48
+
}
49
49
+
}))).filter(x=>x).map(x=>x!.value).sort((a,b)=>a.issueId-b.issueId);
50
50
+
this.searchRow.style(s=>s.removeProperty("display"));
51
51
+
this.render(this.issues);
52
52
+
}
53
53
+
render(issues: Issue[]) {
54
54
+
this.remove(this.renderOut);
55
55
+
this.renderOut = new Table().with(
56
56
+
new TableRow().with(
57
57
+
new TableCell().with("Handle"),
58
58
+
new TableCell().with("Issue#"),
59
59
+
new TableCell().with("Title")),
60
60
+
...issues.map(issue => new TableRow().with(
61
61
+
new TableCell().with(new Link(issue.owner).to(`https://tangled.sh/@${issue.owner}`)),
62
62
+
new TableCell().with(new Link(issue.issueId.toString()).to(`https://tangled.sh/@${this.repoInfo.owner}/${this.repoInfo.name}/issues/${issue.issueId}`)),
63
63
+
new TableCell().with(issue.title)
64
64
+
))
65
65
+
);
66
66
+
this.with(this.renderOut);
67
67
+
}
68
68
+
69
69
+
static parseRepoInfo(repo: string) {
70
70
+
const repoSplat = repo.split("//");
71
71
+
let owner: string;
72
72
+
let name: string;
73
73
+
if (repoSplat.length == 1) {
74
74
+
const repoHalves = repo.split("/");
75
75
+
if (repoHalves.length == 1) throw new Error("invalid repo string");
76
76
+
owner = repoHalves[0];
77
77
+
name = repoHalves[1];
78
78
+
} else {
79
79
+
if (repoSplat[0] == "https:") {
80
80
+
const repoUrlSplat = new URL(repo).pathname.split("/");
81
81
+
// [ "", "@tangled.sh", "core" ]
82
82
+
if (repoUrlSplat.length < 2) throw new Error("invalid repo url");
83
83
+
owner = repoUrlSplat[1];
84
84
+
name = repoUrlSplat[2];
85
85
+
} else {
86
86
+
throw new Error("unknown repo uri scheme");
87
87
+
}
88
88
+
}
89
89
+
if (owner.startsWith("@")) owner = owner.substring(1);
90
90
+
return { owner, name };
91
91
+
}
92
92
+
}