Skip to content

Commit

Permalink
[Edit] isShowRatingDialog 프로퍼티 RecordViewModel 내로 이동 #166
Browse files Browse the repository at this point in the history
  • Loading branch information
withseon committed Mar 22, 2024
1 parent 561ca11 commit a5ef9f3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 33 deletions.
1 change: 0 additions & 1 deletion JUDA_iOS/JUDA/Resource/Components/PostCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct PostCell: View {
// 좋아요를 등록 -> 빨간색이 채워진 하트
// 좋아요를 해제 -> 테두리가 회색인 하트
Button {
// TODO: 로그인 안 되어 있을 때, 로그인 페이지 넘어가기
if authViewModel.signInStatus {
isLike.toggle()
debouncer.call {
Expand Down
12 changes: 6 additions & 6 deletions JUDA_iOS/JUDA/View/Posts/PostGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ struct PostGridContent: View {
var body: some View {
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: 15) {
if usedTo == .post {
if !postViewModel.isLoading {
ForEach(postViewModel.posts, id: \.postField.postID) { post in
if !postViewModel.isLoading {
ForEach(postViewModel.posts, id: \.postField.postID) { post in
NavigationLink(value: Route
.PostDetail(postUserType: authViewModel.currentUser?.userField.userID == post.postField.user.userID ? .writer : .reader,
post: post,
Expand All @@ -82,10 +82,10 @@ struct PostGridContent: View {
}
}
}
.buttonStyle(EmptyActionStyle())
// TODO: 비로그인 상태인 경우 눌렀을 때 로그인뷰로 이동
.disabled(!authViewModel.signInStatus)
}
.buttonStyle(EmptyActionStyle())
// TODO: 비로그인 상태인 경우 눌렀을 때 로그인뷰로 이동
.disabled(!authViewModel.signInStatus)
}
} else {
ForEach(0..<10) { _ in
ShimmerPostCell()
Expand Down
10 changes: 4 additions & 6 deletions JUDA_iOS/JUDA/View/Record/AddTagView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ struct AddTagView: View {
@State private var selectedPhotos: [PhotosPickerItem] = []
// SearchTagView Sheet를 띄워주는 상태 프로퍼티
@State private var isShowSearchTag = false
// CustomDialog - rating 을 띄워주는 상태 프로퍼티
@State private var isShowRatingDialog: Bool = false
// CustomDialog - oneButton 을 띄워주는 상태 프로퍼티
@State private var isShowAlertDialog: Bool = false
// 숱 태그가 5개를 넘어가는지 확인하는 상태 프로퍼티
Expand Down Expand Up @@ -60,18 +58,18 @@ struct AddTagView: View {
} else {
// 술 태그가 있을 때, DrinkTagCellScrollView 보여주기
// DrinkTagScroll 내부 Cell을 탭하면 CustomRatingDialog 띄워주기 위한 상태 프로퍼티 파라미터로 넘기기
DrinkTagScroll(isShowRatingDialog: $isShowRatingDialog)
DrinkTagScroll()
}
}
// CustomDialog - .rating
if isShowRatingDialog {
if recordViewModel.isShowRatingDialog {
CustomDialog(type: .rating(
// 선택된 술 태그의 술 이름
drinkName: recordViewModel.selectedDrinkTag?.drinkName ?? "",
leftButtonLabel: "취소",
leftButtonAction: {
// CustomRatingDialog 사라지게 하기
isShowRatingDialog = false
recordViewModel.isShowRatingDialog = false
},
rightButtonLabel: "수정",
rightButtonAction: {
Expand All @@ -83,7 +81,7 @@ struct AddTagView: View {
recordViewModel.drinkTags[index] = DrinkTag(drinkID: selectedDrinkTag.drinkID, drinkName: selectedDrinkTag.drinkName, drinkAmount: selectedDrinkTag.drinkAmount, drinkRating: rating)
}
// 점수 변경 후 CustomRatingDialog 사라지게 하기
isShowRatingDialog = false
recordViewModel.isShowRatingDialog = false
}
},
// 선택된 술 태그의 점수를 CustomDialog에 반영해서 띄워주기 위함
Expand Down
12 changes: 4 additions & 8 deletions JUDA_iOS/JUDA/View/Record/DrinkTagScroll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ import SwiftUI

// MARK: - 기록 시, 태그 된 술 리스트
struct DrinkTagScroll: View {
// CustomRatingDialog를 띄워주는 상태 프로퍼티
@Binding var isShowRatingDialog: Bool

var body: some View {
// MARK: iOS 16.4 이상
if #available(iOS 16.4, *) {
ScrollView {
DrinkTagContent(isShowRatingDialog: $isShowRatingDialog)
DrinkTagContent()
}
.scrollBounceBehavior(.basedOnSize, axes: .vertical)
// MARK: iOS 16.4 미만
} else {
ViewThatFits(in: .vertical) {
DrinkTagContent(isShowRatingDialog: $isShowRatingDialog)
DrinkTagContent()
.frame(maxHeight: .infinity, alignment: .top)
ScrollView {
DrinkTagContent(isShowRatingDialog: $isShowRatingDialog)
DrinkTagContent()
}
}
}
Expand All @@ -35,8 +33,6 @@ struct DrinkTagScroll: View {
// MARK: - DrinkTagScroll 로 보여줄 내용
struct DrinkTagContent: View {
@EnvironmentObject private var recordViewModel: RecordViewModel
// CustomRatingDialog를 띄워주는 상태 프로퍼티
@Binding var isShowRatingDialog: Bool

var body: some View {
LazyVStack {
Expand All @@ -46,7 +42,7 @@ struct DrinkTagContent: View {
// 현재 선택된 DrinkTagCell의 술 태그 정보 받아오기
recordViewModel.selectedDrinkTag = drinkTag
// CustomRatingDialog 띄우기
isShowRatingDialog.toggle()
recordViewModel.isShowRatingDialog = true
}
}
}
Expand Down
20 changes: 8 additions & 12 deletions JUDA_iOS/JUDA/View/Record/SearchTagView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ struct SearchTagView: View {
@EnvironmentObject private var drinkViewModel: DrinkViewModel
// drink 검색 결과를 담은 배열
@State var searchResult = [Drink]()
// CostomRatingDialog를 띄워주는 상태 프로퍼티
@State private var isShowRatingDialog: Bool = false
// SearchTagView Sheet를 띄워주는 상태 프로퍼티
@Binding var isShowSearchTag: Bool
// 점수
Expand Down Expand Up @@ -78,20 +76,20 @@ struct SearchTagView: View {
}
// 검색 텍스트 O
} else {
// MARK: iOS 16.4 이상
// MARK: iOS 16.4 이상isShowRatingDialog
if #available(iOS 16.4, *) {
ScrollView() {
SearchTagListContent(isShowRatingDialog: $isShowRatingDialog, searchResult: searchResult)
SearchTagListContent(searchResult: searchResult)
}
.scrollBounceBehavior(.basedOnSize, axes: .vertical)
.scrollDismissesKeyboard(.immediately)
// MARK: iOS 16.4 미만
} else {
ViewThatFits(in: .vertical) {
SearchTagListContent(isShowRatingDialog: $isShowRatingDialog, searchResult: searchResult)
SearchTagListContent(searchResult: searchResult)
.frame(maxHeight: .infinity, alignment: .top)
ScrollView {
SearchTagListContent(isShowRatingDialog: $isShowRatingDialog, searchResult: searchResult)
SearchTagListContent(searchResult: searchResult)
}
.scrollDismissesKeyboard(.immediately)
}
Expand All @@ -103,7 +101,7 @@ struct SearchTagView: View {
isFocused = false
}
// CustomDialog - .rating
if isShowRatingDialog {
if recordViewModel.isShowRatingDialog {
// 선택된 Cell의 술 정보 데이터를 잘 받아왔을 때
if let selectedDrinkTag = recordViewModel.selectedDrinkTag {
CustomDialog(type: .rating(
Expand All @@ -112,7 +110,7 @@ struct SearchTagView: View {
leftButtonLabel: "취소",
leftButtonAction: {
// CustomRatingDialog 사라지게 하기
isShowRatingDialog.toggle()
recordViewModel.isShowRatingDialog = false
},
rightButtonLabel: "평가",
rightButtonAction: {
Expand All @@ -135,7 +133,7 @@ struct SearchTagView: View {
drinkRating: rating))
}
// 변경 후 CustomRatingDialog, SearchTagView 사라지게 하기
isShowRatingDialog.toggle()
recordViewModel.isShowRatingDialog = false
isShowSearchTag.toggle()
}
},
Expand All @@ -154,8 +152,6 @@ struct SearchTagView: View {
// MARK: - 스크롤 뷰 or 뷰 로 보여질 태그 추가 시, DrinkListCell 리스트
struct SearchTagListContent: View {
@EnvironmentObject private var recordViewModel: RecordViewModel
// CostomRatingDialog를 띄워주는 상태 프로퍼티
@Binding var isShowRatingDialog: Bool
// drink 검색 결과 배열
let searchResult: [Drink]

Expand All @@ -168,7 +164,7 @@ struct SearchTagListContent: View {
guard let drinkID = drink.drinkField.drinkID else { return }
recordViewModel.selectedDrinkTag = DrinkTag(drinkID: drinkID, drinkName: drink.drinkField.name, drinkAmount: drink.drinkField.amount, drinkRating: 0)
// CustomRatingDialog 띄우기
isShowRatingDialog.toggle()
recordViewModel.isShowRatingDialog = true
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions JUDA_iOS/JUDA/ViewModel/Posts/PostViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ final class PostViewModel: ObservableObject {
@Published var isLoading = false
// 검색 중
@Published var isSearching = false
// 로그인 안내 다이얼로그
@Published var isLoginDialog = false
}

// MARK: - Fetch
Expand Down
2 changes: 2 additions & 0 deletions JUDA_iOS/JUDA/ViewModel/Record/RecordViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ final class RecordViewModel: ObservableObject {
@Published var postContentIsEmpty: Bool = true
// post 업로드 완료 확인 및 로딩 뷰 출력용 프로퍼티
@Published var isPostUploading: Bool = false
// CustomRatingDialog 띄워주는 프로퍼티
@Published var isShowRatingDialog: Bool = false
// 화면 너비 받아오기
var windowWidth: CGFloat {
TagHandler.getScreenWidthWithoutPadding(padding: 20)
Expand Down

0 comments on commit a5ef9f3

Please sign in to comment.