feat(chat): 대화 탭 당겨서 새로고침을 추가한다
This commit is contained in:
@@ -54,16 +54,10 @@ struct MainChatView: View {
|
|||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var chatListContent: some View {
|
private var chatListContent: some View {
|
||||||
if viewModel.isLoading && viewModel.rooms.isEmpty {
|
if viewModel.isLoading && !viewModel.hasLoaded {
|
||||||
ProgressView()
|
loadingContent
|
||||||
.progressViewStyle(.circular)
|
|
||||||
.tint(Color.soda400)
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
} else if viewModel.shouldShowEmptyState {
|
} else if viewModel.shouldShowEmptyState {
|
||||||
Text(I18n.MainChat.emptyStateMessage)
|
emptyContent
|
||||||
.appFont(size: 16, weight: .medium)
|
|
||||||
.foregroundColor(Color.gray500)
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
} else {
|
} else {
|
||||||
ScrollView(showsIndicators: false) {
|
ScrollView(showsIndicators: false) {
|
||||||
LazyVStack(spacing: 0) {
|
LazyVStack(spacing: 0) {
|
||||||
@@ -85,6 +79,39 @@ struct MainChatView: View {
|
|||||||
}
|
}
|
||||||
.padding(.top, 0)
|
.padding(.top, 0)
|
||||||
}
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var loadingContent: some View {
|
||||||
|
GeometryReader { geometry in
|
||||||
|
ScrollView(showsIndicators: false) {
|
||||||
|
ProgressView()
|
||||||
|
.progressViewStyle(.circular)
|
||||||
|
.tint(Color.soda400)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.frame(minHeight: geometry.size.height)
|
||||||
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var emptyContent: some View {
|
||||||
|
GeometryReader { geometry in
|
||||||
|
ScrollView(showsIndicators: false) {
|
||||||
|
Text(I18n.MainChat.emptyStateMessage)
|
||||||
|
.appFont(size: 16, weight: .medium)
|
||||||
|
.foregroundColor(Color.gray500)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.frame(minHeight: geometry.size.height)
|
||||||
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,16 @@ final class MainChatViewModel: ObservableObject {
|
|||||||
fetchChatRooms(filter: filter, cursor: nil, isNextPage: false)
|
fetchChatRooms(filter: filter, cursor: nil, isNextPage: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refresh() async {
|
||||||
|
if !isLoading {
|
||||||
|
fetchChatRooms(filter: selectedFilter, cursor: nil, isNextPage: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
for await isLoading in $isLoading.values {
|
||||||
|
if !isLoading { return }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func applyFilter(_ filter: MainChatFilter) {
|
func applyFilter(_ filter: MainChatFilter) {
|
||||||
guard selectedFilter != filter else { return }
|
guard selectedFilter != filter else { return }
|
||||||
fetchFirstPage(filter: filter)
|
fetchFirstPage(filter: filter)
|
||||||
@@ -42,7 +52,11 @@ final class MainChatViewModel: ObservableObject {
|
|||||||
fetchChatRooms(filter: selectedFilter, cursor: nextCursor, isNextPage: true)
|
fetchChatRooms(filter: selectedFilter, cursor: nextCursor, isNextPage: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func fetchChatRooms(filter: MainChatFilter, cursor: String?, isNextPage: Bool) {
|
private func fetchChatRooms(
|
||||||
|
filter: MainChatFilter,
|
||||||
|
cursor: String?,
|
||||||
|
isNextPage: Bool
|
||||||
|
) {
|
||||||
latestRequestId += 1
|
latestRequestId += 1
|
||||||
let requestId = latestRequestId
|
let requestId = latestRequestId
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user