ui: align js with api
This commit is contained in:
+5
-7
@@ -36,6 +36,7 @@
|
||||
</div>
|
||||
<script type="module">
|
||||
import Alpine from 'alpinejs'
|
||||
import { requireAuth } from '/src/auth.js'
|
||||
import { logout, getchannels, getmessages } from '/src/api.js'
|
||||
|
||||
window.app = () => ({
|
||||
@@ -45,12 +46,9 @@
|
||||
selectedChannel: null,
|
||||
messages: [],
|
||||
async init() {
|
||||
const res = await fetch('/api/whoami')
|
||||
if (res.status === 401) {
|
||||
window.location.href = '/login.html'
|
||||
return
|
||||
}
|
||||
this.username = await res.text()
|
||||
const username = await requireAuth()
|
||||
if (!username) return
|
||||
this.username = username
|
||||
try {
|
||||
this.channels = await getchannels()
|
||||
} catch (e) {
|
||||
@@ -62,7 +60,7 @@
|
||||
this.messages = []
|
||||
this.error = ''
|
||||
try {
|
||||
const from = new Date(Date.now() - 24 * 60 * 60 * 1000)
|
||||
const from = new Date(Date.now() - 96 * 60 * 60 * 1000)
|
||||
const to = new Date(Date.now())
|
||||
this.messages = await getmessages(ch.ID, { from, to })
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user