Skip to content

Commit

Permalink
Fixes for storing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Jul 15, 2023
1 parent dd2eda0 commit fd46c03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions public/game/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const apiUrl = 'https://api.slaytheweb.cards/api/runs'
* @param {string} name
* @returns {Promise}
*/
export function postRun(game, name) {
export async function postRun(game, name) {
const run = {
name: name || 'Unknown entity',
win: isDungeonCompleted(game.state),
state: game.state,
past: game.past.list,
past: game.past,
}

let body
Expand All @@ -34,14 +34,16 @@ export function postRun(game, name) {
throw new Error('Could not stringify run')
}

return fetch(apiUrl, {
const res = await fetch(apiUrl, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body,
})
console.log(res.status, res.statusText)
return res
}

/**
Expand Down
8 changes: 4 additions & 4 deletions public/stats/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover"
/>
<link rel="manifest" href="manifest.webmanifest" />
<link rel="manifest" href="/manifest.webmanifest" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="theme-color" content="#116f54" />
<meta name="msapplication-TileColor" content="#116f54" />
<link rel="icon" type="image/png" href="/ui/images/favicons/favicon-512.png" sizes="512x512" />
<link rel="shortcut icon" href="/ui/images/favicons/favicon.ico" />
<link rel="apple-touch-icon" href="/ui/images/favicon-512.png" />
<link rel="stylesheet" href="ui/index.css" />
<link rel="stylesheet" href="/ui/index.css" />
</head>

<body style="overflow: auto">
<div id="root"></div>
<script type="module">
import {html, render, Component} from '../web_modules/htm/preact/standalone.module.js'
import {getRuns} from './game/backend.js'
import {getRuns} from '../game/backend.js'

getRuns().then((runs) => {
console.log(runs)
Expand Down Expand Up @@ -51,7 +51,7 @@ <h2>Highscores, statistics</h2>
const date = new Intl.DateTimeFormat('en', {
dateStyle: 'long',
timeStyle: 'short',
}).format(new Date(run.date))
}).format(new Date(run.createdAt))
return html`<tr>
<td>${date}</td>
<td>${run.name}</td>
Expand Down

0 comments on commit fd46c03

Please sign in to comment.