feat: Refactor sidebar components for improved structure and styling

This commit is contained in:
Will Miao
2025-08-26 15:26:45 +08:00
parent 4dc80e7f6e
commit 6df083a1d5
5 changed files with 203 additions and 114 deletions

View File

@@ -1,28 +1,24 @@
/* Folder Sidebar Styles */
.main-layout {
display: flex;
gap: 0;
width: 100%;
min-height: calc(100vh - 120px);
}
.folder-sidebar {
width: 280px;
background: var(--card-bg);
position: fixed;
top: 68px; /* Below header */
left: 0px;
width: 230px;
height: calc(100vh - 88px);
background: var(--bg-color);
border: 1px solid var(--border-color);
border-radius: var(--border-radius-base);
border-radius: var(--border-radius-xs);
overflow: hidden;
transition: all 0.3s ease;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
flex-shrink: 0;
height: fit-content;
max-height: calc(100vh - 140px);
position: sticky;
top: 20px;
z-index: var(--z-overlay);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
display: flex;
flex-direction: column;
backdrop-filter: blur(8px);
}
.folder-sidebar.collapsed {
width: 0;
border: none;
transform: translateX(-100%);
opacity: 0;
pointer-events: none;
}
@@ -32,10 +28,23 @@
align-items: center;
justify-content: space-between;
padding: 12px 16px;
background: var(--lora-accent);
color: white;
font-weight: 600;
background: var(--bg-color);
color: var(--text-color);
font-weight: 500;
font-size: 0.9em;
flex-shrink: 0;
border-bottom: 1px solid var(--border-color);
cursor: pointer;
transition: all 0.2s ease;
}
.sidebar-header:hover {
background: var(--lora-surface);
}
.sidebar-header.root-selected {
background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
color: var(--lora-accent);
}
.sidebar-header h3 {
@@ -44,37 +53,45 @@
display: flex;
align-items: center;
gap: 8px;
font-weight: 500;
}
.sidebar-close-btn {
.sidebar-toggle-close {
background: none;
border: none;
color: white;
color: var(--text-muted);
cursor: pointer;
padding: 4px;
border-radius: 4px;
opacity: 0.8;
transition: opacity 0.2s ease;
opacity: 0.6;
transition: all 0.2s ease;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
}
.sidebar-close-btn:hover {
.sidebar-toggle-close:hover {
opacity: 1;
background: rgba(255, 255, 255, 0.1);
background: var(--lora-surface);
color: var(--text-color);
}
.sidebar-content {
height: calc(100% - 45px);
flex: 1;
overflow: hidden;
display: flex;
flex-direction: column;
}
.folder-tree-container {
height: 100%;
max-height: calc(100vh - 185px);
.sidebar-tree-container {
flex: 1;
overflow-y: auto;
padding: 8px 0;
}
/* Tree Node Styles */
/* Sidebar Tree Node Styles */
.sidebar-tree-node {
position: relative;
user-select: none;
@@ -83,22 +100,23 @@
.sidebar-tree-node-content {
display: flex;
align-items: center;
padding: 6px 16px;
padding: 8px 16px;
cursor: pointer;
transition: all 0.2s ease;
font-size: 0.85em;
border-left: 3px solid transparent;
color: var(--text-color);
}
.sidebar-tree-node-content:hover {
background: var(--lora-accent);
color: white;
background: var(--lora-surface);
color: var(--text-color);
}
.sidebar-tree-node-content.selected {
background: var(--lora-accent);
color: white;
border-left-color: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.8);
background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
color: var(--lora-accent);
border-left-color: var(--lora-accent);
font-weight: 500;
}
@@ -123,15 +141,20 @@
.sidebar-tree-folder-icon {
margin-right: 8px;
color: var(--lora-accent);
opacity: 0.8;
color: var(--text-muted);
opacity: 0.7;
}
.sidebar-tree-node-content.selected .sidebar-tree-folder-icon {
color: white;
color: var(--lora-accent);
opacity: 1;
}
.sidebar-tree-node-content:hover .sidebar-tree-folder-icon {
color: var(--text-color);
opacity: 0.9;
}
.sidebar-tree-folder-name {
flex: 1;
overflow: hidden;
@@ -161,16 +184,16 @@
padding-left: 64px;
}
/* Breadcrumb Styles */
.breadcrumb-container {
/* Sidebar Breadcrumb Styles */
.sidebar-breadcrumb-container {
margin-top: 8px;
padding: 8px 0;
border-bottom: 1px solid var(--border-color);
background: var(--card-bg);
background: var(--bg-color);
border-radius: var(--border-radius-xs);
}
.breadcrumb-nav {
.sidebar-breadcrumb-nav {
display: flex;
align-items: center;
flex-wrap: wrap;
@@ -179,7 +202,7 @@
padding: 0 8px;
}
.breadcrumb-item {
.sidebar-breadcrumb-item {
display: flex;
align-items: center;
gap: 4px;
@@ -190,28 +213,43 @@
color: var(--text-muted);
}
.breadcrumb-item:hover {
background: var(--lora-accent);
color: white;
.sidebar-breadcrumb-item:hover {
background: var(--lora-surface);
color: var(--text-color);
}
.breadcrumb-item.active {
background: var(--lora-accent);
color: white;
.sidebar-breadcrumb-item.active {
background: oklch(var(--lora-accent-l) var(--lora-accent-c) var(--lora-accent-h) / 0.1);
color: var(--lora-accent);
font-weight: 500;
}
.breadcrumb-separator {
.sidebar-breadcrumb-separator {
color: var(--text-muted);
opacity: 0.6;
margin: 0 2px;
}
/* Content Area */
.content-area {
flex: 1;
min-width: 0;
margin-left: 16px;
/* Responsive Design */
@media (min-width: 2000px) {
.folder-sidebar {
width: 280px;
left: 24px;
}
}
@media (min-width: 3000px) {
.folder-sidebar {
width: 320px;
left: 32px;
}
}
@media (max-width: 1400px) {
.folder-sidebar {
width: 260px;
left: 16px;
}
}
/* Sidebar Toggle Button */
@@ -261,60 +299,94 @@
display: block;
}
/* Smooth transitions for tree nodes */
.sidebar-tree-node {
overflow: hidden;
}
.sidebar-tree-children {
transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-tree-expand-icon {
transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Visual separator for nested levels */
.sidebar-tree-children .sidebar-tree-node-content {
position: relative;
}
.sidebar-tree-children .sidebar-tree-node-content::before {
content: '';
position: absolute;
left: 8px;
top: 0;
bottom: 0;
width: 1px;
background: var(--border-color);
opacity: 0.3;
}
/* Responsive Design */
@media (max-width: 1024px) {
.folder-sidebar {
position: fixed;
top: 68px;
left: 16px;
z-index: 1000;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
max-height: calc(100vh - 88px);
width: calc(100vw - 32px);
max-width: 320px;
height: calc(100vh - 88px);
z-index: calc(var(--z-overlay) + 10);
}
.folder-sidebar.collapsed {
left: -300px;
transform: translateX(-100%);
}
.content-area {
margin-left: 0;
}
.main-layout {
flex-direction: column;
/* Mobile overlay */
.folder-sidebar:not(.collapsed)::before {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.3);
z-index: -1;
backdrop-filter: blur(2px);
}
}
@media (max-width: 768px) {
.folder-sidebar {
width: calc(100vw - 32px);
max-width: 280px;
left: 16px;
right: 16px;
}
.breadcrumb-nav {
.sidebar-breadcrumb-nav {
font-size: 0.8em;
}
.breadcrumb-item {
.sidebar-breadcrumb-item {
padding: 3px 6px;
}
}
/* Hide scrollbar but keep functionality */
.folder-tree-container::-webkit-scrollbar {
.sidebar-tree-container::-webkit-scrollbar {
width: 6px;
}
.folder-tree-container::-webkit-scrollbar-track {
.sidebar-tree-container::-webkit-scrollbar-track {
background: transparent;
}
.folder-tree-container::-webkit-scrollbar-thumb {
.sidebar-tree-container::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 3px;
}
.folder-tree-container::-webkit-scrollbar-thumb:hover {
background: var(--lora-accent);
.sidebar-tree-container::-webkit-scrollbar-thumb:hover {
background: var(--text-muted);
}

View File

@@ -671,9 +671,9 @@ export class BaseModelApiClient {
if (pageState.searchOptions.creator !== undefined) {
params.append('search_creator', pageState.searchOptions.creator.toString());
}
params.append('recursive', (pageState.searchOptions?.recursive ?? false).toString());
}
}
params.append('recursive', (pageState.searchOptions?.recursive ?? false).toString());
if (pageState.filters) {
if (pageState.filters.tags && pageState.filters.tags.length > 0) {

View File

@@ -38,8 +38,14 @@ export class SidebarManager {
toggleBtn.addEventListener('click', this.toggleSidebar);
}
// Sidebar header (root selection)
const sidebarHeader = document.getElementById('sidebarHeader');
if (sidebarHeader) {
sidebarHeader.addEventListener('click', () => this.selectFolder(''));
}
// Sidebar close button
const closeBtn = document.getElementById('sidebarCloseBtn');
const closeBtn = document.getElementById('sidebarToggleClose');
if (closeBtn) {
closeBtn.addEventListener('click', this.closeSidebar);
}
@@ -58,13 +64,12 @@ export class SidebarManager {
// Close sidebar when clicking outside on mobile
document.addEventListener('click', (e) => {
if (window.innerWidth <= 1024) {
if (window.innerWidth <= 1024 && this.isVisible) {
const sidebar = document.getElementById('folderSidebar');
const toggleBtn = document.querySelector('.sidebar-toggle-btn');
if (sidebar && !sidebar.contains(e.target) &&
toggleBtn && !toggleBtn.contains(e.target) &&
!sidebar.classList.contains('collapsed')) {
toggleBtn && !toggleBtn.contains(e.target)) {
this.closeSidebar();
}
}
@@ -121,9 +126,7 @@ export class SidebarManager {
style="${hasChildren ? '' : 'opacity: 0; pointer-events: none;'}">
<i class="fas fa-chevron-right"></i>
</div>
<div class="sidebar-tree-folder-icon">
<i class="fas fa-folder"></i>
</div>
<i class="fas fa-folder sidebar-tree-folder-icon"></i>
<div class="sidebar-tree-folder-name" title="${folderName}">${folderName}</div>
</div>
${hasChildren ? `
@@ -178,7 +181,7 @@ export class SidebarManager {
}
handleBreadcrumbClick(event) {
const breadcrumbItem = event.target.closest('.breadcrumb-item');
const breadcrumbItem = event.target.closest('.sidebar-breadcrumb-item');
if (breadcrumbItem) {
const path = breadcrumbItem.dataset.path || '';
this.selectFolder(path);
@@ -192,6 +195,7 @@ export class SidebarManager {
// Update UI
this.updateTreeSelection();
this.updateBreadcrumbs();
this.updateSidebarHeader();
// Update page state
this.pageControls.pageState.activeFolder = path || null;
@@ -255,7 +259,7 @@ export class SidebarManager {
let currentPath = '';
const breadcrumbs = [`
<span class="breadcrumb-item ${!this.selectedPath ? 'active' : ''}" data-path="">
<span class="sidebar-breadcrumb-item ${!this.selectedPath ? 'active' : ''}" data-path="">
<i class="fas fa-home"></i> All Folders
</span>
`];
@@ -264,9 +268,9 @@ export class SidebarManager {
currentPath = currentPath ? `${currentPath}/${part}` : part;
const isLast = index === parts.length - 1;
breadcrumbs.push(`<span class="breadcrumb-separator">/</span>`);
breadcrumbs.push(`<span class="sidebar-breadcrumb-separator">/</span>`);
breadcrumbs.push(`
<span class="breadcrumb-item ${isLast ? 'active' : ''}" data-path="${currentPath}">
<span class="sidebar-breadcrumb-item ${isLast ? 'active' : ''}" data-path="${currentPath}">
${part}
</span>
`);
@@ -275,6 +279,17 @@ export class SidebarManager {
breadcrumbNav.innerHTML = breadcrumbs.join('');
}
updateSidebarHeader() {
const sidebarHeader = document.getElementById('sidebarHeader');
if (!sidebarHeader) return;
if (!this.selectedPath) {
sidebarHeader.classList.add('root-selected');
} else {
sidebarHeader.classList.remove('root-selected');
}
}
toggleSidebar() {
const sidebar = document.getElementById('folderSidebar');
const toggleBtn = document.querySelector('.sidebar-toggle-btn');
@@ -332,12 +347,15 @@ export class SidebarManager {
this.selectedPath = activeFolder;
this.updateTreeSelection();
this.updateBreadcrumbs();
this.updateSidebarHeader();
// Show breadcrumb container
const breadcrumbContainer = document.getElementById('breadcrumbContainer');
if (breadcrumbContainer) {
breadcrumbContainer.classList.remove('hidden');
}
} else {
this.updateSidebarHeader();
}
}
@@ -357,9 +375,10 @@ export class SidebarManager {
destroy() {
// Clean up event handlers
const toggleBtn = document.querySelector('.sidebar-toggle-btn');
const closeBtn = document.getElementById('sidebarCloseBtn');
const closeBtn = document.getElementById('sidebarToggleClose');
const folderTree = document.getElementById('sidebarFolderTree');
const breadcrumbNav = document.getElementById('breadcrumbNav');
const sidebarHeader = document.getElementById('sidebarHeader');
if (toggleBtn) {
toggleBtn.removeEventListener('click', this.toggleSidebar);
@@ -373,5 +392,8 @@ export class SidebarManager {
if (breadcrumbNav) {
breadcrumbNav.removeEventListener('click', this.handleBreadcrumbClick);
}
if (sidebarHeader) {
sidebarHeader.removeEventListener('click', () => this.selectFolder(''));
}
}
}

View File

@@ -99,8 +99,8 @@
</div>
<!-- Breadcrumb Navigation -->
<div id="breadcrumbContainer" class="breadcrumb-container hidden">
<nav class="breadcrumb-nav" id="breadcrumbNav">
<div id="breadcrumbContainer" class="sidebar-breadcrumb-container hidden">
<nav class="sidebar-breadcrumb-nav" id="breadcrumbNav">
<!-- Breadcrumbs will be populated by JavaScript -->
</nav>
</div>

View File

@@ -17,31 +17,26 @@
{% include 'components/controls.html' %}
{% include 'components/duplicates_banner.html' %}
<div class="main-layout">
<!-- Folder Navigation Sidebar -->
<div class="folder-sidebar" id="folderSidebar">
<div class="sidebar-header">
<h3><i class="fas fa-folder-tree"></i> Folders</h3>
<button class="sidebar-close-btn" id="sidebarCloseBtn">
<i class="fas fa-times"></i>
</button>
</div>
<div class="sidebar-content">
<div class="folder-tree-container">
<div class="folder-tree" id="sidebarFolderTree">
<!-- Tree will be populated by JavaScript -->
</div>
<!-- Folder Navigation Sidebar -->
<div class="folder-sidebar" id="folderSidebar">
<div class="sidebar-header" id="sidebarHeader">
<h3><i class="fas fa-home"></i> LoRA Root</h3>
<button class="sidebar-toggle-close" id="sidebarToggleClose">
<i class="fas fa-times"></i>
</button>
</div>
<div class="sidebar-content">
<div class="sidebar-tree-container">
<div class="sidebar-tree" id="sidebarFolderTree">
<!-- Tree will be populated by JavaScript -->
</div>
</div>
</div>
<!-- Main Content Area -->
<div class="content-area">
<!-- Lora卡片容器 -->
<div class="card-grid" id="modelGrid">
<!-- Cards will be dynamically inserted here -->
</div>
</div>
</div>
<!-- Lora卡片容器 -->
<div class="card-grid" id="modelGrid">
<!-- Cards will be dynamically inserted here -->
</div>
<!-- Bulk operations panel will be inserted here by JavaScript -->