mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 18:25:26 +00:00
Update notifications periodically (#311)
- Call periodically from API class
This commit is contained in:
@ -129,9 +129,12 @@ class InvenTreeDrawer extends StatelessWidget {
|
||||
}
|
||||
|
||||
if (InvenTreeAPI().supportsNotifications) {
|
||||
int notification_count = InvenTreeAPI().notification_counter;
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
leading: FaIcon(FontAwesomeIcons.bell),
|
||||
trailing: notification_count > 0 ? Text(notification_count.toString()) : null,
|
||||
title: Text(L10().notifications),
|
||||
onTap: _notifications,
|
||||
)
|
||||
|
@ -42,16 +42,6 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
// Initially load the profile and attempt server connection
|
||||
_loadProfile();
|
||||
|
||||
_refreshNotifications();
|
||||
|
||||
// Refresh notifications every ~30 seconds
|
||||
Timer.periodic(
|
||||
Duration(
|
||||
milliseconds: 30000,
|
||||
), (timer) {
|
||||
_refreshNotifications();
|
||||
});
|
||||
|
||||
InvenTreeAPI().registerCallback(() {
|
||||
|
||||
if (mounted) {
|
||||
@ -180,28 +170,6 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
/*
|
||||
* Refresh the number of active notifications for this user
|
||||
*/
|
||||
Future<void> _refreshNotifications() async {
|
||||
|
||||
if (!InvenTreeAPI().isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if the widget is no longer active
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
// final notifications = await InvenTreeNotification().list();
|
||||
|
||||
setState(() {
|
||||
// _notificationCounter = notifications.length;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Widget _listTile(BuildContext context, String label, IconData icon, {Function()? callback, String role = "", String permission = "", Widget? trailing}) {
|
||||
|
||||
bool connected = InvenTreeAPI().isConnected();
|
||||
|
Reference in New Issue
Block a user