forked from Nexus/nexus
disable react button while last action is pending
This commit is contained in:
parent
4954fb8c09
commit
3e8eba0872
3 changed files with 79 additions and 53 deletions
|
|
@ -377,6 +377,7 @@ class RoomChatController extends AsyncNotifier<InMemoryChatController> {
|
|||
"key": reaction,
|
||||
},
|
||||
},
|
||||
synchronous: true,
|
||||
disableEncryption: true,
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ abstract class SendEventRequest with _$SendEventRequest {
|
|||
required String roomId,
|
||||
required String type,
|
||||
required Map<String, dynamic> content,
|
||||
@Default(false) bool synchronous,
|
||||
@Default(false) bool disableEncryption,
|
||||
}) = _SendEventRequest;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import "package:cross_cache/cross_cache.dart";
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_chat_core/flutter_chat_core.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/client_state_controller.dart";
|
||||
import "package:nexus/controllers/cross_cache_controller.dart";
|
||||
|
|
@ -24,7 +25,11 @@ class ReactionRow extends ConsumerWidget {
|
|||
runSpacing: 4,
|
||||
children: clientState?.homeserverUrl == null || message.reactions == null
|
||||
? []
|
||||
: message.reactions!.mapTo((reaction, reactors) {
|
||||
: message.reactions!
|
||||
.mapTo(
|
||||
(reaction, reactors) => HookBuilder(
|
||||
builder: (context) {
|
||||
final enabled = useState(true);
|
||||
final selected = reactors.contains(clientState!.userId);
|
||||
return SizedBox(
|
||||
child: Tooltip(
|
||||
|
|
@ -42,25 +47,37 @@ class ReactionRow extends ConsumerWidget {
|
|||
image: CachedNetworkImage(
|
||||
headers: ref.headers,
|
||||
Uri.parse(reaction)
|
||||
.mxcToHttps(clientState.homeserverUrl!)
|
||||
.mxcToHttps(
|
||||
clientState.homeserverUrl!,
|
||||
)
|
||||
.toString(),
|
||||
ref.watch(CrossCacheController.provider),
|
||||
ref.watch(
|
||||
CrossCacheController.provider,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(reaction),
|
||||
Text(reactors.length.toString()),
|
||||
],
|
||||
),
|
||||
onSelected: (value) async {
|
||||
onSelected: enabled.value
|
||||
? (value) async {
|
||||
enabled.value = false;
|
||||
try {
|
||||
final roomId = ref.watch(
|
||||
SelectedRoomController.provider.select(
|
||||
(value) => value?.metadata?.id,
|
||||
),
|
||||
);
|
||||
if (roomId == null || clientState.userId == null) return;
|
||||
if (roomId == null ||
|
||||
clientState.userId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final controller = ref.watch(
|
||||
RoomChatController.provider(roomId).notifier,
|
||||
RoomChatController.provider(
|
||||
roomId,
|
||||
).notifier,
|
||||
);
|
||||
|
||||
if (selected) {
|
||||
|
|
@ -76,11 +93,18 @@ class ReactionRow extends ConsumerWidget {
|
|||
.sendReaction(reaction, message)
|
||||
.onError(showError);
|
||||
}
|
||||
} finally {
|
||||
enabled.value = true;
|
||||
}
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue