chore: disable save edits button if no changes in course edit page (#4033)

This commit is contained in:
ggurdin 2025-09-18 12:27:13 -04:00 committed by GitHub
parent 5450885afe
commit 218e9ab3fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 4 deletions

View file

@ -33,6 +33,14 @@ class EditCourseController extends State<EditCourse> {
_titleController.text = _room!.name;
_descController.text = _room!.topic;
}
_titleController.addListener(() {
setState(() {});
});
_descController.addListener(() {
setState(() {});
});
}
@override
@ -44,8 +52,18 @@ class EditCourseController extends State<EditCourse> {
Room? get _room => Matrix.of(context).client.getRoomById(widget.roomId);
bool get hasChanges {
if (_room == null) return false;
final title = _titleController.text.trim();
final desc = _descController.text.trim();
if (title.isNotEmpty && title != _room!.name) return true;
if (desc.isNotEmpty && desc != _room!.topic) return true;
if (_avatar != null) return true;
return false;
}
Future<void> _saveChanges() async {
if (_room == null) return;
if (_room == null || !hasChanges) return;
final title = _titleController.text.trim();
final desc = _descController.text.trim();
@ -58,6 +76,16 @@ class EditCourseController extends State<EditCourse> {
if (_avatar != null) {
await _room!.setAvatar(_avatar!);
}
_room!.client.onRoomState.stream.first.then((_) {
if (mounted) {
setState(() {
_titleController.text = _room!.name;
_descController.text = _room!.topic;
_avatar = null;
});
}
});
}
Future<void> _save() async {
@ -240,7 +268,7 @@ class EditCourseController extends State<EditCourse> {
Container(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: _save,
onPressed: hasChanges ? _save : null,
child: Row(
spacing: 8.0,
mainAxisAlignment: MainAxisAlignment.center,

View file

@ -314,9 +314,9 @@ class SpaceDetailsContent extends StatelessWidget {
return SingleChildScrollView(
child: Column(
children: [
if (courseController.course != null) ...[
if (room.topic.isNotEmpty) ...[
Text(
courseController.course!.description,
room.topic,
style: TextStyle(
fontSize: isColumnMode ? 16.0 : 12.0,
),