Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SummaryApi 리팩토링 및 긴글요약 UI 변경 #18

Merged
merged 9 commits into from
Jan 8, 2025
23 changes: 12 additions & 11 deletions PJ3T3_Postie.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"originHash" : "80b28216e3b9698278981fea0e0b3236fc9f0451523b03f4389c82f65dd436e6",
"pins" : [
{
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "bfc0b6f81adc06ce5121eb23f628473638d67c5c",
"version" : "1.2022062300.0"
"revision" : "194a6706acbd25e4ef639bcaddea16e8758a3e27",
"version" : "1.2024011602.0"
}
},
{
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "3e464dad87dad2d29bb29a97836789bf0f8f67d2",
"version" : "10.18.1"
"revision" : "3b62f154d00019ae29a71e9738800bb6f18b236d",
"version" : "10.19.2"
}
},
{
Expand All @@ -32,17 +33,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "b880ec8ec927a838c51c12862c6222c30d7097d7",
"version" : "10.20.0"
"revision" : "eca84fd638116dd6adb633b5a3f31cc7befcbb7d",
"version" : "10.29.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "ceec9f28dea12b7cf3dabf18b5ed7621c88fd4aa",
"version" : "10.20.0"
"revision" : "fe727587518729046fc1465625b9afd80b5ab361",
"version" : "10.28.0"
}
},
{
Expand Down Expand Up @@ -77,8 +78,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "a673bc2937fbe886dd1f99c401b01b6d977a9c98",
"version" : "1.49.1"
"revision" : "e9fad491d0673bdda7063a0341fb6b47a30c5359",
"version" : "1.62.2"
}
},
{
Expand Down Expand Up @@ -163,5 +164,5 @@
}
}
],
"version" : 2
"version" : 3
}
72 changes: 72 additions & 0 deletions PJ3T3_Postie/Core/Letter/View/AddLetterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ struct AddLetterView: View {
focusField = .summary
}
}
.sheet(isPresented: $addLetterViewModel.showingSelectSummaryView) {
SelectSummaryView
.presentationDetents([.medium])
.interactiveDismissDisabled(true)
}
.customOnChange(addLetterViewModel.shouldDismiss) { shouldDismiss in
if shouldDismiss {
dismiss()
Expand Down Expand Up @@ -347,6 +352,73 @@ extension AddLetterView {
}
}
}

@ViewBuilder
private var SelectSummaryView: some View {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 뷰 같은 코드가 반복되고 있는 것 같은데, SelectSummaryView를 별도의 파일로 분리하고, SelectSummaryViewModel도 하나로 관리하면 좋을 것 같습니다.
ViewModel의 경우 AddLetterView, EditLetterView, SlowPostboxView의 공통 상위 뷰에서 StateObject로 선언하고
AddLetterView, EditLetterView, SlowPostboxView 내부에는 ObservedObject로 선언한 다음 AddLetterView, EditLetterView, SlowPostboxView를 생성할 때 주입해주는 방식이 좋을 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

흠 그럼 SelectSummaryView말고도 다른 반복되는 뷰들도 많은데 그렇게 하는데 더 낫겠죠?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우선 운기님이 새로 만들어주신 SelectSummaryView만이라도 분리되면 좋을 것 같아요!
다른 뷰도 반복이 많기는 한데 뷰모델을 분리할 방법을 생각을 아직 못해봤습니다!!

ZStack {
postieColors.backGroundColor
.ignoresSafeArea()

VStack(spacing : 0) {
Text("요약 선택")
.font(.title)
.bold()
.foregroundStyle(postieColors.tintColor)
.padding()
.padding(.top, 5)

ScrollView (showsIndicators: false) {
VStack(spacing: 0) {
// summaryList에서 하나를 선택할 수 있는 기능
ForEach(addLetterViewModel.summaryList.indices, id: \.self) { index in
let summary = addLetterViewModel.summaryList[index]

Button(action: {
addLetterViewModel.selectedSummary = summary
}) {
Text(summary)
.padding()
.foregroundColor(addLetterViewModel.selectedSummary == summary ? postieColors.tintColor : postieColors.tabBarTintColor)
.fontWeight(addLetterViewModel.selectedSummary == summary ? .bold : .regular)
.frame(maxWidth: .infinity)
.background(postieColors.receivedLetterColor)
.cornerRadius(10)
}
.padding(.horizontal)
.padding(.vertical, 5)
}
}
}
.scrollContentBackground(.hidden)

Spacer()

HStack {
Spacer()

Button("취소") {
addLetterViewModel.closeSelectSummaryView()
}
.foregroundStyle(postieColors.tabBarTintColor)
.padding()

Spacer()

Button("확인") {
addLetterViewModel.summary = addLetterViewModel.selectedSummary
addLetterViewModel.showSummaryTextField()
addLetterViewModel.closeSelectSummaryView()
}
.foregroundStyle(addLetterViewModel.selectedSummary.isEmpty ? postieColors.profileColor : postieColors.tintColor)
.fontWeight(addLetterViewModel.selectedSummary.isEmpty ? .regular : .bold)
.padding()
.disabled(addLetterViewModel.selectedSummary.isEmpty) // 선택해야 확인 버튼 활성화

Spacer()
}
}
}
}
}

#Preview {
Expand Down
72 changes: 72 additions & 0 deletions PJ3T3_Postie/Core/Letter/View/EditLetterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ struct EditLetterView: View {
focusField = .summary
}
}
.sheet(isPresented: $editLetterViewModel.showingSelectSummaryView) {
SelectSummaryView
.presentationDetents([.medium])
.interactiveDismissDisabled(true)
}
.customOnChange(editLetterViewModel.shouldDismiss) { shouldDismiss in
if shouldDismiss {
dismiss()
Expand Down Expand Up @@ -349,6 +354,73 @@ extension EditLetterView {
}
}
}

@ViewBuilder
private var SelectSummaryView: some View {
ZStack {
postieColors.backGroundColor
.ignoresSafeArea()

VStack(spacing : 0) {
Text("요약 선택")
.font(.title)
.bold()
.foregroundStyle(postieColors.tintColor)
.padding()
.padding(.top, 5)

ScrollView (showsIndicators: false) {
VStack(spacing: 0) {
// summaryList에서 하나를 선택할 수 있는 기능
ForEach(editLetterViewModel.summaryList.indices, id: \.self) { index in
let summary = editLetterViewModel.summaryList[index]

Button(action: {
editLetterViewModel.selectedSummary = summary
}) {
Text(summary)
.padding()
.foregroundColor(editLetterViewModel.selectedSummary == summary ? postieColors.tintColor : postieColors.tabBarTintColor)
.fontWeight(editLetterViewModel.selectedSummary == summary ? .bold : .regular)
.frame(maxWidth: .infinity)
.background(postieColors.receivedLetterColor)
.cornerRadius(10)
}
.padding(.horizontal)
.padding(.vertical, 5)
}
}
}
.scrollContentBackground(.hidden)

Spacer()

HStack {
Spacer()

Button("취소") {
editLetterViewModel.closeSelectSummaryView()
}
.foregroundStyle(postieColors.tabBarTintColor)
.padding()

Spacer()

Button("확인") {
editLetterViewModel.summary = editLetterViewModel.selectedSummary
editLetterViewModel.showSummaryTextField()
editLetterViewModel.closeSelectSummaryView()
}
.foregroundStyle(editLetterViewModel.selectedSummary.isEmpty ? postieColors.profileColor : postieColors.tintColor)
.fontWeight(editLetterViewModel.selectedSummary.isEmpty ? .regular : .bold)
.padding()
.disabled(editLetterViewModel.selectedSummary.isEmpty) // 선택해야 확인 버튼 활성화

Spacer()
}
}
}
}
}


Expand Down
72 changes: 72 additions & 0 deletions PJ3T3_Postie/Core/Letter/View/SlowPostBoxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ struct SlowPostBoxView: View {
focusField = .summary
}
}
.sheet(isPresented: $slowPostBoxViewModel.showingSelectSummaryView) {
SelectSummaryView
.presentationDetents([.medium])
.interactiveDismissDisabled(true)
}
.customOnChange(slowPostBoxViewModel.shouldDismiss) { shouldDismiss in
if shouldDismiss {
dismiss()
Expand Down Expand Up @@ -349,6 +354,73 @@ extension SlowPostBoxView {
}
}
}

@ViewBuilder
private var SelectSummaryView: some View {
ZStack {
postieColors.backGroundColor
.ignoresSafeArea()

VStack(spacing : 0) {
Text("요약 선택")
.font(.title)
.bold()
.foregroundStyle(postieColors.tintColor)
.padding()
.padding(.top, 5)

ScrollView (showsIndicators: false) {
VStack(spacing: 0) {
// summaryList에서 하나를 선택할 수 있는 기능
ForEach(slowPostBoxViewModel.summaryList.indices, id: \.self) { index in
let summary = slowPostBoxViewModel.summaryList[index]

Button(action: {
slowPostBoxViewModel.selectedSummary = summary
}) {
Text(summary)
.padding()
.foregroundColor(slowPostBoxViewModel.selectedSummary == summary ? postieColors.tintColor : postieColors.tabBarTintColor)
.fontWeight(slowPostBoxViewModel.selectedSummary == summary ? .bold : .regular)
.frame(maxWidth: .infinity)
.background(postieColors.receivedLetterColor)
.cornerRadius(10)
}
.padding(.horizontal)
.padding(.vertical, 5)
}
}
}
.scrollContentBackground(.hidden)

Spacer()

HStack {
Spacer()

Button("취소") {
slowPostBoxViewModel.closeSelectSummaryView()
}
.foregroundStyle(postieColors.tabBarTintColor)
.padding()

Spacer()

Button("확인") {
slowPostBoxViewModel.summary = slowPostBoxViewModel.selectedSummary
slowPostBoxViewModel.showSummaryTextField()
slowPostBoxViewModel.closeSelectSummaryView()
}
.foregroundStyle(slowPostBoxViewModel.selectedSummary.isEmpty ? postieColors.profileColor : postieColors.tintColor)
.fontWeight(slowPostBoxViewModel.selectedSummary.isEmpty ? .regular : .bold)
.padding()
.disabled(slowPostBoxViewModel.selectedSummary.isEmpty) // 선택해야 확인 버튼 활성화

Spacer()
}
}
}
}
}


Expand Down
18 changes: 14 additions & 4 deletions PJ3T3_Postie/Core/Letter/ViewModel/AddLetterViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class AddLetterViewModel: ObservableObject {
@Published var shouldDismiss: Bool = false
@Published var isLoading: Bool = false
@Published var loadingText: String = "편지를 저장하고 있어요."
@Published var showingSelectSummaryView: Bool = false
@Published var summaryList: [String] = []
@Published var selectedSummary: String = ""

private(set) var imagePickerSourceType: UIImagePickerController.SourceType = .camera
var isReceived: Bool
Expand Down Expand Up @@ -63,6 +66,14 @@ class AddLetterViewModel: ObservableObject {
selectedIndex = index
showingLetterImageFullScreenView = true
}

func showSelectSummaryView() {
showingSelectSummaryView = true
}

func closeSelectSummaryView() {
showingSelectSummaryView = false
}

func showSummaryTextField() {
showingSummaryTextField = true
Expand Down Expand Up @@ -164,14 +175,13 @@ class AddLetterViewModel: ObservableObject {

func getSummary() async {
do {
let summaryResponse = try await APIClient.shared.postRequestToAPI(
title: isReceived ? "\(sender)에게 받은 편지" : "\(receiver)에게 쓴 편지",
let summaries = try await APIClient.shared.postRequestToAPI(
content: text
)

await MainActor.run {
summary = summaryResponse
showSummaryTextField()
summaryList = summaries
showSelectSummaryView()
}
} catch {
await MainActor.run {
Expand Down
Loading