feat(app): 老师点评功能 — CommentCreate事件 + CommentBottomSheet + 日记墙点评按钮
This commit is contained in:
@@ -66,6 +66,12 @@ final class ClassJoin extends ClassEvent {
|
||||
const ClassJoin({required this.classCode, this.nickname});
|
||||
}
|
||||
|
||||
final class CommentCreate extends ClassEvent {
|
||||
final String journalId;
|
||||
final String content;
|
||||
const CommentCreate({required this.journalId, required this.content});
|
||||
}
|
||||
|
||||
// ===== State =====
|
||||
|
||||
class ClassMember {
|
||||
@@ -125,6 +131,7 @@ final class ClassDetailLoaded extends ClassState {
|
||||
final bool isLoadingWall;
|
||||
final bool isLoadingMembers;
|
||||
final String? selectedJournalId;
|
||||
final String? error;
|
||||
|
||||
const ClassDetailLoaded({
|
||||
required this.classInfo,
|
||||
@@ -135,6 +142,7 @@ final class ClassDetailLoaded extends ClassState {
|
||||
this.isLoadingWall = false,
|
||||
this.isLoadingMembers = false,
|
||||
this.selectedJournalId,
|
||||
this.error,
|
||||
});
|
||||
|
||||
ClassDetailLoaded copyWith({
|
||||
@@ -147,6 +155,8 @@ final class ClassDetailLoaded extends ClassState {
|
||||
bool? isLoadingMembers,
|
||||
String? selectedJournalId,
|
||||
bool clearSelectedJournal = false,
|
||||
String? error,
|
||||
bool clearError = false,
|
||||
}) =>
|
||||
ClassDetailLoaded(
|
||||
classInfo: classInfo ?? this.classInfo,
|
||||
@@ -157,6 +167,7 @@ final class ClassDetailLoaded extends ClassState {
|
||||
isLoadingWall: isLoadingWall ?? this.isLoadingWall,
|
||||
isLoadingMembers: isLoadingMembers ?? this.isLoadingMembers,
|
||||
selectedJournalId: clearSelectedJournal ? null : (selectedJournalId ?? this.selectedJournalId),
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -186,6 +197,7 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
|
||||
on<ClassCreate>(_onCreateClass);
|
||||
on<TopicAssign>(_onTopicAssign);
|
||||
on<ClassJoin>(_onJoinClass);
|
||||
on<CommentCreate>(_onCommentCreate);
|
||||
}
|
||||
|
||||
Future<void> _onLoadMyClasses(
|
||||
@@ -369,4 +381,23 @@ class ClassBloc extends Bloc<ClassEvent, ClassState> {
|
||||
emit(ClassError('加入班级失败: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onCommentCreate(
|
||||
CommentCreate event,
|
||||
Emitter<ClassState> emit,
|
||||
) async {
|
||||
final currentState = state;
|
||||
if (currentState is! ClassDetailLoaded) return;
|
||||
|
||||
try {
|
||||
await _classRepo.createComment(
|
||||
journalId: event.journalId,
|
||||
content: event.content,
|
||||
);
|
||||
// 创建成功后重新加载评语列表
|
||||
add(ClassLoadComments(event.journalId));
|
||||
} catch (e) {
|
||||
emit(currentState.copyWith(error: '评语发布失败'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user