Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions src/routes/workspaces/[workspaceId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -106,62 +106,23 @@
}
$: if (!isWorkspaceLoading && selectedFilePath !== activeFilePath) {
console.log(`reactive nav! active: ${activeFilePath}, selected: ${selectedFilePath}`);
// the UI's selected file doesn't match our actively loaded file, try to navigate to selected
maybeNavigate(selectedFilePath);
}
async function maybeNavigate(nextPath: string | null) {
// don't navigate if the selected path is a text file and not a folder or binary
// treat `null` as a navigable path so we can intentionally unload the editor file rather than skipping
const isNavigableFileOrNull = (nextPath && isNavigableFile(workspaceTreeMap[nextPath]?.type)) || nextPath === null;
if (!isNavigableFileOrNull) {
// wait a tick then revert selected UI to the existing active path
await tick();
selectedFilePath = activeFilePath;
return;
}
const didNavigate = await goToSequence(nextPath);
if (!didNavigate) {
// user decided not to navigate away due to unsaved changes, set selected UI back to active file
selectedFilePath = activeFilePath;
return;
}
// successfully navigated, update activeFilePath & get the file contents
activeFilePath = nextPath;
if (activeFilePath) {
const { filename } = separateFilenameFromPath(activeFilePath);
getSelectedFileContent(activeFilePath);
availableActionsForActiveFile = getAvailableActionsForNodes(allActionsForWorkspace, [
workspaceTreeMap[activeFilePath],
]);
if (filename) {
selectedFileName = filename;
selectedFileType = workspaceTreeMap[activeFilePath]?.type ?? null;
} else {
selectedFileName = undefined;
selectedFileType = null;
}
} else {
// navigated to a null/empty file, reset the editor contents
initialSelectedFileContent = '';
updatedSelectedFileContent = initialSelectedFileContent;
selectedFileName = undefined;
selectedFileType = null;
}
}
$: if (initialWorkspace || $workspace) {
const ws: Workspace = $workspace ?? (initialWorkspace as Workspace);
hasEditWorkspacePermission = featurePermissions.workspace.canUpdate(user, ws);
hasEditWorkspaceCollaboratorsPermission = featurePermissions.workspaceCollaborators.canCreate(user, ws);
if (activeFilePath) {
if (activeFilePath && workspaceTreeMap[activeFilePath]) {
hasEditFilePermission = featurePermissions.workspace.canUpdate(user, ws, workspaceTreeMap[activeFilePath]);
availableActionsForActiveFile = getAvailableActionsForNodes(allActionsForWorkspace, [
workspaceTreeMap[activeFilePath],
]);
} else {
hasEditFilePermission = featurePermissions.workspace.canUpdate(user, ws);
availableActionsForActiveFile = [];
}
}
Expand Down Expand Up @@ -216,6 +177,45 @@
}
}
async function maybeNavigate(nextPath: string | null) {
// don't navigate if the selected path is a text file and not a folder or binary
// treat `null` as a navigable path so we can intentionally unload the editor file rather than skipping
const isNavigableFileOrNull = (nextPath && isNavigableFile(workspaceTreeMap[nextPath]?.type)) || nextPath === null;
if (!isNavigableFileOrNull) {
// wait a tick then revert selected UI to the existing active path
await tick();
selectedFilePath = activeFilePath;
return;
}
const didNavigate = await goToSequence(nextPath);
if (!didNavigate) {
// user decided not to navigate away due to unsaved changes, set selected UI back to active file
selectedFilePath = activeFilePath;
return;
}
// successfully navigated, update activeFilePath & get the file contents
activeFilePath = nextPath;
if (activeFilePath) {
const { filename } = separateFilenameFromPath(activeFilePath);
getSelectedFileContent(activeFilePath);
if (filename) {
selectedFileName = filename;
selectedFileType = workspaceTreeMap[activeFilePath]?.type ?? null;
} else {
selectedFileName = undefined;
selectedFileType = null;
}
} else {
// navigated to a null/empty file, reset the editor contents
initialSelectedFileContent = '';
updatedSelectedFileContent = initialSelectedFileContent;
selectedFileName = undefined;
selectedFileType = null;
}
}
function resetRefreshInterval() {
if (refreshInterval !== null) {
clearInterval(refreshInterval);
Expand Down
Loading