diff --git a/muxplex/frontend/app.js b/muxplex/frontend/app.js index f99ac04..e5aa2d3 100644 --- a/muxplex/frontend/app.js +++ b/muxplex/frontend/app.js @@ -2133,6 +2133,30 @@ async function createNewSession(name, remoteId) { const res = await api('POST', endpoint, { name }); const data = await res.json(); const sessionName = data.name || name; + + // Auto-add to active user view (not 'all' or 'hidden') + if (_activeView !== 'all' && _activeView !== 'hidden') { + var views = (_serverSettings && _serverSettings.views) || []; + var viewIdx = -1; + for (var vi = 0; vi < views.length; vi++) { + if (views[vi].name === _activeView) { viewIdx = vi; break; } + } + if (viewIdx >= 0) { + var newSessionKey = remoteId ? (remoteId + ':' + sessionName) : sessionName; + if (!remoteId && _serverSettings && _serverSettings.device_id) { + newSessionKey = _serverSettings.device_id + ':' + sessionName; + } + var updatedViews = JSON.parse(JSON.stringify(views)); + if (!updatedViews[viewIdx].sessions.includes(newSessionKey)) { + updatedViews[viewIdx].sessions.push(newSessionKey); + api('PATCH', '/api/settings', { views: updatedViews }).catch(function(err) { + console.warn('[createNewSession] auto-add to view failed:', err); + }); + if (_serverSettings) _serverSettings.views = updatedViews; + } + } + } + showToast('Creating session \'' + sessionName + '\'…'); // Inject a loading placeholder tile so the user sees feedback immediately diff --git a/muxplex/tests/test_frontend_js.py b/muxplex/tests/test_frontend_js.py index 00815e2..507e966 100644 --- a/muxplex/tests/test_frontend_js.py +++ b/muxplex/tests/test_frontend_js.py @@ -3093,3 +3093,22 @@ def test_set_active_view_helper_exported() -> None: assert "_setActiveView" in exports, ( "module.exports must export _setActiveView test helper" ) + + +# --------------------------------------------------------------------------- +# Auto-add session to active user view on creation (task-3-auto-add-to-view) +# --------------------------------------------------------------------------- + + +def test_create_new_session_references_active_view() -> None: + """createNewSession must reference _activeView to auto-add the new session to the active user view.""" + match = re.search( + r"async function createNewSession\s*\([\w,\s]+\)\s*\{(.*?)(?=\nasync function |\nfunction |\n// )", + _JS, + re.DOTALL, + ) + assert match, "createNewSession function not found" + body = match.group(1) + assert "_activeView" in body, ( + "createNewSession must reference _activeView to auto-add new session to the active user view" + )