-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Feature - Add HashTag Page
- Loading branch information
ChenDoXiu
committed
Dec 22, 2024
1 parent
623c28a
commit 552a976
Showing
16 changed files
with
389 additions
and
89 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Changelog | ||
|
||
## 0.8.0 | ||
|
||
### Feature | ||
|
||
- Add HashTag Page | ||
|
||
## 0.7.4 | ||
|
||
### Chore | ||
|
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
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,32 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
|
||
import '../widgets/mk_refresh_load.dart'; | ||
|
||
MkRefreshLoadListController useMkRefreshLoadListController() { | ||
return use(_MkRefreshLoadListControllerHook()); | ||
} | ||
|
||
class _MkRefreshLoadListControllerHook | ||
extends Hook<MkRefreshLoadListController> { | ||
@override | ||
HookState<MkRefreshLoadListController, Hook<MkRefreshLoadListController>> | ||
createState() { | ||
return _MkRefreshLoadListControllerHookState(); | ||
} | ||
} | ||
|
||
class _MkRefreshLoadListControllerHookState extends HookState< | ||
MkRefreshLoadListController, _MkRefreshLoadListControllerHook> { | ||
late final controller = MkRefreshLoadListController(); | ||
|
||
@override | ||
MkRefreshLoadListController build(BuildContext context) { | ||
return controller; | ||
} | ||
|
||
@override | ||
void dispose() { | ||
controller.dispose(); | ||
} | ||
} |
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,86 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:moekey/apis/models/note.dart'; | ||
import 'package:moekey/hook/use_mk_refresh_load_list_controller.dart'; | ||
import 'package:moekey/widgets/mk_header.dart'; | ||
import 'package:moekey/widgets/mk_scaffold.dart'; | ||
import 'package:moekey/widgets/notes/note_pagination_list.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
import '../../status/misskey_api.dart'; | ||
|
||
part 'hashtag_page.g.dart'; | ||
|
||
class HashtagPage extends HookConsumerWidget { | ||
const HashtagPage({super.key, required this.name}); | ||
|
||
final String name; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
var model = hashTagPageProvider(name); | ||
var state = ref.watch(model); | ||
var data = state.valueOrNull; | ||
var controller = useMkRefreshLoadListController(); | ||
return MkScaffold( | ||
header: MkAppbar( | ||
showBack: true, | ||
content: GestureDetector( | ||
onTap: () { | ||
controller.refresh(); | ||
}, | ||
child: Text( | ||
"#$name", | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
), | ||
), | ||
body: Center( | ||
child: MkPaginationNoteList( | ||
onLoad: () => ref.read(model.notifier).load(), | ||
onRefresh: () => ref.refresh(model.future), | ||
hasMore: data?.hasMore ?? true, | ||
items: data?.list, | ||
controller: controller, | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
@riverpod | ||
class HashTagPage extends _$HashTagPage { | ||
@override | ||
FutureOr<NoteListModel> build(String tag) async { | ||
var model = NoteListModel(); | ||
model.list = await notes(); | ||
return model; | ||
} | ||
|
||
Future<List<NoteModel>> notes({String? untilId}) async { | ||
var apis = ref.read(misskeyApisProvider); | ||
var list = await apis.notes.searchByTag(tag: tag, untilId: untilId); | ||
return list; | ||
} | ||
|
||
load() async { | ||
if (state.isLoading) return; | ||
state = const AsyncValue.loading(); | ||
var model = state.valueOrNull ?? NoteListModel(); | ||
try { | ||
String? untilId; | ||
if (state.valueOrNull?.list.isNotEmpty ?? false) { | ||
untilId = state.valueOrNull?.list.last.id; | ||
} | ||
List<NoteModel> notesList = await notes(untilId: untilId); | ||
|
||
model.list += notesList; | ||
if (notesList.isEmpty) { | ||
model.hasMore = false; | ||
} | ||
} finally { | ||
state = AsyncData(model); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.