Skip to content

Commit

Permalink
Merge pull request #18 from Eunice0927/feat/summaryApi
Browse files Browse the repository at this point in the history
SummaryApi 리팩토링 및 긴글요약 UI 변경
  • Loading branch information
qlrmr111 authored Jan 8, 2025
2 parents 157f77c + 150baed commit 31b0e4e
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 98 deletions.
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 {
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

0 comments on commit 31b0e4e

Please sign in to comment.