🚧 Create history page

This commit is contained in:
Anand Chowdhary
2020-08-14 00:31:51 +05:30
parent 5fa6a6c074
commit 4f1589324b
3 changed files with 97 additions and 2 deletions
+80
View File
@@ -0,0 +1,80 @@
<script>
import Loading from "../components/Loading.svelte";
import { Octokit } from "@octokit/rest";
import { onMount } from "svelte";
import config from "../data/config.json";
export let number;
let loading = true;
const octokit = new Octokit({
userAgent: config["user-agent"],
});
const owner = config.owner;
const repo = config.repo;
let incidents = [];
onMount(async () => {
incidents = (
await octokit.issues.listForRepo({
owner,
repo,
state: "closed",
filter: "all",
sort: "created",
direction: "desc",
labels: `status,${number}`,
})
).data;
incidents = incidents.map((incident, index) => {
incident.showHeading =
index === 0 ||
new Date(incidents[index - 1].created_at).toLocaleDateString() !==
new Date(incident.created_at).toLocaleDateString();
return incident;
});
loading = false;
});
</script>
<style>
h2 {
margin-top: 2rem;
}
</style>
<section>
{#if loading}
<Loading />
{:else if incidents.length}
<h2>{config.i18n.pastIncidents}</h2>
{#each incidents as incident}
{#if incident.showHeading}
<h3>{new Date(incident.created_at).toLocaleDateString()}</h3>
{/if}
<article class="down link">
<div class="f">
<div>
<h4>{incident.title.replace('🛑', '').replace('⚠️', '').trim()}</h4>
<div>
{@html config.i18n.pastIncidentsResolved
.replace(
/\$MINUTES/g,
(
(new Date(incident.closed_at).getTime() -
new Date(incident.created_at).getTime()) /
60000
).toFixed(0)
)
.replace(/\$POSTS/g, incident.comments)}
</div>
</div>
<div class="f r">
<a href={`/incident/${incident.number}`}>
{config.i18n.incidentReport.replace(/\$NUMBER/g, incident.number)}
</a>
</div>
</div>
</article>
{/each}
{/if}
</section>
+4 -2
View File
@@ -43,9 +43,11 @@
{:else if sites.length}
{#each sites as site}
<article
class={site.status}
class={`${site.status} link`}
style={`background-image: url("https://raw.githubusercontent.com/${owner}/${repo}/master/graphs/${site.slug}.png`}>
<h4>{site.name}</h4>
<h4>
<a href={`/history/${site.slug}`}>{site.name}</a>
</h4>
<div>
{@html config.i18n.overallUptime.replace(/\$UPTIME/g, site.uptime)}
</div>
+13
View File
@@ -0,0 +1,13 @@
<script context="module">
export async function preload(page) {
const { number } = page.params;
return { number };
}
</script>
<script>
import History from "../../components/History.svelte";
export let number;
</script>
<History {number} />