refactor: Modularize JavaScript Code into Separate Files
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s
This commit is contained in:
23
public/js/session.js
Normal file
23
public/js/session.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { $nameDisplay, $nameLobby } from './dom.js';
|
||||
import { state } from './state.js';
|
||||
import { sendMsg } from './ws.js';
|
||||
|
||||
// If we have a stored player name, set it in the input and send to server
|
||||
export function reusePlayerName() {
|
||||
const stored = localStorage.getItem('playerName');
|
||||
if (!stored) return;
|
||||
if ($nameLobby && $nameLobby.value !== stored) {
|
||||
$nameLobby.value = stored;
|
||||
}
|
||||
if ($nameDisplay) {
|
||||
$nameDisplay.textContent = stored;
|
||||
}
|
||||
sendMsg({ type: 'set_name', name: stored });
|
||||
}
|
||||
|
||||
export function reconnectLastRoom() {
|
||||
const last = state.room?.id || localStorage.getItem('lastRoomId');
|
||||
if (last && !localStorage.getItem('sessionId')) {
|
||||
sendMsg({ type: 'join_room', code: last });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user