Skip to content

Commit f366ccb

Browse files
committed
feat :: [#111] 메인화면 토스트 처리 완료
1 parent b117d6e commit f366ccb

2 files changed

Lines changed: 143 additions & 108 deletions

File tree

Projects/Feature/HomeFeature/Sources/HomeReducer.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ComposableArchitecture
2+
import PiCK_iOS_DesignSystem
23
import HomeDomainInterface
34
import AcceptDomainInterface
45
import OutListDomainInterface
@@ -51,6 +52,9 @@ public struct HomeReducer: Reducer {
5152
public var floor: String = "0층"
5253
public var isHomeroomTeacher: Bool = false
5354
public var isSelfStudyTeacher: Bool = false
55+
public var showAlert: Bool = false
56+
public var alertSuccessType: SuccessType = .success
57+
public var alertMessage: String = ""
5458

5559
// 내부용 리스트
5660
var earlyReturnList: [EarlyReturnEntity] = []
@@ -90,6 +94,8 @@ public struct HomeReducer: Reducer {
9094
case classroomMoveResponse(TaskResult<[ClassroomMoveListEntity]>)
9195
case outListResponse(TaskResult<[OutListEntity]>)
9296
case earlyReturnListResponse(TaskResult<[EarlyReturnEntity]>)
97+
98+
case dismissAlert
9399
}
94100

95101
public var body: some Reducer<State, Action> {
@@ -236,6 +242,10 @@ public struct HomeReducer: Reducer {
236242
}
237243

238244
case .updateStatusResponse(.success):
245+
state.alertSuccessType = .success
246+
state.alertMessage = "외출 처리를 성공했어요"
247+
state.showAlert = true
248+
239249
let components = state.classroom.split(separator: "-").compactMap { Int($0) }
240250
if components.count == 2 {
241251
return .merge(
@@ -245,9 +255,16 @@ public struct HomeReducer: Reducer {
245255
}
246256
return .none
247257
case .updateStatusResponse(.failure):
258+
state.alertSuccessType = .fail
259+
state.alertMessage = "외출 처리를 실패했어요"
260+
state.showAlert = true
248261
return .none
249262

250263
case .updateEarlyReturnStatusResponse(.success):
264+
state.alertSuccessType = .success
265+
state.alertMessage = "조기귀가 처리를 성공했어요"
266+
state.showAlert = true
267+
251268
let components = state.classroom.split(separator: "-").compactMap { Int($0) }
252269
if components.count == 2 {
253270
return .merge(
@@ -257,6 +274,9 @@ public struct HomeReducer: Reducer {
257274
}
258275
return .none
259276
case .updateEarlyReturnStatusResponse(.failure):
277+
state.alertSuccessType = .fail
278+
state.alertMessage = "조기귀가 처리를 실패했어요"
279+
state.showAlert = true
260280
return .none
261281

262282
case let .classroomMoveResponse(.success(students)):
@@ -284,6 +304,10 @@ public struct HomeReducer: Reducer {
284304
return .none
285305
case .earlyReturnListResponse(.failure):
286306
return .none
307+
308+
case .dismissAlert:
309+
state.showAlert = false
310+
return .none
287311
}
288312
}
289313
}

Projects/Feature/HomeFeature/Sources/Scene/HomeView.swift

Lines changed: 119 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -14,130 +14,141 @@ public struct HomeView: View {
1414

1515
public var body: some View {
1616
WithViewStore(self.store, observe: { $0 }) { viewStore in
17-
ScrollView {
18-
VStack(spacing: 24) {
19-
SelfStudyView(
20-
adminMessage: viewStore.adminSelfStudyTeacher
21-
)
22-
.frame(maxWidth: .infinity)
23-
.frame(height: 72)
17+
ZStack {
18+
ScrollView {
19+
VStack(spacing: 24) {
20+
SelfStudyView(
21+
adminMessage: viewStore.adminSelfStudyTeacher
22+
)
23+
.frame(maxWidth: .infinity)
24+
.frame(height: 72)
2425

25-
if viewStore.isHomeroomTeacher {
26-
AccordionView(
27-
badge: viewStore.classroom,
28-
title: "외출 수락",
29-
content: {
30-
VStack(spacing: 8) {
31-
if viewStore.outingAcceptList.isEmpty {
32-
emptyStateView(message: "외출 신청이 없습니다")
33-
} else {
34-
ForEach(viewStore.outingAcceptList) { item in
35-
AcceptCell(
36-
studentNumber: self.studentNumber(
37-
grade: item.grade,
38-
classNum: item.classNum,
39-
num: item.num
40-
),
41-
name: item.userName,
42-
type: item.type,
43-
onAccept: {
44-
switch item.type {
45-
case .outgoing:
46-
viewStore.send(.acceptApplication(id: item.id))
47-
case .earlyReturn:
48-
viewStore.send(.acceptEarlyReturn(id: item.id))
26+
if viewStore.isHomeroomTeacher {
27+
AccordionView(
28+
badge: viewStore.classroom,
29+
title: "외출 수락",
30+
content: {
31+
VStack(spacing: 8) {
32+
if viewStore.outingAcceptList.isEmpty {
33+
emptyStateView(message: "외출 신청이 없습니다")
34+
} else {
35+
ForEach(viewStore.outingAcceptList) { item in
36+
AcceptCell(
37+
studentNumber: self.studentNumber(
38+
grade: item.grade,
39+
classNum: item.classNum,
40+
num: item.num
41+
),
42+
name: item.userName,
43+
type: item.type,
44+
onAccept: {
45+
switch item.type {
46+
case .outgoing:
47+
viewStore.send(.acceptApplication(id: item.id))
48+
case .earlyReturn:
49+
viewStore.send(.acceptEarlyReturn(id: item.id))
50+
}
51+
},
52+
onReject: {
53+
switch item.type {
54+
case .outgoing:
55+
viewStore.send(.rejectApplication(id: item.id))
56+
case .earlyReturn:
57+
viewStore.send(.rejectEarlyReturn(id: item.id))
58+
}
4959
}
50-
},
51-
onReject: {
52-
switch item.type {
53-
case .outgoing:
54-
viewStore.send(.rejectApplication(id: item.id))
55-
case .earlyReturn:
56-
viewStore.send(.rejectEarlyReturn(id: item.id))
57-
}
58-
}
59-
)
60+
)
61+
}
6062
}
6163
}
64+
.padding(.vertical, 12)
6265
}
63-
.padding(.vertical, 12)
64-
}
65-
)
66-
}
66+
)
67+
}
6768

68-
if viewStore.isSelfStudyTeacher {
69-
AccordionView(
70-
badge: viewStore.floor,
71-
title: "외출자 확인",
72-
content: {
73-
VStack(spacing: 8) {
74-
if viewStore.outingStudentList.isEmpty {
75-
emptyStateView(message: "외출자가 없습니다")
76-
} else {
77-
ForEach(viewStore.outingStudentList) { item in
78-
OutingCell(
79-
studentNumber: self.studentNumber(
80-
grade: item.grade,
81-
classNum: item.classNum,
82-
num: item.num
83-
),
84-
name: item.userName,
85-
type: item.type
86-
)
69+
if viewStore.isSelfStudyTeacher {
70+
AccordionView(
71+
badge: viewStore.floor,
72+
title: "외출자 확인",
73+
content: {
74+
VStack(spacing: 8) {
75+
if viewStore.outingStudentList.isEmpty {
76+
emptyStateView(message: "외출자가 없습니다")
77+
} else {
78+
ForEach(viewStore.outingStudentList) { item in
79+
OutingCell(
80+
studentNumber: self.studentNumber(
81+
grade: item.grade,
82+
classNum: item.classNum,
83+
num: item.num
84+
),
85+
name: item.userName,
86+
type: item.type
87+
)
88+
}
8789
}
8890
}
91+
.padding(.vertical, 12)
8992
}
90-
.padding(.vertical, 12)
91-
}
92-
)
93+
)
9394

94-
AccordionView(
95-
badge: viewStore.floor,
96-
title: "교실 이동자 확인",
97-
content: {
98-
VStack(spacing: 8) {
99-
if viewStore.classroomMoveList.isEmpty {
100-
emptyStateView(message: "교실 이동자가 없습니다")
101-
} else {
102-
ForEach(viewStore.classroomMoveList, id: \.id) { item in
103-
PiCKClassroomMoveCell(
104-
studentNumber: self.studentNumber(
105-
grade: item.grade,
106-
classNum: item.classNum,
107-
num: item.num
108-
),
109-
studentName: item.userName,
110-
startPeriod: item.start,
111-
endPeriod: item.end,
112-
currentClassroom: "\(item.grade)학년 \(item.classNum)",
113-
moveToClassroom: item.classroomName,
114-
isSelected: false,
115-
onTap: {}
116-
)
95+
AccordionView(
96+
badge: viewStore.floor,
97+
title: "교실 이동자 확인",
98+
content: {
99+
VStack(spacing: 8) {
100+
if viewStore.classroomMoveList.isEmpty {
101+
emptyStateView(message: "교실 이동자가 없습니다")
102+
} else {
103+
ForEach(viewStore.classroomMoveList, id: \.id) { item in
104+
PiCKClassroomMoveCell(
105+
studentNumber: self.studentNumber(
106+
grade: item.grade,
107+
classNum: item.classNum,
108+
num: item.num
109+
),
110+
studentName: item.userName,
111+
startPeriod: item.start,
112+
endPeriod: item.end,
113+
currentClassroom: "\(item.grade)학년 \(item.classNum)",
114+
moveToClassroom: item.classroomName,
115+
isSelected: false,
116+
onTap: {}
117+
)
118+
}
117119
}
118120
}
121+
.padding(.vertical, 12)
119122
}
120-
.padding(.vertical, 12)
121-
}
122-
)
123-
}
123+
)
124+
}
124125

125-
AllSelfStudyView(selfStudyDirector: viewStore.selfStudyDirector)
126-
.frame(maxWidth: .infinity)
126+
AllSelfStudyView(selfStudyDirector: viewStore.selfStudyDirector)
127+
.frame(maxWidth: .infinity)
128+
}
129+
.padding(24)
127130
}
128-
.padding(24)
129-
}
130-
.navigationBarBackButtonHidden(true)
131-
.toolbar {
132-
ToolbarItem(placement: .navigationBarLeading) {
133-
PiCKNavigationBar()
134-
.padding(.leading, 8)
131+
.navigationBarBackButtonHidden(true)
132+
.toolbar {
133+
ToolbarItem(placement: .navigationBarLeading) {
134+
PiCKNavigationBar()
135+
.padding(.leading, 8)
136+
}
137+
}
138+
.onAppear {
139+
viewStore.send(.fetchSelfStudyDirector(date: Date.todayString()))
140+
viewStore.send(.fetchAdminSelfStudyInfo)
141+
viewStore.send(.fetchSelfStudyAndClassroom)
142+
}
143+
if viewStore.showAlert {
144+
PiCKDisappearAlert(
145+
successType: viewStore.alertSuccessType,
146+
message: viewStore.alertMessage
147+
)
148+
.onDisappear {
149+
viewStore.send(.dismissAlert)
150+
}
135151
}
136-
}
137-
.onAppear {
138-
viewStore.send(.fetchSelfStudyDirector(date: Date.todayString()))
139-
viewStore.send(.fetchAdminSelfStudyInfo)
140-
viewStore.send(.fetchSelfStudyAndClassroom)
141152
}
142153
}
143154
}

0 commit comments

Comments
 (0)