Hide mixed view if no pinned accounts

This commit is contained in:
Elias Bonnici 2024-06-13 11:09:06 +02:00
parent ba4a8296af
commit dd7e14fb44
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF

View File

@ -217,16 +217,6 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
);
}
final pinnedLayout = ref.watch(pinnedLayoutProvider);
final layout = ref.watch(layoutProvider);
final mixedView =
pinnedLayout == FlexLayout.grid && layout == FlexLayout.list;
final listView =
pinnedLayout == FlexLayout.list && layout == FlexLayout.list;
final gridView =
pinnedLayout == FlexLayout.grid && layout == FlexLayout.grid;
return OathActions(
devicePath: widget.devicePath,
actions: (context) => {
@ -390,9 +380,40 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
},
child: Builder(builder: (context) {
final textTheme = Theme.of(context).textTheme;
return Consumer(
builder: (context, ref, child) {
final pinnedLayout = ref.watch(pinnedLayoutProvider);
final layout = ref.watch(layoutProvider);
final mixedView = pinnedLayout == FlexLayout.grid &&
layout == FlexLayout.list;
final listView = pinnedLayout == FlexLayout.list &&
layout == FlexLayout.list;
final gridView = pinnedLayout == FlexLayout.grid &&
layout == FlexLayout.grid;
final credentials = ref.watch(filteredCredentialsProvider(
ref.watch(credentialListProvider(widget.devicePath)) ??
[]));
final favorites = ref.watch(favoritesProvider);
final pinnedCreds = credentials
.where((entry) => favorites.contains(entry.credential.id));
ref.listen(favoritesProvider, (prev, next) {
final newPinnedCreds = credentials
.where((entry) => next.contains(entry.credential.id));
if (newPinnedCreds.isEmpty) {
// reset to list view
ref
.read(pinnedLayoutProvider.notifier)
.setLayout(FlexLayout.list);
ref
.read(layoutProvider.notifier)
.setLayout(FlexLayout.list);
}
});
return Padding(
padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
child: AppTextFormField(
key: searchField,
controller: searchController,
@ -443,7 +464,8 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
// between icons
padding: const EdgeInsets.only(left: 17.0),
child: Container(
color: Theme.of(context).colorScheme.background,
color:
Theme.of(context).colorScheme.background,
width: 1,
height: 40,
),
@ -510,6 +532,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
: null),
),
),
if (pinnedCreds.isNotEmpty)
MouseRegion(
onEnter: (event) {
if (!searchFocus.hasFocus) {
@ -546,15 +569,20 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
),
onChanged: (value) {
ref.read(accountsSearchProvider.notifier).setFilter(value);
ref
.read(accountsSearchProvider.notifier)
.setFilter(value);
setState(() {});
},
textInputAction: TextInputAction.next,
onFieldSubmitted: (value) {
Focus.of(context).focusInDirection(TraversalDirection.down);
Focus.of(context)
.focusInDirection(TraversalDirection.down);
},
).init(),
);
},
);
}),
),
builder: (context, expanded) {