-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add saved views to landing page
- Loading branch information
1 parent
53a01ae
commit b79375c
Showing
10 changed files
with
198 additions
and
36 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
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
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
28 changes: 28 additions & 0 deletions
28
lib/features/saved_view_details/cubit/saved_view_preview_cubit.dart
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,28 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:paperless_api/paperless_api.dart'; | ||
|
||
part 'saved_view_preview_state.dart'; | ||
part 'saved_view_preview_cubit.freezed.dart'; | ||
|
||
class SavedViewPreviewCubit extends Cubit<SavedViewPreviewState> { | ||
final PaperlessDocumentsApi _api; | ||
final SavedView view; | ||
SavedViewPreviewCubit(this._api, this.view) | ||
: super(const SavedViewPreviewState.initial()); | ||
|
||
Future<void> initialize() async { | ||
emit(const SavedViewPreviewState.loading()); | ||
try { | ||
final documents = await _api.findAll( | ||
view.toDocumentFilter().copyWith( | ||
page: 1, | ||
pageSize: 5, | ||
), | ||
); | ||
emit(SavedViewPreviewState.loaded(documents: documents.results)); | ||
} catch (e) { | ||
emit(const SavedViewPreviewState.error()); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lib/features/saved_view_details/cubit/saved_view_preview_state.dart
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,11 @@ | ||
part of 'saved_view_preview_cubit.dart'; | ||
|
||
@freezed | ||
class SavedViewPreviewState with _$SavedViewPreviewState { | ||
const factory SavedViewPreviewState.initial() = _Initial; | ||
const factory SavedViewPreviewState.loading() = _Loading; | ||
const factory SavedViewPreviewState.loaded({ | ||
required List<DocumentModel> documents, | ||
}) = _Loaded; | ||
const factory SavedViewPreviewState.error() = _Error; | ||
} |
84 changes: 84 additions & 0 deletions
84
lib/features/saved_view_details/view/saved_view_details_preview.dart
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,84 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:paperless_api/paperless_api.dart'; | ||
import 'package:paperless_mobile/features/documents/cubit/documents_cubit.dart'; | ||
import 'package:paperless_mobile/features/documents/view/widgets/adaptive_documents_view.dart'; | ||
import 'package:paperless_mobile/features/documents/view/widgets/items/document_list_item.dart'; | ||
import 'package:paperless_mobile/features/landing/view/widgets/expansion_card.dart'; | ||
import 'package:paperless_mobile/features/saved_view_details/cubit/saved_view_details_cubit.dart'; | ||
import 'package:paperless_mobile/features/saved_view_details/cubit/saved_view_preview_cubit.dart'; | ||
import 'package:paperless_mobile/routes/typed/branches/documents_route.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class SavedViewDetailsPreview extends StatelessWidget { | ||
final SavedView savedView; | ||
const SavedViewDetailsPreview({ | ||
super.key, | ||
required this.savedView, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Provider( | ||
create: (context) => | ||
SavedViewPreviewCubit(context.read(), savedView)..initialize(), | ||
builder: (context, child) { | ||
return ExpansionCard( | ||
title: Text(savedView.name), | ||
content: BlocBuilder<SavedViewPreviewCubit, SavedViewPreviewState>( | ||
builder: (context, state) { | ||
return Column( | ||
children: [ | ||
state.maybeWhen( | ||
loaded: (documents) { | ||
return Column( | ||
children: [ | ||
for (final document in documents) | ||
DocumentListItem( | ||
document: document, | ||
isLabelClickable: false, | ||
isSelected: false, | ||
isSelectionActive: false, | ||
onTap: (document) { | ||
DocumentDetailsRoute($extra: document) | ||
.push(context); | ||
}, | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
children: [ | ||
TextButton( | ||
child: Text("Show more"), | ||
onPressed: documents.length >= 5 ? () {} : null, | ||
), | ||
TextButton.icon( | ||
icon: Icon(Icons.open_in_new), | ||
label: Text("Show in documents"), | ||
onPressed: () { | ||
context.read<DocumentsCubit>().updateFilter( | ||
filter: savedView.toDocumentFilter(), | ||
); | ||
DocumentsRoute().go(context); | ||
}, | ||
), | ||
], | ||
), | ||
], | ||
); | ||
}, | ||
error: () => | ||
const Text("Error loading preview"), //TODO: INTL | ||
orElse: () => const Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Center(child: CircularProgressIndicator()), | ||
), | ||
), | ||
], | ||
); | ||
}, | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |