Skip to content

Commit c30845d

Browse files
authored
Merge pull request #109 from githubnext/hazy-anchor/github-row-actions
feat(app): open GitHub items on GitHub or in a new channel
2 parents 5058c40 + dde96ad commit c30845d

7 files changed

Lines changed: 176 additions & 417 deletions

File tree

‎apps/app/src/app.tsx‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { Channel, ChannelDetails, type ChannelDraft } from "./channel";
2828
import { Dashboard } from "./dashboard";
2929
import { Github, GithubSidebar } from "./github";
3030
import { useGithubRefresh } from "./github-cache";
31-
import { GithubLinks, type GithubTarget } from "./github-link";
3231
import { desktop, titlebar } from "./desktop";
3332
import { host } from "./host";
3433
import { Rename } from "./layout/rename";
@@ -38,6 +37,9 @@ import { projectId, projects } from "./projects";
3837
import { Settings } from "./settings";
3938
import { UpdateNotice } from "./updates";
4039

40+
// Older versions saved an inline GitHub item per project; Ace now opens items on GitHub.
41+
localStorage.removeItem(`ace:github-targets:${host.url}`);
42+
4143
/**
4244
* On a phone the channel list is a drawer over the channel: open while no channel is chosen, and
4345
* out of the way once one is.
@@ -135,9 +137,6 @@ export function App() {
135137
const [settings, setSettings] = useState<boolean | "updates">(false);
136138
const [draft, setDraft] = useState<ChannelDraft>();
137139
const [renaming, setRenaming] = useState<{ id: string; name: string }>();
138-
const [github, setGithub] = useLocalStorage<
139-
Record<string, Partial<Record<"issues" | "prs", GithubTarget>>>
140-
>(`ace:github-targets:${host.url}`, {});
141140
const [left, setLeft] = useLocalStorage("panel:left", true);
142141
const [width, setWidth] = useLocalStorage("panel:left:width", 200);
143142
const [collapsed, setCollapsed] = useState<Record<SessionSidebarGroupId, boolean>>({
@@ -279,23 +278,9 @@ export function App() {
279278
setRenaming(undefined);
280279
}
281280

282-
function setTarget(kind: "issues" | "prs", target?: GithubTarget) {
283-
if (!current) return;
284-
setGithub((value) => ({
285-
...value,
286-
[current.id]: { ...value[current.id], [kind]: target },
287-
}));
288-
}
289-
290-
function openGithub(target: GithubTarget) {
291-
setTarget(target.kind, target);
292-
setPage(target.kind);
293-
}
294-
295281
return (
296282
<ThemeProvider storageKey="ace-theme">
297283
<TooltipProvider>
298-
{current && <GithubLinks onOpen={openGithub} />}
299284
<Layout
300285
appearance={desktop ? "native" : "web"}
301286
defaultNavOpen={false}
@@ -375,7 +360,6 @@ export function App() {
375360
connected={connected}
376361
onProject={setProject}
377362
onOpen={() => void choose()}
378-
onTarget={(target) => setTarget(page, target)}
379363
/>
380364
)}
381365
</Sidebar>
@@ -421,8 +405,8 @@ export function App() {
421405
key={`${current.id}:${page}`}
422406
kind={page}
423407
project={current}
424-
target={github[current.id]?.[page]}
425-
onTarget={(target) => setTarget(page, target)}
408+
connected={connected}
409+
onCreate={local ? create : undefined}
426410
/>
427411
)
428412
: channel

‎apps/app/src/github-cache.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import type { HostRequest } from "@ace/host/protocol";
55
import { host, onOpen } from "./host";
66
import type { AppProject } from "./projects";
77

8-
type Request = Extract<
9-
HostRequest,
10-
{ op: "project-repo" | "github-list" | "github-detail" | "github-files" }
11-
>;
8+
type Request = Extract<HostRequest, { op: "project-repo" | "github-list" }>;
129
type Snapshot = { value?: unknown; error?: string; loading: boolean };
1310
type Saved = { key: string; request: Request; value: unknown };
1411
type Entry = {
@@ -28,11 +25,22 @@ const INTERVAL = 3 * 60 * 60 * 1000;
2825
const EMPTY: Snapshot = { loading: true };
2926
const cache = new Map<string, Entry>();
3027
const database = new Promise<IDBDatabase>((resolve, reject) => {
31-
const request = indexedDB.open(`ace:github:${host.url}`, 1);
32-
request.addEventListener(
33-
"upgradeneeded",
34-
() => request.result.createObjectStore("queries", { keyPath: "key" }),
35-
);
28+
const request = indexedDB.open(`ace:github:${host.url}`, 2);
29+
request.addEventListener("upgradeneeded", (event) => {
30+
if (event.oldVersion < 1) {
31+
return request.result.createObjectStore("queries", { keyPath: "key" });
32+
}
33+
// Version 1 also saved inline item details, which background refresh would keep requesting.
34+
const cursor = request.transaction!.objectStore("queries").openCursor();
35+
cursor.addEventListener("success", () => {
36+
const saved = cursor.result;
37+
if (!saved) return;
38+
if (!["project-repo", "github-list"].includes((saved.value as Saved).request.op)) {
39+
saved.delete();
40+
}
41+
saved.continue();
42+
});
43+
});
3644
request.addEventListener("success", () => {
3745
request.result.addEventListener("versionchange", () => request.result.close());
3846
resolve(request.result);

‎apps/app/src/github-link.tsx‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)