WIP: Automatically select previous server

This commit is contained in:
Jeroen De Meerleer 2023-03-20 17:03:17 +01:00
parent fa9f8d3a83
commit d43649a4b3
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -17,12 +17,21 @@
<script lang="js"> <script lang="js">
import { urls } from "../../../stores.js"; import { urls } from "../../../stores.js";
import { createEventDispatcher } from 'svelte'; import {createEventDispatcher, onMount} from 'svelte';
import {browser} from "$app/environment";
export let globals; export let globals;
const dispatch = createEventDispatcher();
var loginserver; var loginserver;
const dispatch = createEventDispatcher();
onMount(() => {
if(sessionStorage.getItem('serverurl') != undefined) {
loginserver = sessionStorage.getItem('serverurl');
handleSelectServer();
}
})
function handleSelectServer() { function handleSelectServer() {
if(!isValidHttpUrl(loginserver)) { if(!isValidHttpUrl(loginserver)) {
loginserver = 'https://' + loginserver; loginserver = 'https://' + loginserver;
@ -40,6 +49,9 @@
if(!data.login) return dispatch('message', {text: 'This server is unavailable for login currently'}) if(!data.login) return dispatch('message', {text: 'This server is unavailable for login currently'})
globals.server.url = loginserver; globals.server.url = loginserver;
globals.server.caps = data; globals.server.caps = data;
if(browser) {
sessionStorage.setItem('serverurl', loginserver);
}
}) })
.catch((error) => { .catch((error) => {
return dispatch('message', {text: 'This server is not a Blackbird Chess server'}) return dispatch('message', {text: 'This server is not a Blackbird Chess server'})