Skip to content

Commit 2d75e71

Browse files
committed
feat: show downtime news if backend is down
Fixes #436
1 parent 4e71252 commit 2d75e71

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Add loading indicators to global filter selectors [#429](https://github.com/spraakbanken/korp-frontend/issues/429)
88
- Corpus selector: expand partially selected folders by default [#431](https://github.com/spraakbanken/korp-frontend/issues/431)
9+
- Show downtime announcements if backend is down [#436](https://github.com/spraakbanken/korp-frontend/issues/436)
910
- Statistics: link cells to corpus-filtered search [#455](https://github.com/spraakbanken/korp-frontend/issues/455)
1011
- More accurate headers in KWIC CSV download
1112

app/scripts/main.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import korpLogo from "../img/korp.svg"
88
import korpFail from "../img/korp_fail.svg"
99
import { findAuthModule } from "@/auth/init"
1010
import { initAuth, setAuthModule } from "@/auth/auth"
11+
import { createMaintenanceNewsElement } from "./services/maintenance-news"
1112

1213
const createSplashScreen = () => {
1314
const splash = document.getElementById("preload")
@@ -16,6 +17,17 @@ const createSplashScreen = () => {
1617
return
1718
}
1819
splash.innerHTML = html`<img class="animate-pulse" height="300" width="300" src="${korpLogo}" />`
20+
21+
// Add maintenance news if loading is slow.
22+
const newsTimeout = 5000
23+
setTimeout(async () => {
24+
const splash = document.getElementById("preload")
25+
// Abort if app has continued loading
26+
if (!splash) return
27+
const html = await createMaintenanceNewsElement()
28+
const element = $(html).get(0)
29+
if (element) splash.append(element)
30+
}, newsTimeout)
1931
}
2032

2133
function initApp() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { html } from "@/util"
2+
import { fetchNews } from "./news-service"
3+
import { locObj } from "@/i18n"
4+
5+
/** Show simple HTML for maintenance-tagged news items. */
6+
export async function createMaintenanceNewsElement(): Promise<string> {
7+
const allItems = await fetchNews()
8+
const items = allItems.filter((item) => item.tags?.includes("maintenance"))
9+
if (!items.length) return ""
10+
11+
const htmlItems = items.map(
12+
(item) => html`
13+
<article>
14+
<heading><h3>${locObj(item.title)}</h3></heading>
15+
<div>${locObj(item.body)}</div>
16+
</article>
17+
`,
18+
)
19+
return html`<section class="maintenance-news">${htmlItems.join("\n")}</section>`
20+
}

app/scripts/services/news-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export function isEnabled(): boolean {
88
}
99

1010
export async function fetchNews(): Promise<NewsItem[]> {
11-
const response = await fetch(settings.news_url!)
11+
if (!settings.news_url) return []
12+
const response = await fetch(settings.news_url)
1213
const feedYaml: string = await response.text()
1314

1415
const itemsRaw = Yaml.load(feedYaml) as NewsItemRaw[]
@@ -45,4 +46,5 @@ export type NewsItem = {
4546
created: string
4647
title: LangString
4748
body: LangString
49+
tags?: string[]
4850
}

app/styles/styles.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,10 +1854,16 @@ line.tick {
18541854

18551855
#preload {
18561856
display: flex;
1857+
flex-direction: column;
18571858
justify-content: center;
1859+
align-items: center;
18581860
height: 100vh;
18591861
}
18601862

1863+
.maintenance-news {
1864+
width: 40em;
1865+
}
1866+
18611867
// reading mode
18621868
.word.selected {
18631869
color: #fff !important;

0 commit comments

Comments
 (0)