Fix workspace selection and secret modal layout
This commit is contained in:
+30
-5
@@ -1,6 +1,4 @@
|
||||
var WS_LIST = [
|
||||
{ id: 'ws_default', slug: 'default', name: 'Default workspace', role: 'Owner', letter: 'D', color: '#0d9488' }
|
||||
];
|
||||
var WS_LIST = [];
|
||||
|
||||
var workspaceLoadPromise = null;
|
||||
var workspaceLoadFailed = false;
|
||||
@@ -41,8 +39,35 @@ function cacheCurrentWorkspace(workspace) {
|
||||
} catch (_error) {}
|
||||
}
|
||||
|
||||
function storedWorkspaceId() {
|
||||
try {
|
||||
return localStorage.getItem('crank_workspace_id') || '';
|
||||
} catch (_error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function sessionWorkspaceId() {
|
||||
if (!(window.CrankAuth && typeof window.CrankAuth.getCachedSession === 'function')) {
|
||||
return '';
|
||||
}
|
||||
var session = window.CrankAuth.getCachedSession();
|
||||
return session && session.current_workspace_id ? session.current_workspace_id : '';
|
||||
}
|
||||
|
||||
function resolveCurrentWorkspace() {
|
||||
return WS_LIST[0] || null;
|
||||
var preferredId = sessionWorkspaceId() || storedWorkspaceId();
|
||||
if (preferredId) {
|
||||
var preferred = WS_LIST.find(function(workspace) {
|
||||
return workspace.id === preferredId;
|
||||
});
|
||||
if (preferred) {
|
||||
return preferred;
|
||||
}
|
||||
}
|
||||
return WS_LIST.find(function(workspace) {
|
||||
return workspace.id === 'ws_default';
|
||||
}) || WS_LIST[0] || null;
|
||||
}
|
||||
|
||||
function updateWorkspaceHeader(workspace) {
|
||||
@@ -88,7 +113,7 @@ async function loadWorkspaces() {
|
||||
var response = await window.CrankApi.listWorkspaces();
|
||||
var items = (response && response.items ? response.items : []).map(mapWorkspace);
|
||||
if (items.length > 0) {
|
||||
WS_LIST = [items[0]];
|
||||
WS_LIST = items;
|
||||
}
|
||||
workspaceLoadFailed = false;
|
||||
} catch (_error) {
|
||||
|
||||
Reference in New Issue
Block a user