feat(main): 홈 대화 탭을 추가한다
This commit is contained in:
93
SodaLive/Sources/V2/Main/Chat/MainChatView.swift
Normal file
93
SodaLive/Sources/V2/Main/Chat/MainChatView.swift
Normal file
@@ -0,0 +1,93 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainChatView: View {
|
||||
let onTapCanCharge: () -> Void
|
||||
let onTapSearch: () -> Void
|
||||
|
||||
@StateObject private var viewModel = MainChatViewModel()
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
DefaultTitleBar(title: MainTab.chat.title) {
|
||||
HStack(spacing: SodaSpacing.s14) {
|
||||
Image("ic_bar_cash")
|
||||
.onTapGesture { onTapCanCharge() }
|
||||
|
||||
Image("ic_bar_search")
|
||||
.onTapGesture { onTapSearch() }
|
||||
}
|
||||
}
|
||||
|
||||
CapsuleTabBar(
|
||||
items: MainChatFilter.allCases,
|
||||
selectedItem: selectedFilterBinding,
|
||||
title: { $0.title }
|
||||
)
|
||||
|
||||
chatListContent
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
.background(Color.black.ignoresSafeArea())
|
||||
.onAppear { viewModel.fetchFirstPageIfNeeded() }
|
||||
.sodaToast(
|
||||
isPresented: $viewModel.isShowPopup,
|
||||
message: viewModel.errorMessage,
|
||||
autohideIn: 2
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private var selectedFilterBinding: Binding<MainChatFilter> {
|
||||
Binding(
|
||||
get: { viewModel.selectedFilter },
|
||||
set: { viewModel.applyFilter($0) }
|
||||
)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var chatListContent: some View {
|
||||
if viewModel.isLoading && viewModel.rooms.isEmpty {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
.tint(Color.soda400)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else if viewModel.shouldShowEmptyState {
|
||||
Text(I18n.MainChat.emptyStateMessage)
|
||||
.appFont(size: 16, weight: .medium)
|
||||
.foregroundColor(Color.gray500)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
ScrollView(showsIndicators: false) {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(viewModel.rooms) { room in
|
||||
MainChatRoomListItem(room: room) { roomId, chatType in
|
||||
handleChatRoomTap(roomId: roomId, chatType: chatType)
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.fetchNextPageIfNeeded(currentItem: room)
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.isLoadingNextPage {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
.tint(Color.soda400)
|
||||
.padding(.vertical, SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
.padding(.top, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleChatRoomTap(roomId: Int, chatType: String) {
|
||||
guard chatType == "AI" else { return }
|
||||
AppState.shared.setAppStep(step: .chatRoom(id: roomId))
|
||||
}
|
||||
}
|
||||
|
||||
struct MainChatView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainChatView(onTapCanCharge: {}, onTapSearch: {})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user