-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from YAPP-Github/TNT-205-alarmPage
[TNT-205] AlarmCheck ํ๋ฉด ์์ฑ
- Loading branch information
Showing
7 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// AlarmItemEntity.swift | ||
// Domain | ||
// | ||
// Created by ๋ฐ๋ฏผ์ on 2/2/25. | ||
// Copyright ยฉ 2025 yapp25thTeamTnT. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// ์๋ ํ์ธ์ ์ฌ์ฉ๋๋ ์๋ ์ ๋ณด ๊ตฌ์กฐ์ฒด | ||
public struct AlarmItemEntity: Equatable { | ||
/// ์๋ id | ||
public let alarmId: Int | ||
/// ์๋ ํ์ | ||
public let alarmType: AlarmType | ||
/// ์๋ ๋์ฐฉ ์๊ฐ | ||
public let alarmDate: Date | ||
/// ์๋ ํ์ธ ์ฌ๋ถ | ||
public let alarmSeenBefore: Bool | ||
|
||
public init( | ||
alarmId: Int, | ||
alarmType: AlarmType, | ||
alarmDate: Date, | ||
alarmSeenBefore: Bool | ||
) { | ||
self.alarmId = alarmId | ||
self.alarmType = alarmType | ||
self.alarmDate = alarmDate | ||
self.alarmSeenBefore = alarmSeenBefore | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// AlarmType.swift | ||
// Domain | ||
// | ||
// Created by ๋ฐ๋ฏผ์ on 2/2/25. | ||
// Copyright ยฉ 2025 yapp25thTeamTnT. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// ์ฑ์์ ์กด์ฌํ๋ ์๋ ์ ํ์ ์ ์ํ ์ด๊ฑฐํ | ||
public enum AlarmType: Equatable { | ||
/// ํธ๋ ์ด๋ ์ฐ๊ฒฐ ์๋ฃ | ||
case traineeConnected(name: String) | ||
/// ํธ๋ ์ด๋ ์ฐ๊ฒฐ ํด์ | ||
case traineeDisconnected(name: String) | ||
/// ํธ๋ ์ด๋ ์ฐ๊ฒฐ ํด์ | ||
case trainerDisconnected(name: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
TnT/Projects/Presentation/Sources/Alarm/AlarmCheckFeature.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// AlarmCheckFeature.swift | ||
// Presentation | ||
// | ||
// Created by ๋ฐ๋ฏผ์ on 2/2/25. | ||
// Copyright ยฉ 2025 yapp25thTeamTnT. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import ComposableArchitecture | ||
|
||
import Domain | ||
import DesignSystem | ||
|
||
@Reducer | ||
public struct AlarmCheckFeature { | ||
|
||
@ObservableState | ||
public struct State: Equatable { | ||
// MARK: Data related state | ||
/// ์ ์ ํ์ | ||
var userType: UserType | ||
/// ์๋ ์ ๋ณด ๋ชฉ๋ก | ||
var alarmList: [AlarmItemEntity] | ||
|
||
/// `AlarmCheckFeature.State`์ ์์ฑ์ | ||
/// - Parameters: | ||
/// - userType: ์ ์ ํ์ | ||
/// - alarmList: ์ ์ ์๊ฒ ๋์ฐฉํ ์๋ ๋ชฉ๋ก (๊ธฐ๋ณธ๊ฐ: `[]`) | ||
public init( | ||
userType: UserType, | ||
alarmList: [AlarmItemEntity] = [] | ||
) { | ||
self.userType = userType | ||
self.alarmList = alarmList | ||
} | ||
} | ||
|
||
@Dependency(\.dismiss) private var dismiss | ||
|
||
public enum Action: Sendable, ViewAction { | ||
/// ๋ทฐ์์ ๋ฐ์ํ ์ก์ ์ ์ฒ๋ฆฌํฉ๋๋ค. | ||
case view(View) | ||
/// ๋ค๋น๊ฒ์ด์ ์ฌ๋ถ ์ค์ | ||
case setNavigating | ||
|
||
@CasePathable | ||
public enum View: Sendable, BindableAction { | ||
/// ๋ฐ์ธ๋ฉ ์ก์ ์ฒ๋ฆฌ | ||
case binding(BindingAction<State>) | ||
/// ์๋ ์์ดํ ํญ ๋์์ ๋ | ||
case tapAlarmItem(Int) | ||
/// ๋ค๋น๊ฒ์ด์ back ๋ฒํผ ํญ ๋์์ ๋ | ||
case tapNavBackButton | ||
} | ||
} | ||
|
||
public init() {} | ||
|
||
public var body: some ReducerOf<Self> { | ||
BindingReducer(action: \.view) | ||
|
||
Reduce { state, action in | ||
switch action { | ||
case .view(let action): | ||
switch action { | ||
case .binding: | ||
return .none | ||
|
||
case .tapAlarmItem(let id): | ||
print("alarmId: \(id)") | ||
return .none | ||
|
||
case .tapNavBackButton: | ||
return .run { _ in | ||
// TODO: ์๋ฒ API ๋ช ์ธ ๋์ค๋ฉด ์ฐ๊ฒฐ | ||
// ํ์ฌ ๋ชจ๋ ์๋ ํ์ธ ํ์ | ||
await self.dismiss() | ||
} | ||
} | ||
case .setNavigating: | ||
return .none | ||
} | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
TnT/Projects/Presentation/Sources/Alarm/AlarmCheckView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// AlarmCheckView.swift | ||
// Presentation | ||
// | ||
// Created by ๋ฐ๋ฏผ์ on 2/2/25. | ||
// Copyright ยฉ 2025 yapp25thTeamTnT. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import ComposableArchitecture | ||
|
||
import Domain | ||
import DesignSystem | ||
|
||
/// ์๋ ๋ชฉ๋ก์ ์ ๋ ฅํ๋ ํ๋ฉด | ||
/// ์ ์ ์๊ฒ ๋์ฐฉํ ์๋์ ํ์ - ์ ์ ํ์ ์ ๋ฐ๋ผ ๋ถ๋ฅ | ||
@ViewAction(for: AlarmCheckFeature.self) | ||
public struct AlarmCheckView: View { | ||
|
||
@Bindable public var store: StoreOf<AlarmCheckFeature> | ||
@Environment(\.dismiss) var dismiss: DismissAction | ||
|
||
public init(store: StoreOf<AlarmCheckFeature>) { | ||
self.store = store | ||
} | ||
|
||
public var body: some View { | ||
VStack(spacing: 0) { | ||
TNavigation( | ||
type: .LButtonWithTitle(leftImage: .icnArrowLeft, centerTitle: "์๋ฆผ"), | ||
leftAction: { send(.tapNavBackButton) } | ||
) | ||
|
||
ScrollView { | ||
AlarmList() | ||
Spacer() | ||
} | ||
} | ||
.navigationBarBackButtonHidden(true) | ||
} | ||
|
||
// MARK: - Sections | ||
@ViewBuilder | ||
private func AlarmList() -> some View { | ||
VStack(spacing: 0) { | ||
ForEach(store.alarmList, id: \.alarmId) { item in | ||
AlarmListItem( | ||
alarmTypeText: item.alarmTypeText, | ||
alarmMainText: item.alarmMainText, | ||
alarmTimeText: item.alarmDate.timeAgoDisplay(), | ||
alarmSeenBefore: item.alarmSeenBefore | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private extension AlarmCheckView { | ||
struct AlarmListItem: View { | ||
/// ์ฐ๊ฒฐ ์๋ฃ, ์ฐ๊ฒฐ ํด์ ๋ฑ | ||
let alarmTypeText: String | ||
/// ์๋ ๋ณธ๋ฌธ | ||
let alarmMainText: String | ||
/// ์๋ ์๊ฐ | ||
let alarmTimeText: String | ||
/// ์๋ ํ์ธ ์ฌ๋ถ | ||
let alarmSeenBefore: Bool | ||
|
||
var body: some View { | ||
HStack(spacing: 16) { | ||
Image(.icnBombEmpty) | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: 32, height: 32) | ||
|
||
VStack(alignment: .leading, spacing: 4) { | ||
HStack { | ||
Text(alarmTypeText) | ||
.typographyStyle(.label1Bold, with: .neutral400) | ||
.padding(.bottom, 3) | ||
Spacer() | ||
Text(alarmTimeText) | ||
.typographyStyle(.label1Medium, with: .neutral400) | ||
} | ||
|
||
Text(alarmMainText) | ||
.typographyStyle(.body2Medium, with: .neutral800) | ||
} | ||
} | ||
.padding(20) | ||
.background(alarmSeenBefore ? Color.common0 : Color.neutral100) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Date+.swift | ||
// Presentation | ||
// | ||
// Created by ๋ฐ๋ฏผ์ on 2/2/25. | ||
// Copyright ยฉ 2025 yapp25thTeamTnT. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
|
||
extension Date { | ||
func timeAgoDisplay() -> String { | ||
let now = Date() | ||
let calendar = Calendar.current | ||
let components = calendar.dateComponents([.second, .minute, .hour, .day], from: self, to: now) | ||
|
||
if let day = components.day, day >= 1 { | ||
return TDateFormatUtility.formatter(for: .M์_d์ผ).string(from: self) | ||
} else if let hour = components.hour, hour >= 1 { | ||
return "\(hour)์๊ฐ ์ " | ||
} else if let minute = components.minute, minute >= 1 { | ||
return "\(minute)๋ถ ์ " | ||
} else { | ||
return "๋ฐฉ๊ธ" | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
TnT/Projects/Presentation/Sources/PresentationSupport/AlarmItemEntity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// AlarmItemEntity.swift | ||
// Presentation | ||
// | ||
// Created by ๋ฐ๋ฏผ์ on 2/2/25. | ||
// Copyright ยฉ 2025 yapp25thTeamTnT. All rights reserved. | ||
// | ||
|
||
import Domain | ||
|
||
extension AlarmItemEntity { | ||
/// ์ฐ๊ฒฐ ์๋ฃ, ์ฐ๊ฒฐ ํด์ ๋ฑ | ||
var alarmTypeText: String { | ||
switch self.alarmType { | ||
case .traineeConnected: | ||
return "ํธ๋ ์ด๋ ์ฐ๊ฒฐ ์๋ฃ" | ||
case .traineeDisconnected: | ||
return "ํธ๋ ์ด๋ ์ฐ๊ฒฐ ํด์ " | ||
case .trainerDisconnected: | ||
return "ํธ๋ ์ด๋ ์ฐ๊ฒฐ ํด์ " | ||
} | ||
} | ||
|
||
/// ์๋ ๋ณธ๋ฌธ | ||
var alarmMainText: String { | ||
switch self.alarmType { | ||
case .traineeConnected(let name): | ||
return "\(name) ํ์๊ณผ ์ฐ๊ฒฐ๋์์ด์" | ||
case .traineeDisconnected(let name): | ||
return "\(name) ํ์์ด ์ฐ๊ฒฐ์ ๋์์ด์" | ||
case .trainerDisconnected(let name): | ||
return "\(name) ํธ๋ ์ด๋๊ฐ ์ฐ๊ฒฐ์ ๋์์ด์" | ||
} | ||
} | ||
} |