Add refresh emotes button to emote menu

This commit is contained in:
Tommy Chow 2022-07-03 06:31:07 -04:00
parent fa9c8688de
commit 18d311f76f
3 changed files with 65 additions and 40 deletions

View file

@ -4,6 +4,7 @@ import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:frosty/screens/channel/chat/emote_menu/emote_menu_panel.dart';
import 'package:frosty/screens/channel/chat/emote_menu/recent_emotes_panel.dart';
import 'package:frosty/screens/channel/stores/chat_store.dart';
import 'package:frosty/widgets/alert_message.dart';
import 'package:frosty/widgets/button.dart';
class EmoteMenu extends StatefulWidget {
@ -41,33 +42,55 @@ class _EmoteMenuState extends State<EmoteMenu> {
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: sections
.mapIndexed(
(index, section) => Padding(
padding: const EdgeInsets.only(right: 5.0),
child: Observer(
builder: (context) => Button(
onPressed: () {
_pageContoller.animateToPage(
index,
duration: const Duration(milliseconds: 200),
curve: Curves.ease,
);
widget.chatStore.assetsStore.emoteMenuIndex = index;
},
color: index == widget.chatStore.assetsStore.emoteMenuIndex ? Theme.of(context).colorScheme.secondary : Colors.grey,
child: Text(
section,
style: const TextStyle(
letterSpacing: 0.8,
fontWeight: FontWeight.w600,
),
children: [
...sections.mapIndexed(
(index, section) => Padding(
padding: const EdgeInsets.only(right: 5.0),
child: Observer(
builder: (context) => Button(
onPressed: () {
_pageContoller.animateToPage(
index,
duration: const Duration(milliseconds: 200),
curve: Curves.ease,
);
widget.chatStore.assetsStore.emoteMenuIndex = index;
},
color: index == widget.chatStore.assetsStore.emoteMenuIndex ? Theme.of(context).colorScheme.secondary : Colors.grey,
child: Text(
section,
style: const TextStyle(
letterSpacing: 0.8,
fontWeight: FontWeight.w600,
),
),
),
),
)
.toList(),
),
),
Button(
onPressed: () async {
await widget.chatStore.getAssets();
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: AlertMessage(message: 'Emotes refreshed'),
behavior: SnackBarBehavior.floating,
),
);
},
color: Theme.of(context).colorScheme.secondary,
child: const Text(
'REFRESH EMOTES',
style: TextStyle(
letterSpacing: 0.8,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
Expanded(

View file

@ -159,10 +159,8 @@ abstract class ChatAssetsStoreBase with Store {
required Function onError,
}) =>
Future.wait([
twitchApi
.getBadgesGlobal()
.then((badges) => twitchBadgesToObject.addAll(badges))
.then((_) => twitchApi.getBadgesChannel(id: channelId).then((badges) => twitchBadgesToObject.addAll(badges)).catchError(onError)),
twitchApi.getBadgesGlobal().then((badges) => twitchBadgesToObject.addAll(badges)).catchError(onError),
twitchApi.getBadgesChannel(id: channelId).then((badges) => twitchBadgesToObject.addAll(badges)).catchError(onError),
ffzApi.getBadges().then((badges) => _userToFFZBadges = badges).catchError(onError),
sevenTVApi.getBadges().then((badges) => _userTo7TVBadges = badges).catchError(onError),
bttvApi.getBadges().then((badges) => _userToBTTVBadges = badges).catchError(onError),

View file

@ -231,19 +231,8 @@ abstract class ChatStoreBase with Store {
} else if (message.contains('Welcome, GLHF!')) {
_messages.add(IRCMessage.createNotice(message: "Connected to $displayName${regexEnglish.hasMatch(displayName) ? '' : ' ($channelName)'}'s chat!"));
// Fetch the assets used in chat including badges and emotes.
assetsStore.assetsFuture(
channelId: channelId,
headers: auth.headersTwitch,
onEmoteError: (error) {
debugPrint(error.toString());
return <Emote>[];
},
onBadgeError: (error) {
debugPrint(error.toString());
return <Badge>[];
},
);
getAssets();
// Reset exponential backoff if successfully connected.
_retries = 0;
_backoffTime = 0;
@ -251,6 +240,21 @@ abstract class ChatStoreBase with Store {
}
}
// Fetch the assets used in chat including badges and emotes.
@action
Future<void> getAssets() async => assetsStore.assetsFuture(
channelId: channelId,
headers: auth.headersTwitch,
onEmoteError: (error) {
debugPrint(error.toString());
return <Emote>[];
},
onBadgeError: (error) {
debugPrint(error.toString());
return <Badge>[];
},
);
/// Re-enables [_autoScroll] and jumps to the latest message.
@action
void resumeScroll() {