Heavily improved forum readability

This commit is contained in:
2017-06-20 15:46:49 +02:00
parent ef6c5aaea0
commit 76d43f9f43
12 changed files with 63 additions and 14 deletions

View File

@ -45,9 +45,13 @@ export class AnimeNotifier {
onPopState(e: PopStateEvent) {
if(e.state) {
this.app.load(e.state, false)
this.app.load(e.state, {
addToHistory: false
})
} else if(this.app.currentPath !== this.app.originalPath) {
this.app.load(this.app.originalPath, false)
this.app.load(this.app.originalPath, {
addToHistory: false
})
}
}

View File

@ -1,3 +1,8 @@
class LoadOptions {
addToHistory?: boolean
forceReload?: boolean
}
export class Application {
ajaxClass: string
fadeOutClass: string
@ -46,11 +51,19 @@ export class Application {
})
}
load(url: string, addToHistory: boolean) {
load(url: string, options?: LoadOptions) {
if(this.lastRequest) {
this.lastRequest.abort()
this.lastRequest = null
}
if(!options) {
options = new LoadOptions()
}
if(options.addToHistory === undefined) {
options.addToHistory = true
}
this.currentPath = url
@ -70,7 +83,7 @@ export class Application {
// Wait for the network request to end.
request.then(html => {
// Add to browser history
if(addToHistory)
if(options.addToHistory)
history.pushState(url, null, url)
// Set content
@ -144,7 +157,7 @@ export class Application {
return
// Load requested page
self.load(url, true)
self.load(url)
}
}
}

5
scripts/Diff.ts Normal file
View File

@ -0,0 +1,5 @@
export class Diff {
static update(element: HTMLElement, html: string) {
element.innerHTML = html
}
}

View File

@ -1,5 +1,6 @@
import { Application } from "./Application"
import { AnimeNotifier } from "./AnimeNotifier"
import { Diff } from "./Diff"
// Add anime to collection
export function addAnimeToCollection(arn: AnimeNotifier, button: HTMLElement) {
@ -19,7 +20,11 @@ export function addAnimeToCollection(arn: AnimeNotifier, button: HTMLElement) {
throw body
}
return arn.app.load("/+" + userNick + "/animelist/" + animeId, true)
return fetch("/_" + arn.app.currentPath, {
credentials: "same-origin"
})
.then(response => response.text())
.then(html => Diff.update(arn.app.content, html))
})
.catch(console.error)
.then(() => arn.loading(false))
@ -43,7 +48,7 @@ export function removeAnimeFromCollection(arn: AnimeNotifier, button: HTMLElemen
throw body
}
return arn.app.load("/+" + userNick + "/animelist", true)
return arn.app.load("/+" + userNick + "/animelist")
})
.catch(console.error)
.then(() => arn.loading(false))