mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-16 09:41:23 +00:00
refac
This commit is contained in:
parent
250108302e
commit
2e55c36564
3 changed files with 14 additions and 12 deletions
|
|
@ -108,7 +108,6 @@
|
|||
> = {};
|
||||
let dirtyFiles: Record<string, boolean> = {};
|
||||
let fileContexts: Record<string, TerminalContext | null> = {};
|
||||
let gitDirectories: Record<string, string | null> = {};
|
||||
let panelTarget: HTMLElement | null = null;
|
||||
let initialized = false;
|
||||
let tabsChatId = chatId;
|
||||
|
|
@ -165,9 +164,10 @@
|
|||
$: activeTabId = tabs.activeId;
|
||||
$: activeTab = tabs.tabs.find((tab) => tab.id === tabs.activeId);
|
||||
$: terminalContext = fileContexts[tabs.activeId] ?? activeTab?.context ?? null;
|
||||
// Resolve before reactive Files-tab creation, which can run later in the same update.
|
||||
$: gitConnection =
|
||||
mounted &&
|
||||
tabs.tabs.length > 0 &&
|
||||
$config?.features?.enable_tool_servers &&
|
||||
(tabs.tabs.find((tab) => tab.id === tabs.activeId)?.connection ??
|
||||
resolveTerminalConnection(
|
||||
tabs.tabs.find((tab) => tab.id === tabs.activeId)?.terminalId ?? $selectedTerminalId,
|
||||
|
|
@ -305,7 +305,6 @@
|
|||
tabs = removeTab(tabs, id);
|
||||
delete dirtyFiles[id];
|
||||
delete fileContexts[id];
|
||||
delete gitDirectories[id];
|
||||
if (!tabs.tabs.length) showTabs.set(false);
|
||||
await tick();
|
||||
document.getElementById(domId(tabs.activeId))?.focus();
|
||||
|
|
@ -469,7 +468,6 @@
|
|||
tabs = removeTab(tabs, tab.id);
|
||||
delete dirtyFiles[tab.id];
|
||||
delete fileContexts[tab.id];
|
||||
delete gitDirectories[tab.id];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -522,7 +520,6 @@
|
|||
tabs = emptyTabs();
|
||||
dirtyFiles = {};
|
||||
fileContexts = {};
|
||||
gitDirectories = {};
|
||||
initialized = false;
|
||||
commentTarget = {};
|
||||
}
|
||||
|
|
@ -905,7 +902,6 @@
|
|||
overlay={dragged}
|
||||
{chatId}
|
||||
bind:terminalContext={fileContexts[tab.id]}
|
||||
bind:gitDirectory={gitDirectories[tab.id]}
|
||||
/>
|
||||
{:else if tab.kind === 'files' && codeInterpreterEnabled}
|
||||
<PyodideFileNav overlay={dragged} />
|
||||
|
|
@ -918,14 +914,14 @@
|
|||
{$i18n.t('Open a tab using the + menu.')}
|
||||
</div>{/if}
|
||||
</div>
|
||||
{#if gitConnection}
|
||||
{#if gitConnection && tabs.tabs.length}
|
||||
<GitBar
|
||||
bind:status={gitStatus}
|
||||
bind:diffMode={gitDiffMode}
|
||||
bind:hideWhitespace={gitHideWhitespace}
|
||||
connection={gitConnection}
|
||||
{chatId}
|
||||
directory={gitDirectories[tabs.activeId] ?? terminalContext?.currentDirectory ?? '.'}
|
||||
directory={terminalContext?.currentDirectory ?? '.'}
|
||||
active={!!$showTabs}
|
||||
onOpenFile={(path) => openFile(path, gitConnection.selector)}
|
||||
onOpenDirectory={(path) => openFiles(gitConnection.selector, path)}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@
|
|||
export let overlay = false;
|
||||
export let active = true;
|
||||
export let gitStatus: GitStatus | null = null;
|
||||
export let gitDirectory: string | null = null;
|
||||
export let gitConnection: TerminalConnection | null = null;
|
||||
export let gitDiffMode: 'unified' | 'split' = 'unified';
|
||||
export let gitHideWhitespace = false;
|
||||
|
|
@ -1024,9 +1023,10 @@
|
|||
selectedFileWritable = true;
|
||||
clearFilePreview();
|
||||
clearSelection();
|
||||
if (!options.preserveTree || directory !== currentPath) gitDirectory = directory;
|
||||
if (!options.preserveTree || directory !== currentPath || !terminalContext) {
|
||||
terminalContext = { terminalId: effectiveTerminalId, currentDirectory: directory };
|
||||
}
|
||||
currentPath = directory;
|
||||
terminalContext = { terminalId: effectiveTerminalId, currentDirectory: directory };
|
||||
savedPath = directory;
|
||||
pushNavHistory(directory);
|
||||
|
||||
|
|
@ -1089,7 +1089,7 @@
|
|||
}
|
||||
|
||||
expandedDirs = new Set(expandedDirs).add(directory);
|
||||
gitDirectory = directory;
|
||||
terminalContext = { terminalId: effectiveTerminalId, currentDirectory: directory };
|
||||
saveTreeState();
|
||||
|
||||
const result = await fetchExpandedDir(directory);
|
||||
|
|
@ -2108,6 +2108,7 @@
|
|||
}}
|
||||
breadcrumbs={buildBreadcrumbs(currentPath)}
|
||||
{selectedFile}
|
||||
fileSize={openedFile?.size ?? pendingFile?.size}
|
||||
{loading}
|
||||
{showSearch}
|
||||
onToggleSearch={toggleSearch}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@
|
|||
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
import Check from '$lib/components/icons/Check.svelte';
|
||||
import { formatFileSize } from '$lib/utils';
|
||||
|
||||
export let dragType = 'application/x-terminal-file-move';
|
||||
const i18n: any = getContext('i18n');
|
||||
|
||||
export let breadcrumbs: { label: string; path: string }[] = [];
|
||||
export let selectedFile: string | null = null;
|
||||
export let fileSize: number | undefined = undefined;
|
||||
export let loading = false;
|
||||
export let writable = true;
|
||||
export let viewMode: 'grid' | 'list' | null = null;
|
||||
|
|
@ -159,6 +161,9 @@
|
|||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{#if selectedFile && fileSize !== undefined}
|
||||
<span class="shrink-0 text-[0.6875rem] text-gray-400">{formatFileSize(fileSize)}</span>
|
||||
{/if}
|
||||
{#if selectedFile && (gitFile || gitDiffOpen)}
|
||||
<Tooltip content={gitDiffOpen ? $i18n.t('Hide diff') : $i18n.t('Show diff')}>
|
||||
<button
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue