Skip to content

Commit

Permalink
feat: チャンネル内検索の実装
Browse files Browse the repository at this point in the history
  • Loading branch information
4ster1sk committed Dec 1, 2024
1 parent f9fa610 commit 756ae33
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/view/channels_page/channel_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "package:miria/providers.dart";
import "package:miria/router/app_router.dart";
import "package:miria/view/channels_page/channel_detail_info.dart";
import "package:miria/view/channels_page/channel_note_highlight.dart";
import "package:miria/view/channels_page/channel_note_search.dart";
import "package:miria/view/channels_page/channel_timeline.dart";
import "package:miria/view/common/account_scope.dart";

Expand All @@ -27,7 +28,7 @@ class ChannelDetailPage extends ConsumerWidget implements AutoRouteWrapper {
@override
Widget build(BuildContext context, WidgetRef ref) {
return DefaultTabController(
length: 3,
length: 4,
child: Scaffold(
appBar: AppBar(
title: Text(S.of(context).channel),
Expand All @@ -36,7 +37,10 @@ class ChannelDetailPage extends ConsumerWidget implements AutoRouteWrapper {
Tab(child: Text(S.of(context).channelInformation)),
Tab(child: Text(S.of(context).timeline)),
Tab(child: Text(S.of(context).highlight)),
Tab(child: Text(S.of(context).search)),
],
isScrollable: true,
tabAlignment: TabAlignment.center,
),
),
body: TabBarView(
Expand All @@ -55,6 +59,10 @@ class ChannelDetailPage extends ConsumerWidget implements AutoRouteWrapper {
padding: const EdgeInsets.only(left: 10, right: 10),
child: ChannelNoteHighlight(channelId: channelId),
),
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: ChannelNoteSearch(channelId: channelId),
),
],
),
floatingActionButton: ref.read(accountContextProvider).isSame
Expand Down
32 changes: 32 additions & 0 deletions lib/view/channels_page/channel_note_search.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "package:flutter/material.dart";
import "package:flutter_hooks/flutter_hooks.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:miria/view/search_page/note_search.dart";

class ChannelNoteSearch extends HookConsumerWidget {
final String channelId;
const ChannelNoteSearch({required this.channelId, super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final searchQuery = useState("");

return Column(
children: [
const Padding(padding: EdgeInsets.only(top: 5)),
TextField(
decoration: const InputDecoration(prefixIcon: Icon(Icons.search)),
textInputAction: TextInputAction.done,
onSubmitted: (value) => searchQuery.value = value,
),
Expanded(
child: NoteSearchList(
query: searchQuery.value,
channelId: channelId,
localOnly: false,
),
),
],
);
}
}
48 changes: 48 additions & 0 deletions test/view/channel_detail_page/channel_detail_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:flutter/material.dart";
import "package:flutter_test/flutter_test.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:miria/providers.dart";
Expand Down Expand Up @@ -313,5 +314,52 @@ void main() {
),
);
});

testWidgets("チャンネル内の検索でノートが表示されること", (tester) async {
final notes = MockMisskeyNotes();
final channel = MockMisskeyChannels();
final misskey = MockMisskey();
when(misskey.channels).thenReturn(channel);
when(channel.show(any)).thenAnswer(
(_) async =>
TestData.channel1.copyWith(bannerUrl: null, isFollowing: false),
);
when(misskey.notes).thenReturn(notes);
when(notes.search(any)).thenAnswer((_) async => [TestData.note1]);

await tester.pumpWidget(
ProviderScope(
overrides: [misskeyProvider.overrideWith((_) => misskey)],
child: DefaultRootWidget(
initialRoute: ChannelDetailRoute(
accountContext: TestData.accountContext,
channelId: TestData.channel1.id,
),
),
),
);
await tester.pumpAndSettle();

await tester.tap(find.text("検索"));
await tester.pumpAndSettle();

await tester.enterText(find.byType(TextField), "Misskey");
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();

verify(
notes.search(
argThat(
equals(
NotesSearchRequest(
query: "Misskey",
channelId: TestData.channel1.id,
),
),
),
),
).called(1);
expect(find.text(TestData.note1.text!), findsOneWidget);
});
});
}

0 comments on commit 756ae33

Please sign in to comment.