feat(sidebar): add adaptive search to context menu folder list
- Show search input when 8+ folders exist - Scrollable folder list with max-height - Filter folders as user types - "No folders match" message when search has no results - Search resets when context menu closes
This commit is contained in:
1 parent
2c907ea726
commit
83cbfc51c2
1 file changed
+90
-5
@@ -112,6 +112,16 @@
|
|||||||
playlist: null,
|
playlist: null,
|
||||||
currentFolderId: null
|
currentFolderId: null
|
||||||
});
|
});
|
||||||
|
let contextMenuSearch = $state('');
|
||||||
|
const FOLDER_SEARCH_THRESHOLD = 8;
|
||||||
|
|
||||||
|
// Filtered folders for context menu
|
||||||
|
const filteredContextFolders = $derived.by(() => {
|
||||||
|
const available = folders.filter(f => f.id !== contextMenu.currentFolderId);
|
||||||
|
if (!contextMenuSearch.trim()) return available;
|
||||||
|
const query = contextMenuSearch.toLowerCase();
|
||||||
|
return available.filter(f => f.name.toLowerCase().includes(query));
|
||||||
|
});
|
||||||
|
|
||||||
// Offline state
|
// Offline state
|
||||||
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
|
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
|
||||||
@@ -649,6 +659,7 @@
|
|||||||
|
|
||||||
function closeContextMenu() {
|
function closeContextMenu() {
|
||||||
contextMenu = { ...contextMenu, visible: false };
|
contextMenu = { ...contextMenu, visible: false };
|
||||||
|
contextMenuSearch = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleMoveToFolder(folderId: string | null) {
|
async function handleMoveToFolder(folderId: string | null) {
|
||||||
@@ -978,17 +989,31 @@
|
|||||||
|
|
||||||
<!-- Playlist Context Menu -->
|
<!-- Playlist Context Menu -->
|
||||||
{#if contextMenu.visible}
|
{#if contextMenu.visible}
|
||||||
|
{@const availableFolders = folders.filter(f => f.id !== contextMenu.currentFolderId)}
|
||||||
|
{@const showSearch = availableFolders.length >= FOLDER_SEARCH_THRESHOLD}
|
||||||
<div
|
<div
|
||||||
class="context-menu"
|
class="context-menu"
|
||||||
|
class:has-search={showSearch}
|
||||||
style="left: {contextMenu.x}px; top: {contextMenu.y}px;"
|
style="left: {contextMenu.x}px; top: {contextMenu.y}px;"
|
||||||
onclick={(e) => e.stopPropagation()}
|
onclick={(e) => e.stopPropagation()}
|
||||||
role="menu"
|
role="menu"
|
||||||
>
|
>
|
||||||
{#if folders.length > 0}
|
{#if availableFolders.length > 0}
|
||||||
<div class="context-menu-section">
|
<div class="context-menu-section">
|
||||||
<span class="context-menu-label">Move to folder</span>
|
<span class="context-menu-label">Move to folder</span>
|
||||||
{#each folders as folder (folder.id)}
|
{#if showSearch}
|
||||||
{#if folder.id !== contextMenu.currentFolderId}
|
<div class="context-menu-search">
|
||||||
|
<Search size={14} />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Search folders..."
|
||||||
|
bind:value={contextMenuSearch}
|
||||||
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
<div class="context-menu-folders" class:scrollable={showSearch}>
|
||||||
|
{#each filteredContextFolders as folder (folder.id)}
|
||||||
<button
|
<button
|
||||||
class="context-menu-item"
|
class="context-menu-item"
|
||||||
onclick={() => handleMoveToFolder(folder.id)}
|
onclick={() => handleMoveToFolder(folder.id)}
|
||||||
@@ -996,8 +1021,13 @@
|
|||||||
<Folder size={14} />
|
<Folder size={14} />
|
||||||
{folder.name}
|
{folder.name}
|
||||||
</button>
|
</button>
|
||||||
|
{/each}
|
||||||
|
{#if showSearch && filteredContextFolders.length === 0}
|
||||||
|
<div class="context-menu-empty">
|
||||||
|
No folders match
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if contextMenu.currentFolderId}
|
{#if contextMenu.currentFolderId}
|
||||||
@@ -1009,7 +1039,7 @@
|
|||||||
Move to root
|
Move to root
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if folders.length === 0 && !contextMenu.currentFolderId}
|
{#if availableFolders.length === 0 && !contextMenu.currentFolderId}
|
||||||
<div class="context-menu-empty">
|
<div class="context-menu-empty">
|
||||||
No folders yet
|
No folders yet
|
||||||
</div>
|
</div>
|
||||||
@@ -1613,6 +1643,10 @@
|
|||||||
z-index: 10002;
|
z-index: 10002;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.context-menu.has-search {
|
||||||
|
min-width: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
.context-menu-section {
|
.context-menu-section {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -1627,6 +1661,57 @@
|
|||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.context-menu-search {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-search input {
|
||||||
|
flex: 1;
|
||||||
|
background: var(--bg-primary);
|
||||||
|
border: 1px solid var(--bg-tertiary);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 6px 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-primary);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-search input:focus {
|
||||||
|
border-color: var(--accent-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-search input::placeholder {
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-folders {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-folders.scrollable {
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-folders.scrollable::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-folders.scrollable::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context-menu-folders.scrollable::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--bg-tertiary);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.context-menu-item {
|
.context-menu-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
Reference in new issue
Block a user