From 02a7132026a7d8ec881f5f95d0f1916c5e5cd887 Mon Sep 17 00:00:00 2001 From: 728 Date: Sun, 27 Nov 2022 12:05:40 +0800 Subject: [PATCH] ui hashtag #15 --- ismism.ts/src/typ.ts | 2 +- ismism.ts/ui/index/bind.ts | 67 ++++++++++++++++++++++++++++------- ismism.ts/ui/index/index.html | 45 ++--------------------- 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/ismism.ts/src/typ.ts b/ismism.ts/src/typ.ts index 3c82374..cd271e2 100644 --- a/ismism.ts/src/typ.ts +++ b/ismism.ts/src/typ.ts @@ -17,7 +17,7 @@ export type Soc = { } export const sid_ofs = 10000 -type Tag = "" +export type Tag = "" | "进行中" | "已结束" | "设施建设" | "物资配给" | "软件开发" | "苏州" | "成都" diff --git a/ismism.ts/ui/index/bind.ts b/ismism.ts/ui/index/bind.ts index d977bea..fad5e13 100644 --- a/ismism.ts/ui/index/bind.ts +++ b/ismism.ts/ui/index/bind.ts @@ -1,8 +1,25 @@ // deno-lint-ignore-file no-window-prefix -import { Agenda } from "../../../cli/json.ts" -import { utc_medium, utc_short } from "../../src/date.ts" +import { Agenda, Rec } from "../../../cli/json.ts" +import { utc_medium } from "../../src/date.ts" +import { Tag } from "../../src/typ.ts" let hash = "" +let agenda: Agenda[] +let recent: Rec +const tags_all: Tag[] = [ + "", "进行中", "已结束", + "设施建设", "物资配给", "软件开发", + "苏州", "成都", + "工益公益", "星星家园" +] +const tags_count: number[] = [] + +async function json( + name: string +) { + const r = await fetch(`/json/${name}.json`) + return JSON.parse(await r.text()) +} function template( tid: string, @@ -34,20 +51,46 @@ function etag( function eagenda( el: HTMLElement, - { _id, name }: Agenda + agenda: Agenda[] ) { el.innerHTML = "" - const [t, [a, c, s, tag, date]] = template("agenda", ["idname", "id", "name", "tag", "date"]) - c.innerText = (a as HTMLLinkElement).href = `#${_id}` - s.innerText = name - etag(tag, ["进行中", "然后", "1232"]) - date.innerText = `公示时间: ${utc_medium(Date.now())}\n更新时间:${utc_short(Date.now())}` - el.appendChild(t) + for (const { _id, name, tag, utc } of agenda) { + const [t, [a, c, s, et, ed]] = template("agenda", ["idname", "id", "name", "tag", "date"]); + (a as HTMLLinkElement).href = `#a${_id}` + c.innerText = `a${_id}` + if (hash === c.innerText) c.classList.add("darkgray") + else c.classList.remove("darkgray") + s.innerText = name + etag(et, tag) + ed.innerText = `公示时间: ${utc_medium(utc)}\n更新时间:${utc_medium(Date.now())}` + el.appendChild(t) + } } window.addEventListener("hashchange", () => { hash = decodeURI(window.location.hash).substring(1) - etag(document.querySelector(".title div.tag")!, ["", "1232", "然后"], [3, 5, 6]) - eagenda(document.getElementById("main")!, { _id: 3, name: "标题标题" } as Agenda) + etag(document.querySelector(".title div.tag")!, tags_all, tags_count) + switch (hash[0]) { + case "u": break + case "s": break + case "a": eagenda(document.getElementById("main")!, agenda.filter(a => + a._id === parseInt(hash.substring(1)) + )); break + default: eagenda(document.getElementById("main")!, agenda.filter(a => + hash === "" || a.tag.includes(hash as Tag) + )); break + } }) -window.dispatchEvent(new Event("hashchange")) + +async function load( +) { + [agenda, recent] = await Promise.all([ + json("agenda"), json("recent"), + ]) + console.log(`loaded ${agenda.length} agenda`) + tags_count.push(agenda.length, ...tags_all.slice(1).map( + t => agenda.filter(a => a.tag.includes(t)).length) + ) + window.dispatchEvent(new Event("hashchange")) +} +load() diff --git a/ismism.ts/ui/index/index.html b/ismism.ts/ui/index/index.html index 5024be7..7cf3111 100644 --- a/ismism.ts/ui/index/index.html +++ b/ismism.ts/ui/index/index.html @@ -91,10 +91,9 @@ a.idname code.id { padding: 0.1em 8px; + border: 1px solid var(--black); border-radius: 4px; - color: var(--lightgray); - background: var(--darkgray); - text-align: center; + color: var(--black); } a.idname span.name { @@ -213,46 +212,6 @@
-
- main is here -

- p is here -

- code is here -
- a is here -
- ismist.cn is hereismist.cn is hereismist.cn is hereismist.cn is - hereismist.cn is - hereismist.cn is hereismist.cn is hereismist.cn is here -
- small is here - normal is here - large is here -
-
- section is here -
-
-
- section is here -
-
- article is here -
-
-
-
- section is here -
-
- notag - section is here -
-
- article is here -
-