Skip to content

Commit

Permalink
Save audios list in da localstorage and fix msgbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mrilyew committed Dec 2, 2024
1 parent db5296e commit 9a81e35
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Web/static/css/audios.css
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@
width: 500px;
height: 37px;
position: fixed;
z-index: 99;
z-index: 1025;
border-radius: 3px;
}

Expand Down
55 changes: 52 additions & 3 deletions Web/static/js/al_music.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ window.player = new class {
u(this.audioPlayer).trigger('volumechange')
}

async setTrack(id) {
async setTrack(id, ref = null) {
if(!this.tracks || this.tracks.length < 1) {
makeError('Context is not loaded yet', 'Red', 5000, 1489)
return
Expand Down Expand Up @@ -313,6 +313,10 @@ window.player = new class {
}

this.is_closed = false
if(ref != 'localstorage') {
this.dump()
}

this.__updateFace()
u(this.audioPlayer).trigger('volumechange')
}
Expand Down Expand Up @@ -405,6 +409,35 @@ window.player = new class {
return u('.bigPlayer').length > 0
}

dump() {
const final = {
context: this.context,
current_track_id: this.current_track_id,
tracks: this.tracks,
time: this.audioPlayer.currentTime,
}

localStorage.setItem('audio.lastDump', JSON.stringify(final))
console.log('Audio | Tracks was dumped')
}

undump() {
localStorage.setItem('audio.lastDump', null)
}

async loadDump(dump_object) {
this.context = dump_object.context
this.current_track_id = dump_object.current_track_id
this.tracks = dump_object.tracks
if(this.current_track_id) {
await this.setTrack(this.current_track_id, 'localstorage')
}

if(dump_object.time) {
this.audioPlayer.currentTime = dump_object.time
}
}

// Добавляем ощущение продуманности.
__highlightActiveTrack() {
u(`.audiosContainer .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry, .audios_padding .audioEmbed[data-realid='${this.current_track_id}'] .audioEntry`).addClass('nowPlaying')
Expand Down Expand Up @@ -432,7 +465,6 @@ window.player = new class {
}

async _handlePageTransition() {
console.log('Audio | Switched page :3')
const state = this.isAtAudiosPage()
if(!state) {
// AJAX audio player
Expand Down Expand Up @@ -721,7 +753,22 @@ window.player = new class {
}

document.addEventListener("DOMContentLoaded", async () => {
await window.player.init(window.__current_page_audio_context)
let parsed = null
try {
parsed = JSON.parse(localStorage.getItem('audio.lastDump'))
} catch(e) {}

if(parsed) {
await window.player.init(null)
await window.player.loadDump(parsed)
if(!window.player.isAtAudiosPage()) {
window.player.ajReveal()
window.player.__updateFace()
u(window.player.audioPlayer).trigger('timeupdate')
}
} else {
await window.player.init(window.__current_page_audio_context)
}
})

u(document).on('click', '.audioEntry .playerButton > .playIcon', async (e) => {
Expand Down Expand Up @@ -1190,8 +1237,10 @@ u(document).on('contextmenu', '.bigPlayer, .audioEmbed, #ajax_audio_player', (e)
ctx_u.find('#audio_ctx_clear_context').on('click', (ev) => {
const old_url = window.player.context.object.url
window.player.pause()
window.player.ajClose()
window.player.__resetContext()
window.player.__updateFace()
window.player.undump()
window.router.route(old_url)
})
})
Expand Down
7 changes: 5 additions & 2 deletions Web/static/js/al_wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ async function OpenVideo(video_arr = [], init_player = true)

u('body').append(miniplayer)
miniplayer.find('.miniplayer-body').nodes[0].append(msgbox.getNode().find('.center-part > *').nodes[0])
miniplayer.attr('style', `left:100px;top:${scrollY}px;`)
miniplayer.attr('style', `left:100px;top:0px;`)
miniplayer.find('#__miniplayer_return').on('click', (e) => {
msgbox.reveal()
msgbox.getNode().find('.center-part').nodes[0].append(miniplayer.find('.miniplayer-body > *').nodes[0])
Expand Down Expand Up @@ -2218,7 +2218,6 @@ $(document).on("click", "#add_image", (e) => {
let video = document.querySelector("#_takeSelfieFrame video")

if(!navigator.mediaDevices) {
// ех вот бы месседжбоксы были бы классами
u("body").removeClass("dimmed");
document.querySelector("html").style.overflowY = "scroll"
u(".ovk-diag-cont").remove();
Expand Down Expand Up @@ -2365,6 +2364,10 @@ async function __processPaginatorNextPage(page)
window.player.loadContext(page)
}

/*if(window.router) {
window.router.savePreviousPage()
}*/

const new_url = new URL(location.href)
new_url.hash = page
history.replaceState(null, null, new_url)
Expand Down
4 changes: 2 additions & 2 deletions Web/static/js/messagebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CMessageBox {

__exitDialog() {
this.getNode().remove()
if(u('.ovk-msg-all').length < 1) {
if(u('.ovk-msg-all:not(.msgbox-hidden)').length < 1) {
u('body').removeClass('dimmed')
u('html').attr('style', 'overflow-y:scroll')
}
Expand All @@ -101,7 +101,7 @@ class CMessageBox {
hide() {
u('body').removeClass('dimmed')
u('html').attr('style', 'overflow-y:scroll')
this.getNode().attr('style', 'display: none;')
this.getNode().attr('style', 'display: none;').addClass('msgbox-hidden')
this.hidden = true
}

Expand Down
25 changes: 23 additions & 2 deletions Web/static/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ window.router = new class {
})
}

async __integratePage() {
window.scrollTo(0, 0)
async __integratePage(scrolling = null) {
window.scrollTo(0, scrolling ?? 0)
bsdnHydrate()

if(u('.paginator:not(.paginator-at-top)').length > 0) {
Expand All @@ -120,6 +120,7 @@ window.router = new class {
}

if(window.player) {
window.player.dump()
await window.player._handlePageTransition()
}
}
Expand Down Expand Up @@ -158,6 +159,14 @@ window.router = new class {
return true
}

savePreviousPage() {
this.prev_page_html = {
url: location.href,
pathname: location.pathname,
html: u('.page_body').html(),
}
}

async route(params = {}) {
if(typeof params == 'string') {
params = {
Expand All @@ -176,6 +185,10 @@ window.router = new class {
return
}

if(this.prev_page_html && this.prev_page_html.pathname != location.pathname) {
this.prev_page_html = null
}

const push_url = params.push_state ?? true
const next_page_url = new URL(url)
if(push_url) {
Expand Down Expand Up @@ -342,6 +355,14 @@ u(document).on('submit', 'form', async (e) => {

window.addEventListener('popstate', (e) => {
e.preventDefault();
/*if(window.router.prev_page_html) {
u('.page_body').html(window.router.prev_page_html.html)
history.replaceState({'from_router': 1}, '', window.router.prev_page_html.url)
window.router.prev_page_html = null
window.router.__integratePage()
return
}*/

window.router.route({
url: location.href,
push_state: false,
Expand Down

0 comments on commit 9a81e35

Please sign in to comment.