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

[Fix] #241 - 코칭 3차 QA #242

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Smeem-iOS/Smeem-iOS/Global/Extensions/SwiftUI/View+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ extension View {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first {

window.rootViewController = viewControllerToPresent
let navigationController = UINavigationController(rootViewController: viewControllerToPresent)
window.rootViewController = navigationController

UIView.transition(with: window,
duration: 0.5,
Expand Down
9 changes: 7 additions & 2 deletions Smeem-iOS/Smeem-iOS/Global/Extensions/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ extension UIViewController {

func changeRootViewControllerAndPresent(_ viewControllerToPresent: UIViewController) {
if let window = UIApplication.shared.windows.first {
window.rootViewController = viewControllerToPresent
UIView.transition(with: window, duration: 0.5, options: .transitionCrossDissolve, animations: nil)
let navigationController = UINavigationController(rootViewController: viewControllerToPresent)
window.rootViewController = navigationController

UIView.transition(with: window,
duration: 0.5,
options: .transitionCrossDissolve,
animations: nil)
} else {
viewControllerToPresent.modalPresentationStyle = .overFullScreen
self.present(viewControllerToPresent, animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import SwiftUI

struct CoachingContentView: View {
@Binding var currentIndex: Int
@Binding var coachingsResponse: CoachingsResponse
@Binding var coachingResponse: [CoachingResponse]
@Binding var detailDiaryResponse: DetailDiaryResponse
@Binding var corrections: [CoachingResponse]

var body: some View {
VStack(spacing: 20.scaledByHeight()) {
Expand All @@ -19,11 +19,11 @@ struct CoachingContentView: View {
.foregroundStyle(Color(UIColor.gray100))

TabView(selection: $currentIndex) {
ForEach(coachingResponse.indices, id: \.self) { item in
ForEach(corrections.indices, id: \.self) { item in
ScrollView {
VStack(spacing: 8.scaledByHeight()) {
CoachingComparisonView(coachingResponse: $coachingResponse[item])
CoachingExplanationView(coachingResponse: $coachingResponse[item])
CoachingComparisonView(coachingResponse: $corrections[item])
CoachingExplanationView(coachingResponse: $corrections[item])
}
}
}
Expand All @@ -32,52 +32,14 @@ struct CoachingContentView: View {
.tabViewStyle(.page(indexDisplayMode: .never))
.padding(.horizontal, 16.scaledByWidth())

PageControl(currentPage: $currentIndex, coachingResponse: $coachingResponse)
PageControl(currentPage: $currentIndex, coachingResponse: $corrections)
}
}
}

#Preview {
@State var defaultIndex: Int = 0
@State var coachingsResponse = CoachingsResponse.empty
@State var coachingResponse = CoachingsResponse.empty.corrections
CoachingContentView(currentIndex: $defaultIndex, coachingsResponse: $coachingsResponse, coachingResponse: $coachingResponse)
}

//
//struct CoachingContentView: View {
// @Binding var currentIndex: Int
// @Binding var coachingResponse: CoachingsResponse
//
// var body: some View {
// VStack(spacing: screenHeight * (20 / screenHeight)) {
// Rectangle()
// .frame(height: screenHeight * (8 / screenHeight))
// .foregroundStyle(Color(UIColor.gray100))
//
// TabView(selection: $currentIndex) {
// ForEach(coachingResponse.corrections.indices, id: \.self) { item in
// ScrollView {
// VStack(spacing: screenWidth * (8 / screenWidth)) {
// CoachingComparisonView(coachingResponse: $coachingResponse.corrections[item])
//
// CoachingExplanationView(coachingResponse: $coachingResponse.corrections[item])
// }
// }
// }
// }
// .frame(width: screenWidth, height: screenHeight * (286 / screenHeight), alignment: .top)
// .tabViewStyle(.page(indexDisplayMode: .never))
// .padding(.horizontal, screenWidth * (16 / screenWidth))
//
// PageControl(currentPage: $currentIndex,
// coachingResponse: $coachingResponse)
// }
// }
//}
//
//#Preview {
// @State var defaultIndex: Int = 0
// @State var coachingResponse = CoachingsResponse.empty
// CoachingContentView(currentIndex: $defaultIndex, coachingResponse: $coachingResponse)
// @State var coachingsResponse = CoachingsResponse.empty
// @State var coachingResponse = CoachingsResponse.empty.corrections
// CoachingContentView(currentIndex: $defaultIndex, coachingsResponse: $coachingsResponse, coachingResponse: $coachingResponse)
//}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ struct CustomSegmentedControl: View {
)
}
}
.background(Color.gray.opacity(0.2))
// .background(Color.gray.opacity(0.2))
.cornerRadius(6)
}

private func isCoachingOn(_ index: Int) -> Bool {
// "코칭 ON"일 때만 selected 상태로 처리
return options[index] == "코칭 ON" && selectedIndex == index
}
}
Expand All @@ -44,19 +43,19 @@ struct SegmentButton: View {
Button(action: action) {
Text(title)
.padding(.vertical, 8.scaledByHeight())
.padding(.horizontal, 11.scaledByWidth())
.padding(.horizontal, 10.scaledByWidth())
.frame(maxWidth: .infinity)
.background(backgroundColor)
.foregroundColor(foregroundColor)
.font(Font(UIFont.c5))
// .lineLimit(1)
// .minimumScaleFactor(0.9)
.overlay(
Group {
// 'isSelected'일 때만 'isFirstButton'에 오버레이 추가
if isSelected && isFirstButton {
CustomStrokeShape(includeLeadingCorners: false)
.stroke(Color(UIColor.gray500), lineWidth: 1)
} else if !isSelected {
// 'isSelected'가 아닐 때는 모든 버튼에 대해 모서리 처리
CustomStrokeShape(
includeLeadingCorners: isFirstButton,
includeTrailingCorners: isLastButton
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// RandomTopicViewSwiftUI.swift
// Smeem-iOS
//
// Created by Joon Baek on 12/11/24.
//

import SwiftUI

struct RandomTopicViewSwiftUI: View {

// MARK: - Properties

var contentText: String?

// MARK: - Body

var body: some View {
GeometryReader { geometry in
HStack(alignment: .firstTextBaseline, spacing: 3) {
Text("Q.")
.font(Font(UIFont.b1))
.foregroundColor(Color(UIColor.point))
.padding(.leading, 18.scaledByWidth())

Text(contentText ?? "")
.font(Font(UIFont.b4))
.foregroundColor(Color(UIColor.smeemBlack))
.lineLimit(2)
.fixedSize(horizontal: false, vertical: true)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.trailing, 30.scaledByWidth())
}
.padding(.top, 20.scaledByHeight())
.padding(.bottom, 20.scaledByHeight())
.background(Color(UIColor.gray100))
}
.frame(height: contentText?.count ?? 0 > 20 ? 84.scaledByHeight() : 62.scaledByHeight())
}
}

#Preview {
var text: String = "랜덤주제 한줄일 경우 "
RandomTopicViewSwiftUI(contentText: text)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ struct SwiftUINavigationView: View {
navigationViewModel.leftButtonTapped.send()
}, label: {
Image("icnBack")
.imageScale(.large)
})
.padding(.leading, 12.scaledByWidth())
} else {
Spacer().frame(width: 30.scaledByWidth())
}

// 중앙 콘텐츠 (CustomSegmentedControl)
// CustomSegmentedControl
if navigationbarType == .diaryDetails {
CustomSegmentedControl(selectedIndex: $selectedIndex, options: options)
.frame(height: 32.scaledByHeight())
.padding(.leading, 65.scaledByWidth())
.padding(.trailing, 59.scaledByWidth())
.padding(.leading, 64.scaledByWidth())
.padding(.trailing, 58.scaledByWidth())
}

Spacer()
Expand Down Expand Up @@ -78,6 +77,6 @@ struct SwiftUINavigationView: View {
@State var defaultIndex = 0

NavigationView {
SwiftUINavigationView(navigationViewModel: NavigationViewModel(), selectedIndex: $defaultIndex, navigationbarType: .unCoached)
SwiftUINavigationView(navigationViewModel: NavigationViewModel(), selectedIndex: $defaultIndex, navigationbarType: .diaryDetails)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import UIKit

struct DetailDiaryCoachedView: View {

// MARK: - Properties

@StateObject private var navigationViewModel = NavigationViewModel()
@State private var cancelBag = Set<AnyCancellable>()

@State private var coachingsResponse = CoachingsResponse(corrections: [])
@State private var response: DetailDiaryResponse?
@State private var isLoading = false
@State private var onError = false
Expand All @@ -24,6 +25,7 @@ struct DetailDiaryCoachedView: View {
@State var diaryContent = ""
@State var randomTopic = ""
@State var currentIndex = 0
@State private var filteredCorrections: [CoachingResponse] = []
@State private var isShowingFloatingButtons = false
@State private var selectedIndex = 0
@State private var navigationbarType: NavigationbarType = .diaryDetails
Expand All @@ -34,8 +36,10 @@ struct DetailDiaryCoachedView: View {

private let detailDiaryService = DetailDiaryService.shared

// MARK: - Body

var body: some View {
VStack(spacing: 16.scaledByWidth()) {
VStack(spacing: 0) {
SwiftUINavigationView(navigationViewModel: navigationViewModel,
selectedIndex: $selectedIndex,
navigationbarType: navigationbarType
Expand Down Expand Up @@ -75,32 +79,42 @@ struct DetailDiaryCoachedView: View {
}
}

if let topic = response?.topic {
if topic != "" {
RandomTopicViewSwiftUI(contentText: response?.topic)
}
}

if let response = response {
ScrollableDiaryView(
diaryText: response.content,
corrections: response.corrections,
corrections: filteredCorrections,
currentIndex: currentIndex,
selectedIndex: selectedIndex,
dateText: response.createdAt,
authorText: response.username
)
} else {
if isLoading {
ProgressView("Loading...")
SmemeEmptyView()
SmemeLoadingView()
}
}

// "코칭 ON"일 때만 표시
if selectedIndex == 1 {
Spacer()
CoachingContentView(
currentIndex: $currentIndex,
coachingsResponse: $coachingsResponse,
coachingResponse: $coachingsResponse.corrections
)
} else {
Spacer(minLength: 342.scaledByHeight())
}
Spacer()
CoachingContentView(
currentIndex: $currentIndex,
detailDiaryResponse: Binding(
get: { self.response ?? .empty },
set: { _ in }
),
corrections: $filteredCorrections
)
} else {
Spacer()
}
}
.onAppear {
Task {
Expand Down Expand Up @@ -128,6 +142,14 @@ struct DetailDiaryCoachedView: View {
}
}
}
}

// MARK: - Extension

extension DetailDiaryCoachedView {
func filterCorrection(_ response: DetailDiaryResponse) -> [CoachingResponse] {
return response.corrections.filter { $0.isCorrected }.prefix(10).map{$0}
}

private func navigateToEditDiary() {
let editVC = EditDiaryViewController()
Expand All @@ -147,10 +169,9 @@ struct DetailDiaryCoachedView: View {
self.diaryContent = response.content
self.randomTopic = response.topic

let corrections = response.corrections ?? []
self.coachingsResponse = CoachingsResponse(corrections: corrections)
self.filteredCorrections = filterCorrection(response)

if corrections.isEmpty {
if filteredCorrections.isEmpty {
navigationbarType = .unCoached
}

Expand Down