mirror of
https://github.com/riwiwa/muzi.git
synced 2026-03-04 00:51:59 -08:00
hold current settings tab in webUI URL
This commit is contained in:
@@ -113,14 +113,30 @@
|
|||||||
|
|
||||||
<script src="/files/import.js"></script>
|
<script src="/files/import.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
function switchToTab(tabName, updateUrl = true) {
|
||||||
|
document.querySelectorAll('.tab-button').forEach(b => b.classList.remove('active'));
|
||||||
|
document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
|
||||||
|
|
||||||
|
document.querySelector(`.tab-button[data-tab="${tabName}"]`).classList.add('active');
|
||||||
|
document.getElementById(tabName).classList.add('active');
|
||||||
|
|
||||||
|
if (updateUrl) {
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('tab', tabName);
|
||||||
|
history.pushState({}, '', url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelectorAll('.tab-button').forEach(button => {
|
document.querySelectorAll('.tab-button').forEach(button => {
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
document.querySelectorAll('.tab-button').forEach(b => b.classList.remove('active'));
|
switchToTab(button.dataset.tab);
|
||||||
document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
|
|
||||||
|
|
||||||
button.classList.add('active');
|
|
||||||
document.getElementById(button.dataset.tab).classList.add('active');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const tabParam = urlParams.get('tab');
|
||||||
|
if (tabParam) {
|
||||||
|
switchToTab(tabParam, false);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func createAccount(w http.ResponseWriter, r *http.Request) {
|
|||||||
Value: sessionID,
|
Value: sessionID,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: true,
|
Secure: false,
|
||||||
SameSite: http.SameSiteLaxMode,
|
SameSite: http.SameSiteLaxMode,
|
||||||
MaxAge: 86400 * 30,
|
MaxAge: 86400 * 30,
|
||||||
})
|
})
|
||||||
@@ -157,7 +157,7 @@ func loginSubmit(w http.ResponseWriter, r *http.Request) {
|
|||||||
Value: sessionID,
|
Value: sessionID,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: true,
|
Secure: false,
|
||||||
SameSite: http.SameSiteLaxMode,
|
SameSite: http.SameSiteLaxMode,
|
||||||
MaxAge: 86400 * 30,
|
MaxAge: 86400 * 30,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func generateAPIKeyHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, "/settings", http.StatusSeeOther)
|
http.Redirect(w, r, "/settings?tab=scrobble", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSpotifyCredentialsHandler(w http.ResponseWriter, r *http.Request) {
|
func updateSpotifyCredentialsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -132,7 +132,7 @@ func updateSpotifyCredentialsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, "/settings", http.StatusSeeOther)
|
http.Redirect(w, r, "/settings?tab=scrobble", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
func spotifyConnectHandler(w http.ResponseWriter, r *http.Request) {
|
func spotifyConnectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -151,15 +151,15 @@ func spotifyConnectHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
user, err := scrobble.GetUserById(userId)
|
user, err := scrobble.GetUserById(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "spotifyConnectHandler: GetUserById error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "spotifyConnectHandler: GetUserById error: %v\n", err)
|
||||||
http.Redirect(w, r, "/settings", http.StatusSeeOther)
|
http.Redirect(w, r, "/settings?tab=scrobble", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "spotifyConnectHandler: userId=%d, SpotifyClientId=%v\n", userId, user.SpotifyClientId)
|
fmt.Fprintf(os.Stderr, "spotifyConnectHandler: SpotifyClientId is nil or empty, redirecting to settings\n")
|
||||||
|
|
||||||
if user.SpotifyClientId == nil || *user.SpotifyClientId == "" {
|
if user.SpotifyClientId == nil || *user.SpotifyClientId == "" {
|
||||||
fmt.Fprintf(os.Stderr, "spotifyConnectHandler: SpotifyClientId is nil or empty, redirecting to settings\n")
|
fmt.Fprintf(os.Stderr, "spotifyConnectHandler: SpotifyClientId is nil or empty, redirecting to settings\n")
|
||||||
http.Redirect(w, r, "/settings", http.StatusSeeOther)
|
http.Redirect(w, r, "/settings?tab=scrobble", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user