-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d6e050
commit c5c8a06
Showing
5 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
lib/state_notifier/drive_page/drive_file_notes_page/drive_files_attached_notes_notifier.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:miria/model/pagination_state.dart'; | ||
import 'package:misskey_dart/misskey_dart.dart'; | ||
|
||
class DriveFilesAttachedNotesNotifier extends AutoDisposeFamilyNotifier< | ||
PaginationState<Note>, (Misskey, String)> { | ||
@override | ||
PaginationState<Note> build((Misskey, String) arg) { | ||
Future(loadMore); | ||
return const PaginationState(); | ||
} | ||
|
||
Misskey get _misskey => arg.$1; | ||
|
||
String get _fileId => arg.$2; | ||
|
||
Future<void> loadMore() async { | ||
if (state.isLoading || state.isLastLoaded) { | ||
return; | ||
} | ||
state = state.copyWith(isLoading: true); | ||
final untilId = state.lastOrNull?.id; | ||
try { | ||
final response = await _misskey.drive.files.attachedNotes( | ||
DriveFilesAttachedNotesRequest( | ||
fileId: _fileId, | ||
untilId: untilId, | ||
), | ||
); | ||
// Misskey 2023.10.0 より前はpaginationがなかったため | ||
if (response.any((e) => e.id == state.firstOrNull?.id)) { | ||
state = state.copyWith(isLastLoaded: true); | ||
} else { | ||
state = state.copyWith( | ||
items: [...state, ...response], | ||
isLastLoaded: response.isEmpty, | ||
); | ||
} | ||
} finally { | ||
state = state.copyWith(isLoading: false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:miria/model/account.dart'; | ||
import 'package:miria/model/general_settings.dart'; | ||
import 'package:miria/providers.dart'; | ||
import 'package:miria/view/common/account_scope.dart'; | ||
import 'package:miria/view/common/error_dialog_handler.dart'; | ||
import 'package:miria/view/common/misskey_notes/misskey_note.dart'; | ||
import 'package:miria/view/common/pagination_bottom_item.dart'; | ||
import 'package:misskey_dart/misskey_dart.dart'; | ||
|
||
class DriveFileNotes extends ConsumerWidget { | ||
const DriveFileNotes({ | ||
super.key, | ||
required this.account, | ||
required this.file, | ||
}); | ||
|
||
final Account account; | ||
final DriveFile file; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final misskey = ref.watch(misskeyProvider(account)); | ||
final notes = | ||
ref.watch(driveFilesAttachedNotesProvider((misskey, file.id))); | ||
final loadAutomatically = ref.watch( | ||
generalSettingsRepositoryProvider.select( | ||
(repository) => | ||
repository.settings.automaticPush == AutomaticPush.automatic, | ||
), | ||
); | ||
|
||
return RefreshIndicator( | ||
onRefresh: () async => | ||
ref.invalidate(driveFilesAttachedNotesProvider((misskey, file.id))), | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 10), | ||
child: ListView.builder( | ||
itemCount: notes.length + 1, | ||
itemBuilder: (context, index) { | ||
if (index < notes.length) { | ||
return AccountScope( | ||
account: account, | ||
child: MisskeyNote(note: notes[index]), | ||
); | ||
} | ||
if (loadAutomatically && !notes.isLoading && !notes.isLastLoaded) { | ||
Future(() { | ||
ref | ||
.read( | ||
driveFilesAttachedNotesProvider((misskey, file.id)) | ||
.notifier, | ||
) | ||
.loadMore() | ||
.expectFailure(context); | ||
}); | ||
} | ||
return Center( | ||
child: Padding( | ||
padding: const EdgeInsets.all(10), | ||
child: PaginationBottomItem( | ||
paginationState: notes, | ||
noItemLabel: const Text("添付されているノートがありません"), | ||
child: IconButton( | ||
onPressed: () {}, | ||
icon: const Icon(Icons.keyboard_arrow_down), | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters