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,63 +25,86 @@ class ReactionRow extends ConsumerWidget {
|
|||
runSpacing: 4,
|
||||
children: clientState?.homeserverUrl == null || message.reactions == null
|
||||
? []
|
||||
: message.reactions!.mapTo((reaction, reactors) {
|
||||
final selected = reactors.contains(clientState!.userId);
|
||||
return SizedBox(
|
||||
child: Tooltip(
|
||||
message: reactors.join(", "),
|
||||
child: ChoiceChip(
|
||||
showCheckmark: false,
|
||||
selected: selected,
|
||||
label: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
reaction.startsWith("mxc://")
|
||||
? Image(
|
||||
height: 20,
|
||||
image: CachedNetworkImage(
|
||||
headers: ref.headers,
|
||||
Uri.parse(reaction)
|
||||
.mxcToHttps(clientState.homeserverUrl!)
|
||||
.toString(),
|
||||
ref.watch(CrossCacheController.provider),
|
||||
),
|
||||
)
|
||||
: Text(reaction),
|
||||
Text(reactors.length.toString()),
|
||||
],
|
||||
),
|
||||
onSelected: (value) async {
|
||||
final roomId = ref.watch(
|
||||
SelectedRoomController.provider.select(
|
||||
(value) => value?.metadata?.id,
|
||||
: message.reactions!
|
||||
.mapTo(
|
||||
(reaction, reactors) => HookBuilder(
|
||||
builder: (context) {
|
||||
final enabled = useState(true);
|
||||
final selected = reactors.contains(clientState!.userId);
|
||||
return SizedBox(
|
||||
child: Tooltip(
|
||||
message: reactors.join(", "),
|
||||
child: ChoiceChip(
|
||||
showCheckmark: false,
|
||||
selected: selected,
|
||||
label: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
reaction.startsWith("mxc://")
|
||||
? Image(
|
||||
height: 20,
|
||||
image: CachedNetworkImage(
|
||||
headers: ref.headers,
|
||||
Uri.parse(reaction)
|
||||
.mxcToHttps(
|
||||
clientState.homeserverUrl!,
|
||||
)
|
||||
.toString(),
|
||||
ref.watch(
|
||||
CrossCacheController.provider,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(reaction),
|
||||
Text(reactors.length.toString()),
|
||||
],
|
||||
),
|
||||
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;
|
||||
}
|
||||
|
||||
final controller = ref.watch(
|
||||
RoomChatController.provider(
|
||||
roomId,
|
||||
).notifier,
|
||||
);
|
||||
|
||||
if (selected) {
|
||||
await controller
|
||||
.removeReaction(
|
||||
reaction,
|
||||
message,
|
||||
clientState.userId!,
|
||||
)
|
||||
.onError(showError);
|
||||
} else {
|
||||
await controller
|
||||
.sendReaction(reaction, message)
|
||||
.onError(showError);
|
||||
}
|
||||
} finally {
|
||||
enabled.value = true;
|
||||
}
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (roomId == null || clientState.userId == null) return;
|
||||
|
||||
final controller = ref.watch(
|
||||
RoomChatController.provider(roomId).notifier,
|
||||
);
|
||||
|
||||
if (selected) {
|
||||
await controller
|
||||
.removeReaction(
|
||||
reaction,
|
||||
message,
|
||||
clientState.userId!,
|
||||
)
|
||||
.onError(showError);
|
||||
} else {
|
||||
await controller
|
||||
.sendReaction(reaction, message)
|
||||
.onError(showError);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue