Nice little directory browser :D
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat/api/Files: implement sorting by size,time

+24 -8
+24 -8
Components/Pages/api/Files.razor
··· 104 104 private DirectoryInfo _realPath; 105 105 private SortByColumns _sortByColumn; 106 106 private SortByDirection _sortByDirection; 107 - private IEnumerable<FileRow> _rows; 107 + private IOrderedEnumerable<FileRow> _rows; 108 108 109 109 protected override Task OnInitializedAsync() { 110 110 if (String.IsNullOrEmpty(Path)) ··· 123 123 _sortByDirection = SortAsc switch { 124 124 "on" => SortByDirection.Ascending, 125 125 _ => SortByDirection.Descending 126 - 127 126 }; 128 - _rows = _realPath.EnumerateFileSystemInfos() 127 + 128 + _rows = _realPath.EnumerateFileSystemInfos() 129 129 .Select(fsi => new FileRow(fsi, Path ?? "/")) 130 - .OrderByDescending(x => !x.IsFile) 131 - .ThenBy(x => x.Name); 130 + .OrderByDescending(x => !x.IsFile); 132 131 133 - // Console.WriteLine($"Path <{Path}> | Col <{SortByColumn}> | Dir <{SortAsc}>"); 134 - // Console.WriteLine($"RealPath <{_realPath}> | Col <{_sortByColumn}> | Dir <{_sortByDirection}>"); 132 + if (_sortByDirection == SortByDirection.Ascending) { 133 + _rows = _sortByColumn switch { 134 + SortByColumns.Name => _rows.ThenBy(x => x.Name), 135 + SortByColumns.Size => _rows.ThenBy(x => x.Size), 136 + SortByColumns.Time => _rows.ThenBy(x => x.TimeUnix) 137 + }; 138 + 139 + if (_sortByColumn != SortByColumns.Name) 140 + _rows = _rows.ThenBy(x => x.Name); 141 + } else { 142 + _rows = _sortByColumn switch { 143 + SortByColumns.Name => _rows.ThenByDescending(x => x.Name), 144 + SortByColumns.Size => _rows.ThenByDescending(x => x.Size), 145 + SortByColumns.Time => _rows.ThenByDescending(x => x.TimeUnix) 146 + }; 147 + 148 + if (_sortByColumn != SortByColumns.Name) 149 + _rows = _rows.ThenByDescending(x => x.Name); 150 + } 135 151 136 152 return base.OnInitializedAsync(); 137 153 } ··· 185 201 : Utils.GetIconForFileType(Fsi); 186 202 Name = baseFsi.Name; // specifically want whatever its called in the directory we're looking at 187 203 IsDotFile = Name.StartsWith('.'); 188 - Size = IsBad || !IsFile ? -1 : ((FileInfo)Fsi).Length; 204 + Size = IsBad || !IsFile ? 0 : ((FileInfo)Fsi).Length; 189 205 TimeFmtDate = _dt.ToString("yyyy-MM-dd"); 190 206 TimeFmtTime = _dt.ToString("HH:mm"); 191 207 TimeUnix = $"{_dt.Subtract(DateTime.UnixEpoch).TotalSeconds:N0}";