Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat search requests #330

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions lib/providers/collection_providers.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'dart:async';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'settings_providers.dart';
import 'ui_providers.dart';
import 'package:http/http.dart' as http;

import '../consts.dart';
import '../models/models.dart';
import '../services/services.dart' show hiveHandler, HiveHandler, request;
import '../utils/utils.dart' show getNewUuid, collectionToHAR;
import '../consts.dart';
import 'package:http/http.dart' as http;
import 'settings_providers.dart';
import 'ui_providers.dart';

final selectedIdStateProvider = StateProvider<String?>((ref) => null);

Expand Down Expand Up @@ -53,6 +56,26 @@ class CollectionStateNotifier
return state?[id];
}

List<String> tempSequence = [];

void filter(String query) {
if(tempSequence.isEmpty){
tempSequence = ref.read(requestSequenceProvider);
}

if (query == '') {
ref.read(requestSequenceProvider.notifier).state = [...tempSequence];
tempSequence.clear();
} else {
final map = {...state!};
map.removeWhere((key, value) =>
!(value.name.toLowerCase().contains(query.toLowerCase()) ||
value.url.toLowerCase().contains(query.toLowerCase())));
ref
.read(requestSequenceProvider.notifier).state = [...map.keys];
}
}

void add() {
final id = getNewUuid();
final newRequestModel = RequestModel(
Expand Down
1 change: 1 addition & 0 deletions lib/providers/ui_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ final selectedIdEditStateProvider = StateProvider<String?>((ref) => null);
final codePaneVisibleStateProvider = StateProvider<bool>((ref) => false);
final saveDataStateProvider = StateProvider<bool>((ref) => false);
final clearDataStateProvider = StateProvider<bool>((ref) => false);

// final nameTextFieldControllerProvider =
// StateProvider.autoDispose<TextEditingController>((ref) {
// TextEditingController controller = TextEditingController(text: "");
Expand Down
75 changes: 71 additions & 4 deletions lib/screens/home_page/collection_pane.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/consts.dart';
import 'package:apidash/models/models.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart';
import 'package:apidash/models/models.dart';
import 'package:apidash/consts.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class CollectionPane extends ConsumerWidget {
const CollectionPane({
Expand All @@ -15,16 +15,74 @@ class CollectionPane extends ConsumerWidget {
var sm = ScaffoldMessenger.of(context);
final collection = ref.watch(collectionStateNotifierProvider);
final savingData = ref.watch(saveDataStateProvider);

if (collection == null) {
return const Center(
child: CircularProgressIndicator(),
);
}

return Padding(
padding: kIsMacOS ? kP24CollectionPane : kP8CollectionPane,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: 35,
margin: const EdgeInsets.symmetric(horizontal: 8),
padding: const EdgeInsets.symmetric(horizontal: 5),
decoration: BoxDecoration(
borderRadius: kBorderRadius8,
border: Border.all(
color: Theme.of(context).colorScheme.surfaceVariant,
width: 1,
),
),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
const Icon(
Icons.search_rounded,
size: 18,
),
kHSpacer5,
Expanded(
child: SizedBox(
height: 35,
child: TextField(
onChanged: (value) => ref
.read(collectionStateNotifierProvider.notifier)
.filter(value.trim()),
decoration: const InputDecoration(
constraints: BoxConstraints(
maxHeight: 35,
minHeight: 35,
),
border: InputBorder.none,
contentPadding: EdgeInsets.only(
bottom: 16,
right: 5,
left: 5,
),
counterText: '',
),
// cursorHeight: 12,
maxLines: 1,
maxLength: 150,
style: const TextStyle(
fontSize: 12,
// height: 0.1,
),
),
),
),
],
),
),
kVSpacer8,
Padding(
padding: kPr8CollectionPane,
child: Wrap(
Expand Down Expand Up @@ -104,6 +162,15 @@ class _RequestListState extends ConsumerState<RequestList> {
final alwaysShowCollectionPaneScrollbar = ref.watch(settingsProvider
.select((value) => value.alwaysShowCollectionPaneScrollbar));

if (requestItems.isNotEmpty && requestSequence.isEmpty) {
return Center(
child: Text(
'Request not found!',
style: Theme.of(context).textTheme.titleMedium,
),
);
}

return Scrollbar(
controller: controller,
thumbVisibility: alwaysShowCollectionPaneScrollbar ? true : null,
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/dropdowns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class DropdownButtonCodegenLanguage extends StatelessWidget {
final surfaceColor = Theme.of(context).colorScheme.surface;
return DropdownButton<CodegenLanguage>(
focusColor: surfaceColor,
isExpanded: true,
value: codegenLanguage,
icon: const Icon(
Icons.unfold_more_rounded,
Expand Down