fix: Do not allow empty search server

This commit is contained in:
krille-chan 2023-08-13 11:15:13 +02:00
parent 9238dbcd8d
commit 62122e5c79
No known key found for this signature in database
3 changed files with 22 additions and 5 deletions

View file

@ -1044,6 +1044,7 @@
"anyoneCanKnock": "Anyone can knock",
"noOneCanJoin": "No one can join",
"tryAgain": "Try again",
"invalidServerName": "Invalid server name",
"invited": "Invited",
"@invited": {
"type": "text",

View file

@ -181,6 +181,9 @@ class ChatListController extends State<ChatList>
initialText: searchServer,
keyboardType: TextInputType.url,
autocorrect: false,
validator: (server) => server?.contains('.') == true
? null
: L10n.of(context)!.invalidServerName,
)
],
);
@ -244,6 +247,12 @@ class ChatListController extends State<ChatList>
_coolDown = Timer(const Duration(milliseconds: 500), _search);
}
void startSearch() {
setState(() {
isSearchMode = true;
});
}
void cancelSearch({bool unfocus = true}) {
setState(() {
searchController.clear();

View file

@ -62,9 +62,12 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
onPressed: controller.cancelSearch,
color: Theme.of(context).colorScheme.onBackground,
)
: Icon(
Icons.search_outlined,
color: Theme.of(context).colorScheme.onBackground,
: IconButton(
onPressed: controller.startSearch,
icon: Icon(
Icons.search_outlined,
color: Theme.of(context).colorScheme.onBackground,
),
),
suffixIcon: controller.isSearchMode
? controller.isSearching
@ -80,12 +83,16 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
),
),
)
: TextButton(
: TextButton.icon(
onPressed: controller.setServer,
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(99),
),
textStyle: const TextStyle(fontSize: 12),
),
child: Text(
icon: const Icon(Icons.edit_outlined, size: 16),
label: Text(
controller.searchServer ??
Matrix.of(context)
.client