fix back button on blog
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
:host > div {
|
:host > div {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: var(--medium-padding);
|
gap: var(--large-padding);
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
grid-template-rows: auto 1fr auto;
|
grid-template-rows: auto 1fr auto;
|
||||||
}
|
}
|
||||||
@@ -36,13 +36,19 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
grid-template-rows: auto auto auto;
|
grid-template-rows: auto auto auto;
|
||||||
|
padding: var(--medium-padding);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item:hover {
|
||||||
|
background-color: var(--gray);
|
||||||
|
color: unset;
|
||||||
|
}
|
||||||
|
|
||||||
.item > h3 {
|
.item > h3 {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: var(--medium-padding);
|
gap: var(--large-padding);
|
||||||
grid-auto-columns: auto;
|
grid-auto-columns: auto;
|
||||||
grid-auto-flow: column;
|
grid-auto-flow: column;
|
||||||
justify-content: start;
|
justify-content: start;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export class TesoftBlogArticleList extends TesoftComponent {
|
|||||||
this.error = shadowRoot.querySelector<TesoftError>("tesoft-error")!;
|
this.error = shadowRoot.querySelector<TesoftError>("tesoft-error")!;
|
||||||
}
|
}
|
||||||
|
|
||||||
async load(page: number, tags: string[], onParametersChange: (page: number, tags: string[]) => void) {
|
async load(page: number, tags: string[]) {
|
||||||
try {
|
try {
|
||||||
this.tagsDiv.innerHTML = "";
|
this.tagsDiv.innerHTML = "";
|
||||||
for (const tagName of await this.fetchTags()) {
|
for (const tagName of await this.fetchTags()) {
|
||||||
@@ -45,14 +45,22 @@ export class TesoftBlogArticleList extends TesoftComponent {
|
|||||||
|
|
||||||
this.pagination.addEventListener("update-page", (e) => {
|
this.pagination.addEventListener("update-page", (e) => {
|
||||||
const page = (e as CustomEvent).detail.page;
|
const page = (e as CustomEvent).detail.page;
|
||||||
onParametersChange(page, tags);
|
e.stopPropagation();
|
||||||
this.reload(page, tags, onParametersChange);
|
|
||||||
|
this.dispatchEvent(new CustomEvent("update-parameters", {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
composed: true,
|
||||||
|
detail: {
|
||||||
|
page: page,
|
||||||
|
},
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.reload(page, tags, onParametersChange);
|
await this.reload(page, tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async reload(page: number, tags: string[], onParametersChange: (page: number, tags: string[]) => void) {
|
async reload(page: number, tags: string[]) {
|
||||||
const itemsPerPage = 20;
|
const itemsPerPage = 20;
|
||||||
|
|
||||||
for (const tag of this.tagsDiv.children as any as TesoftTag[]) {
|
for (const tag of this.tagsDiv.children as any as TesoftTag[]) {
|
||||||
@@ -67,8 +75,14 @@ export class TesoftBlogArticleList extends TesoftComponent {
|
|||||||
}
|
}
|
||||||
const newTags = Array.from(tagSet);
|
const newTags = Array.from(tagSet);
|
||||||
|
|
||||||
onParametersChange(page, newTags);
|
this.dispatchEvent(new CustomEvent("update-parameters", {
|
||||||
this.reload(page, newTags, onParametersChange);
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
composed: true,
|
||||||
|
detail: {
|
||||||
|
tags: newTags,
|
||||||
|
},
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tags.includes(tagName)) {
|
if (tags.includes(tagName)) {
|
||||||
@@ -120,6 +134,7 @@ export class TesoftBlogArticleList extends TesoftComponent {
|
|||||||
const tag = document.createElement("tesoft-tag") as TesoftTag;
|
const tag = document.createElement("tesoft-tag") as TesoftTag;
|
||||||
tag.textContent = tagName;
|
tag.textContent = tagName;
|
||||||
tag.selected = "";
|
tag.selected = "";
|
||||||
|
tag.small = "";
|
||||||
tag.disabled = "";
|
tag.disabled = "";
|
||||||
tags.appendChild(tag);
|
tags.appendChild(tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
.header > h1 {
|
.header > h1 {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: var(--medium-padding);
|
gap: var(--large-padding);
|
||||||
grid-template-columns: auto auto;
|
grid-template-columns: auto auto;
|
||||||
grid-template-rows: auto;
|
grid-template-rows: auto;
|
||||||
justify-content: start;
|
justify-content: start;
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
padding: var(--small-padding) var(--medium-padding);
|
padding: var(--small-padding) var(--medium-padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host([small]) tesoft-button::part(children) {
|
||||||
|
padding: 0 var(--small-padding);
|
||||||
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
height: 2.4rem;
|
height: 2.4rem;
|
||||||
width: 2.4rem;
|
width: 2.4rem;
|
||||||
|
|||||||
@@ -58,6 +58,14 @@ export class TesoftTag extends TesoftComponent {
|
|||||||
this.setAttribute("selected", "");
|
this.setAttribute("selected", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set small(value: string | null) {
|
||||||
|
if (value === null) {
|
||||||
|
this.removeAttribute("small");
|
||||||
|
} else {
|
||||||
|
this.setAttribute("small", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define("tesoft-tag", TesoftTag);
|
customElements.define("tesoft-tag", TesoftTag);
|
||||||
|
|||||||
@@ -61,19 +61,28 @@ class BlogSite {
|
|||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
async load() {
|
||||||
if (this.parameters.id === null) {
|
if (this.parameters.id === null) {
|
||||||
this.blogArticleList.load(this.parameters.page ?? 1, this.parameters.tags, (page, tags) => {
|
this.blogArticleList.addEventListener("update-parameters", (e) => {
|
||||||
this.parameters = new Parameters(
|
const {page, tags} = (e as CustomEvent).detail;
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
window.history.pushState(
|
||||||
null,
|
null,
|
||||||
page,
|
"",
|
||||||
tags,
|
new Parameters(
|
||||||
|
null,
|
||||||
|
page ?? this.parameters.page,
|
||||||
|
tags ?? this.parameters.tags,
|
||||||
|
).constructUrl(),
|
||||||
);
|
);
|
||||||
window.history.pushState(null, "", this.parameters.constructUrl());
|
this.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await this.blogArticleList.load(this.parameters.page ?? 1, this.parameters.tags);
|
||||||
this.blogArticleList.classList.remove("hidden");
|
this.blogArticleList.classList.remove("hidden");
|
||||||
} else {
|
} else {
|
||||||
this.blogArticle.load(this.parameters.id, (tag) => {
|
await this.blogArticle.load(this.parameters.id, (tag) => {
|
||||||
return new Parameters(
|
return new Parameters(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@@ -83,14 +92,28 @@ class BlogSite {
|
|||||||
this.blogArticle.classList.remove("hidden");
|
this.blogArticle.classList.remove("hidden");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async reload() {
|
||||||
|
this.parameters = Parameters.parse(new URLSearchParams(window.location.search));
|
||||||
|
|
||||||
|
await this.blogArticleList.reload(this.parameters.page ?? 1, this.parameters.tags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onReady(async () => {
|
onReady(async () => {
|
||||||
|
const parameters = Parameters.parse(new URLSearchParams(window.location.search));
|
||||||
|
|
||||||
const blogSite = new BlogSite(
|
const blogSite = new BlogSite(
|
||||||
document.querySelector<TesoftBlogArticle>("tesoft-blog-article")!,
|
document.querySelector<TesoftBlogArticle>("tesoft-blog-article")!,
|
||||||
document.querySelector<TesoftBlogArticleList>("tesoft-blog-article-list")!,
|
document.querySelector<TesoftBlogArticleList>("tesoft-blog-article-list")!,
|
||||||
Parameters.parse(new URLSearchParams(window.location.search)),
|
parameters,
|
||||||
);
|
);
|
||||||
|
|
||||||
blogSite.load();
|
if (parameters.id === null) {
|
||||||
|
window.addEventListener("popstate", async () => {
|
||||||
|
await blogSite.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await blogSite.load();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user