👽 Update the indexed file api calls
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:island/models/file.dart';
|
||||
import 'package:island/models/folder.dart';
|
||||
|
||||
part 'file_list_item.freezed.dart';
|
||||
|
||||
@freezed
|
||||
sealed class FileListItem with _$FileListItem {
|
||||
const factory FileListItem.file(SnCloudFileIndex fileIndex) = FileItem;
|
||||
const factory FileListItem.folder(SnCloudFolder folder) = FolderItem;
|
||||
const factory FileListItem.folder(String folderName) = FolderItem;
|
||||
const factory FileListItem.unindexedFile(SnCloudFile file) =
|
||||
UnindexedFileItem;
|
||||
}
|
||||
|
||||
@@ -122,11 +122,11 @@ return unindexedFile(_that);case _:
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( SnCloudFileIndex fileIndex)? file,TResult Function( SnCloudFolder folder)? folder,TResult Function( SnCloudFile file)? unindexedFile,required TResult orElse(),}) {final _that = this;
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( SnCloudFileIndex fileIndex)? file,TResult Function( String folderName)? folder,TResult Function( SnCloudFile file)? unindexedFile,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case FileItem() when file != null:
|
||||
return file(_that.fileIndex);case FolderItem() when folder != null:
|
||||
return folder(_that.folder);case UnindexedFileItem() when unindexedFile != null:
|
||||
return folder(_that.folderName);case UnindexedFileItem() when unindexedFile != null:
|
||||
return unindexedFile(_that.file);case _:
|
||||
return orElse();
|
||||
|
||||
@@ -145,11 +145,11 @@ return unindexedFile(_that.file);case _:
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function( SnCloudFileIndex fileIndex) file,required TResult Function( SnCloudFolder folder) folder,required TResult Function( SnCloudFile file) unindexedFile,}) {final _that = this;
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function( SnCloudFileIndex fileIndex) file,required TResult Function( String folderName) folder,required TResult Function( SnCloudFile file) unindexedFile,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case FileItem():
|
||||
return file(_that.fileIndex);case FolderItem():
|
||||
return folder(_that.folder);case UnindexedFileItem():
|
||||
return folder(_that.folderName);case UnindexedFileItem():
|
||||
return unindexedFile(_that.file);}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
@@ -164,11 +164,11 @@ return unindexedFile(_that.file);}
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function( SnCloudFileIndex fileIndex)? file,TResult? Function( SnCloudFolder folder)? folder,TResult? Function( SnCloudFile file)? unindexedFile,}) {final _that = this;
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function( SnCloudFileIndex fileIndex)? file,TResult? Function( String folderName)? folder,TResult? Function( SnCloudFile file)? unindexedFile,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case FileItem() when file != null:
|
||||
return file(_that.fileIndex);case FolderItem() when folder != null:
|
||||
return folder(_that.folder);case UnindexedFileItem() when unindexedFile != null:
|
||||
return folder(_that.folderName);case UnindexedFileItem() when unindexedFile != null:
|
||||
return unindexedFile(_that.file);case _:
|
||||
return null;
|
||||
|
||||
@@ -256,10 +256,10 @@ $SnCloudFileIndexCopyWith<$Res> get fileIndex {
|
||||
|
||||
|
||||
class FolderItem implements FileListItem {
|
||||
const FolderItem(this.folder);
|
||||
const FolderItem(this.folderName);
|
||||
|
||||
|
||||
final SnCloudFolder folder;
|
||||
final String folderName;
|
||||
|
||||
/// Create a copy of FileListItem
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -271,16 +271,16 @@ $FolderItemCopyWith<FolderItem> get copyWith => _$FolderItemCopyWithImpl<FolderI
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is FolderItem&&(identical(other.folder, folder) || other.folder == folder));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is FolderItem&&(identical(other.folderName, folderName) || other.folderName == folderName));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,folder);
|
||||
int get hashCode => Object.hash(runtimeType,folderName);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'FileListItem.folder(folder: $folder)';
|
||||
return 'FileListItem.folder(folderName: $folderName)';
|
||||
}
|
||||
|
||||
|
||||
@@ -291,11 +291,11 @@ abstract mixin class $FolderItemCopyWith<$Res> implements $FileListItemCopyWith<
|
||||
factory $FolderItemCopyWith(FolderItem value, $Res Function(FolderItem) _then) = _$FolderItemCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
SnCloudFolder folder
|
||||
String folderName
|
||||
});
|
||||
|
||||
|
||||
$SnCloudFolderCopyWith<$Res> get folder;
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
@@ -308,23 +308,14 @@ class _$FolderItemCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of FileListItem
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? folder = null,}) {
|
||||
@pragma('vm:prefer-inline') $Res call({Object? folderName = null,}) {
|
||||
return _then(FolderItem(
|
||||
null == folder ? _self.folder : folder // ignore: cast_nullable_to_non_nullable
|
||||
as SnCloudFolder,
|
||||
null == folderName ? _self.folderName : folderName // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of FileListItem
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnCloudFolderCopyWith<$Res> get folder {
|
||||
|
||||
return $SnCloudFolderCopyWith<$Res>(_self.folder, (value) {
|
||||
return _then(_self.copyWith(folder: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/models/file.dart';
|
||||
import 'package:island/models/file_list_item.dart';
|
||||
import 'package:island/models/folder.dart';
|
||||
import 'package:island/pods/network.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:riverpod_paging_utils/riverpod_paging_utils.dart';
|
||||
@@ -32,17 +31,15 @@ class CloudFileListNotifier extends _$CloudFileListNotifier
|
||||
queryParameters: {'path': _currentPath},
|
||||
);
|
||||
|
||||
final List<SnCloudFolder> folders =
|
||||
(response.data['folders'] as List)
|
||||
.map((e) => SnCloudFolder.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
final List<String> folders =
|
||||
(response.data['folders'] as List).map((e) => e as String).toList();
|
||||
final List<SnCloudFileIndex> files =
|
||||
(response.data['files'] as List)
|
||||
.map((e) => SnCloudFileIndex.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
final List<FileListItem> items = [
|
||||
...folders.map((folder) => FileListItem.folder(folder)),
|
||||
...folders.map((folderName) => FileListItem.folder(folderName)),
|
||||
...files.map((file) => FileListItem.file(file)),
|
||||
];
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ final billingQuotaProvider =
|
||||
// ignore: unused_element
|
||||
typedef BillingQuotaRef = AutoDisposeFutureProviderRef<Map<String, dynamic>?>;
|
||||
String _$cloudFileListNotifierHash() =>
|
||||
r'5b919f2212ce64c567b9f31912ed18fc4e4bc87d';
|
||||
r'5f2f80357cb31ac6473df5ac2101f9a462004f81';
|
||||
|
||||
/// See also [CloudFileListNotifier].
|
||||
@ProviderFor(CloudFileListNotifier)
|
||||
|
||||
@@ -267,7 +267,7 @@ class FileListView extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
folderItem.folder.name,
|
||||
folderItem.folderName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -276,8 +276,8 @@ class FileListView extends HookConsumerWidget {
|
||||
// Navigate to folder
|
||||
final newPath =
|
||||
currentPath.value == '/'
|
||||
? '/${folderItem.folder.name}'
|
||||
: '${currentPath.value}/${folderItem.folder.name}';
|
||||
? '/${folderItem.folderName}'
|
||||
: '${currentPath.value}/${folderItem.folderName}';
|
||||
currentPath.value = newPath;
|
||||
},
|
||||
),
|
||||
@@ -300,6 +300,7 @@ class FileListView extends HookConsumerWidget {
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
bodyWidget,
|
||||
const SliverGap(12),
|
||||
if (mode.value == FileListMode.normal && currentPath.value == '/')
|
||||
SliverToBoxAdapter(child: _buildUnindexedFilesEntry(ref)),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user