Skip to content

Commit 3f59137

Browse files
Nav rewrite, part 1
#4
1 parent 775f543 commit 3f59137

6 files changed

Lines changed: 107 additions & 170 deletions

File tree

src/renderer/components/packages/PackageDetailView.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export default class PackageDetailView<PackageInfo> extends ProductView {
3737
return packageInfoAdapterForPackageManagerName(this.packageManagerName);
3838
}
3939

40+
get title(): string {
41+
return this.packageInfoAdapter.packageName(this.packageInfo);
42+
}
43+
4044
protected get subtitle(): string {
4145
const name = this.packageInfoAdapter.packageName(this.packageInfo);
4246
const identifier = this.packageInfoAdapter.packageIdentifier(

src/renderer/components/packages/PackagesView.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,6 @@ export default class PackagesView<
529529
}
530530

531531
(window as any).openStore.pages["apps"] = {
532-
title: "",
533-
534532
_currentPackageManager: null,
535533
_currentPackageInfoAdapter: null,
536534

@@ -554,7 +552,6 @@ export default class PackagesView<
554552
const packageInfo = this._currentPackageManager.info(packageIdentifier);
555553

556554
return {
557-
title: this._currentPackageInfoAdapter.packageName(packageInfo),
558555
isSubpage: true,
559556

560557
async onNavigatedTo(content: HTMLElement) {

src/renderer/components/packages/ProductView.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type Button = {
3333
};
3434

3535
export abstract class ProductView extends BootstrapBlockElement {
36+
abstract readonly title: string;
3637
protected abstract readonly subtitle: string;
3738
protected abstract readonly description: string;
3839
protected abstract readonly sourceRepositoryName: string;
@@ -52,6 +53,8 @@ export abstract class ProductView extends BootstrapBlockElement {
5253
taskQueue.addObserver(this.taskQueueObserver);
5354

5455
document.addEventListener("keydown", this.keydown);
56+
57+
window.scrollTo({ top: 0 });
5558
}
5659

5760
disconnectedCallback(): void {
@@ -111,6 +114,106 @@ export abstract class ProductView extends BootstrapBlockElement {
111114

112115
render() {
113116
return html`
117+
<div
118+
class="container-fluid d-flex flex-row justify-content-center align-items-end flex-nowrap sticky-top bg-light pt-1 pb-2"
119+
style="top: 53px"
120+
>
121+
<nav
122+
class="d-flex justify-content-start ms-4 me-auto"
123+
style="flex: 1"
124+
aria-label="Go back"
125+
>
126+
<a
127+
href="#"
128+
class="btn btn-link fs-3 text-decoration-none p-0"
129+
style="-webkit-user-drag: none"
130+
tabindex="0"
131+
@click=${(event: Event) => {
132+
event.preventDefault();
133+
window.history.back();
134+
}}
135+
>
136+
<svg
137+
version="1.1"
138+
xmlns="http://www.w3.org/2000/svg"
139+
width="34"
140+
height="34"
141+
viewBox="0, 0, 128, 128"
142+
color="inherit"
143+
>
144+
<g id="Layer_2">
145+
<circle
146+
cx="64"
147+
cy="64"
148+
r="64"
149+
fill="none"
150+
stroke="currentcolor"
151+
stroke-width="20"
152+
clip-path="url(#back-arrow-bg-circle-clip)"
153+
/>
154+
<clipPath id="back-arrow-bg-circle-clip">
155+
<circle cx="64" cy="64" r="64" />
156+
</clipPath>
157+
</g>
158+
<g id="Layer_1">
159+
<g>
160+
<path
161+
d="M98.178,64.412 L32,64.412"
162+
fill="none"
163+
stroke="currentcolor"
164+
stroke-width="12"
165+
/>
166+
<path
167+
fill="currentcolor"
168+
d="M97.096,69.912 C93.782,69.912 91.096,67.225 91.096,63.912 C91.096,60.598 93.782,57.912 97.096,57.912 C100.41,57.912 103.096,60.598 103.096,63.912 C103.096,67.225 100.41,69.912 97.096,69.912 z"
169+
/>
170+
</g>
171+
<g>
172+
<path
173+
d="M53.293,85.696 L31.064,63.467"
174+
fill="none"
175+
stroke="currentcolor"
176+
stroke-width="12"
177+
/>
178+
<path
179+
fill="currentcolor"
180+
d="M57.11,81.028 C54.767,78.685 50.968,78.685 48.625,81.028 C46.282,83.371 46.282,87.17 48.625,89.513 C50.968,91.857 54.767,91.857 57.11,89.513 C59.453,87.17 59.453,83.371 57.11,81.028 z"
181+
/>
182+
</g>
183+
<g>
184+
<path
185+
d="M53.253,43.304 L31.064,65.493"
186+
fill="none"
187+
stroke="currentcolor"
188+
stroke-width="12"
189+
/>
190+
<path
191+
fill="currentcolor"
192+
d="M57.07,46.972 C54.727,49.315 50.928,49.315 48.585,46.972 C46.242,44.629 46.242,40.83 48.585,38.487 C50.928,36.143 54.727,36.143 57.07,38.487 C59.413,40.83 59.413,44.629 57.07,46.972 z"
193+
/>
194+
</g>
195+
<path
196+
fill="currentcolor"
197+
d="M34.927,67.835 C32.76,70.002 29.247,70.002 27.08,67.835 C24.913,65.668 24.913,62.155 27.08,59.989 C29.247,57.822 32.76,57.822 34.927,59.989 C37.093,62.155 37.093,65.668 34.927,67.835 z"
198+
/>
199+
</g>
200+
</svg>
201+
</a>
202+
</nav>
203+
<div
204+
class="d-flex justify-content-center text-center text-nowrap mt-4"
205+
style="flex: 1"
206+
>
207+
<h1 id="openstore-page-title" class="mb-0" style="font-weight: 500">
208+
${this.title}
209+
</h1>
210+
</div>
211+
<span
212+
class="d-flex justify-content-end ms-auto me-4"
213+
style="flex: 1"
214+
></span>
215+
</div>
216+
114217
<div class="mx-4">
115218
<p
116219
class="d-flex flex-column gap-1 fs-slightly-larger text-center mt-1 mb-2"

src/renderer/index.html

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -53,111 +53,6 @@
5353
</main>
5454
</div>
5555

56-
<template id="openstore-template-page-title">
57-
<div
58-
class="container-fluid d-flex flex-row justify-content-center align-items-end flex-nowrap sticky-top bg-light pt-1 pb-2"
59-
style="top: 53px"
60-
>
61-
<nav
62-
class="d-flex justify-content-start ms-4 me-auto"
63-
style="flex: 1"
64-
aria-label="Go back"
65-
>
66-
<a
67-
href="#"
68-
class="openstore-jsnav-back-link btn btn-link fs-3 text-decoration-none p-0"
69-
tabindex="0"
70-
>
71-
<svg
72-
version="1.1"
73-
xmlns="http://www.w3.org/2000/svg"
74-
width="34"
75-
height="34"
76-
viewBox="0, 0, 128, 128"
77-
color="inherit"
78-
>
79-
<g id="Layer_2">
80-
<circle
81-
cx="64"
82-
cy="64"
83-
r="64"
84-
fill="none"
85-
stroke="currentcolor"
86-
stroke-width="20"
87-
clip-path="url(#back-arrow-bg-circle-clip)"
88-
/>
89-
<clipPath id="back-arrow-bg-circle-clip">
90-
<circle cx="64" cy="64" r="64" />
91-
</clipPath>
92-
</g>
93-
<g id="Layer_1">
94-
<g>
95-
<path
96-
d="M98.178,64.412 L32,64.412"
97-
fill="none"
98-
stroke="currentcolor"
99-
stroke-width="12"
100-
/>
101-
<path
102-
fill="currentcolor"
103-
d="M97.096,69.912 C93.782,69.912 91.096,67.225 91.096,63.912 C91.096,60.598 93.782,57.912 97.096,57.912 C100.41,57.912 103.096,60.598 103.096,63.912 C103.096,67.225 100.41,69.912 97.096,69.912 z"
104-
/>
105-
</g>
106-
<g>
107-
<path
108-
d="M53.293,85.696 L31.064,63.467"
109-
fill="none"
110-
stroke="currentcolor"
111-
stroke-width="12"
112-
/>
113-
<path
114-
fill="currentcolor"
115-
d="M57.11,81.028 C54.767,78.685 50.968,78.685 48.625,81.028 C46.282,83.371 46.282,87.17 48.625,89.513 C50.968,91.857 54.767,91.857 57.11,89.513 C59.453,87.17 59.453,83.371 57.11,81.028 z"
116-
/>
117-
</g>
118-
<g>
119-
<path
120-
d="M53.253,43.304 L31.064,65.493"
121-
fill="none"
122-
stroke="currentcolor"
123-
stroke-width="12"
124-
/>
125-
<path
126-
fill="currentcolor"
127-
d="M57.07,46.972 C54.727,49.315 50.928,49.315 48.585,46.972 C46.242,44.629 46.242,40.83 48.585,38.487 C50.928,36.143 54.727,36.143 57.07,38.487 C59.413,40.83 59.413,44.629 57.07,46.972 z"
128-
/>
129-
</g>
130-
<path
131-
fill="currentcolor"
132-
d="M34.927,67.835 C32.76,70.002 29.247,70.002 27.08,67.835 C24.913,65.668 24.913,62.155 27.08,59.989 C29.247,57.822 32.76,57.822 34.927,59.989 C37.093,62.155 37.093,65.668 34.927,67.835 z"
133-
/>
134-
</g>
135-
</svg>
136-
</a>
137-
</nav>
138-
<div
139-
class="d-flex justify-content-center text-center text-nowrap mt-4"
140-
style="flex: 1"
141-
>
142-
<h1
143-
id="openstore-page-title"
144-
class="mb-0"
145-
style="font-weight: 500"
146-
></h1>
147-
</div>
148-
<span
149-
class="d-flex justify-content-end ms-auto me-4"
150-
style="flex: 1"
151-
></span>
152-
</div>
153-
</template>
154-
155-
<template id="openstore-template-loading">
156-
<div class="openstore-loading-container mx-auto text-center mb-4">
157-
<h2>Loading…</h2>
158-
</div>
159-
</template>
160-
16156
<div id="modalContainer"></div>
16257
</body>
16358
</html>

src/renderer/nav/nav.js

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@ window.addEventListener("popstate", () => {
77
);
88
});
99

10-
new MutationObserver(() => {
11-
document
12-
.querySelectorAll(".openstore-jsnav-back-link")
13-
.forEach((backLink) => {
14-
if (!backLink.openStoreHandlerSetForBackLink) {
15-
backLink.openStoreHandlerSetForBackLink = true;
16-
backLink.addEventListener("click", (event) => {
17-
event.preventDefault();
18-
window.history.back();
19-
});
20-
}
21-
});
22-
}).observe(document.body, { attributes: true, childList: true, subtree: true });
23-
2410
window.openStore.encodeFragment = (routeParams) => {
2511
return "#" + encodeURIComponent(JSON.stringify(routeParams));
2612
};
@@ -69,55 +55,10 @@ window.openStore.displayPage = async (page, subpage, target) => {
6955

7056
if (subpage) page = await page.getSubpage(subpage);
7157

72-
if (page) {
73-
const pageTitleDocumentFragment = document
74-
.querySelector("#openstore-template-page-title")
75-
.content.cloneNode(true);
76-
77-
// Change page title
78-
if (page.title) {
79-
pageTitleDocumentFragment.querySelector(
80-
"#openstore-page-title"
81-
).textContent = page.title;
82-
} else {
83-
for (const child of pageTitleDocumentFragment.children) {
84-
child.classList.add("d-none");
85-
}
86-
}
87-
88-
// Control "back" link visibility
89-
pageTitleDocumentFragment
90-
.querySelectorAll(".openstore-jsnav-back-link")
91-
.forEach((backLink) => {
92-
if (page.isSubpage) {
93-
backLink.classList.remove("d-none");
94-
} else {
95-
backLink.classList.add("d-none");
96-
}
97-
});
98-
99-
target.replaceChildren(pageTitleDocumentFragment);
100-
101-
if (page.isSubpage) {
102-
window.scrollTo({ top: 0 });
103-
}
104-
}
105-
106-
// Display loading template
107-
const loadingDocumentFragment = document
108-
.querySelector("#openstore-template-loading")
109-
.content.cloneNode(true);
110-
loadingDocumentFragment.querySelector(".openstore-loading-container").id =
111-
"displayPage-loading-indicator";
112-
target.append(loadingDocumentFragment);
113-
11458
const renderingContainer = document.createElement("div");
11559

11660
// Let the page do its setup
11761
if (page && page.onNavigatedTo) await page.onNavigatedTo(renderingContainer);
11862

11963
target.append(renderingContainer);
120-
121-
// Remove loading template
122-
target.querySelector("#displayPage-loading-indicator")?.remove();
12364
};

src/renderer/styles/top-level.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
.openstore-jsnav-back-link {
2-
-webkit-user-drag: none;
3-
}

0 commit comments

Comments
 (0)