-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathStarred.razor
More file actions
123 lines (111 loc) · 5.07 KB
/
Copy pathStarred.razor
File metadata and controls
123 lines (111 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@page "/starred"
@inject VFSStateService StateService
@inject IVirtualFileSystem VFS
@inject NavigationManager Navigation
@inject ToastService Toast
@rendermode InteractiveServer
@implements IDisposable
<PageTitle>Starred - CloudDrive</PageTitle>
<div class="h-full flex flex-col bg-white">
@* Header *@
<div class="p-4 border-b border-gray-200">
<div class="flex items-center gap-3">
<svg class="w-6 h-6 text-yellow-500" fill="currentColor" viewBox="0 0 24 24">
<path d="M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.006 5.404.434c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.434 2.082-5.005Z" />
</svg>
<h1 class="text-xl font-semibold text-gray-900">Starred</h1>
</div>
<p class="text-sm text-gray-500 mt-1">Your favorite files and folders</p>
</div>
@* Content *@
<div class="flex-1 overflow-auto">
@if (!StarredItems.Any())
{
<EmptyState Title="No starred items"
Description="Star your favorite files and folders for quick access"
Icon="M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
}
else
{
<div class="divide-y divide-gray-100">
@foreach (var item in StarredItems)
{
<div class="flex items-center gap-4 px-4 py-3 hover:bg-gray-50 transition-colors @(!item.Exists ? "opacity-50" : "cursor-pointer")"
@onclick="() => OpenItem(item)">
<FileIcon IsDirectory="@item.IsDirectory" FileName="@item.Name" />
<div class="flex-1 min-w-0">
<p class="text-sm font-medium text-gray-900 truncate">@item.Name</p>
<p class="text-xs text-gray-500 truncate">@item.Path</p>
</div>
@if (!item.Exists)
{
<Badge Variant="red" Size="sm">Deleted</Badge>
}
<button class="p-1 text-yellow-500 hover:text-yellow-600 rounded-md hover:bg-yellow-50"
@onclick:stopPropagation="true"
@onclick="() => RemoveStar(item.Path)"
title="Remove star">
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.006 5.404.434c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.434 2.082-5.005Z" />
</svg>
</button>
</div>
}
</div>
}
</div>
</div>
@code {
private List<StarredItem> StarredItems => StateService.StarredPaths
.Select(path => {
var isDirectory = VFS.DirectoryExists(path);
var isFile = VFS.FileExists(path);
return new StarredItem
{
Path = path,
Name = System.IO.Path.GetFileName(path.TrimEnd('/')) ?? path,
IsDirectory = isDirectory,
Exists = isDirectory || isFile
};
})
.OrderBy(i => !i.Exists)
.ThenBy(i => !i.IsDirectory)
.ThenBy(i => i.Name)
.ToList();
protected override void OnInitialized()
{
StateService.OnItemStarred += OnItemStarred;
StateService.OnDataChanged += OnDataChanged;
}
private void OnItemStarred(string _) => InvokeAsync(StateHasChanged);
private void OnDataChanged() => InvokeAsync(StateHasChanged);
private void OpenItem(StarredItem item)
{
if (!item.Exists) return;
if (item.IsDirectory)
{
Navigation.NavigateTo(VFSStateService.ToFolderUrl(item.Path));
}
else
{
Navigation.NavigateTo($"/file?path={Uri.EscapeDataString(item.Path)}");
}
}
private void RemoveStar(string path)
{
StateService.ToggleStar(path);
Toast.ShowSuccess("Removed from starred");
}
public void Dispose()
{
StateService.OnItemStarred -= OnItemStarred;
StateService.OnDataChanged -= OnDataChanged;
}
private class StarredItem
{
public string Path { get; init; } = "";
public string Name { get; init; } = "";
public bool IsDirectory { get; init; }
public bool Exists { get; init; }
}
}