feat(home): 팔로잉 최근 대화를 연결한다

This commit is contained in:
Yu Sung
2026-07-01 11:43:45 +09:00
parent 5761d6083b
commit 772af3dfe3
7 changed files with 194 additions and 10 deletions

View File

@@ -0,0 +1,137 @@
import SwiftUI
struct MainHomeFollowingChatSection: View {
let recentChats: [ChatRoomListItemResponse]
let onTapTitle: () -> Void
let onTapChatRoom: (Int) -> Void
init(
recentChats: [ChatRoomListItemResponse],
onTapTitle: @escaping () -> Void = {},
onTapChatRoom: @escaping (Int) -> Void = { _ in }
) {
self.recentChats = recentChats
self.onTapTitle = onTapTitle
self.onTapChatRoom = onTapChatRoom
}
var body: some View {
if !recentChats.isEmpty {
VStack(alignment: .leading, spacing: SodaSpacing.s14) {
SectionTitle(title: I18n.HomeFollowing.recentChatTitle, action: onTapTitle)
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(alignment: .top, spacing: SodaSpacing.s8) {
ForEach(recentChats) { chat in
MainHomeFollowingChatItemView(chat: chat) {
onTapChatRoom(chat.roomId)
}
}
}
.padding(.leading, SodaSpacing.s14)
}
}
}
}
}
private struct MainHomeFollowingChatItemView: View {
let chat: ChatRoomListItemResponse
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(alignment: .center, spacing: SodaSpacing.s12) {
DownsampledKFImage(url: URL(string: chat.targetImageUrl), size: CGSize(width: 64, height: 64))
.clipShape(Circle())
VStack(alignment: .leading, spacing: SodaSpacing.s4) {
HStack(alignment: .top, spacing: SodaSpacing.s6) {
if chat.isDirectMessage {
DirectTagView()
}
Spacer(minLength: 0)
Text(chat.relativeLastMessageAtText())
.appFont(size: 12, weight: .regular)
.foregroundColor(Color.gray500)
.lineLimit(1)
}
.frame(height: 19)
Text(chat.targetName)
.appFont(size: 14, weight: .bold)
.foregroundColor(.white)
.lineLimit(1)
.truncationMode(.tail)
Text(chat.lastMessage)
.appFont(size: 14, weight: .regular)
.foregroundColor(.white)
.lineLimit(1)
.truncationMode(.tail)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(SodaSpacing.s14)
.frame(width: 288, alignment: .leading)
.background(Color.gray900)
.cornerRadius(14)
}
.buttonStyle(.plain)
}
}
private struct DirectTagView: View {
var body: some View {
Text("Direct")
.appFont(size: 12, weight: .bold)
.italic()
.foregroundColor(.white)
.padding(.horizontal, SodaSpacing.s4)
.padding(.vertical, 2)
.background(Color.soda400)
.cornerRadius(4)
}
}
private extension ChatRoomListItemResponse {
var isDirectMessage: Bool {
chatType == "DM"
}
func relativeLastMessageAtText(now: Date = Date()) -> String {
DateParser.relativeTimeText(fromUTC: lastMessageAt, fallback: lastMessageAt, now: now)
}
}
struct MainHomeFollowingChatSection_Previews: PreviewProvider {
private static let previewImageUrl = "https://picsum.photos/500/500"
static var previews: some View {
MainHomeFollowingChatSection(
recentChats: [
ChatRoomListItemResponse(
roomId: 1,
chatType: "DM",
targetName: "크리에이터 이름",
targetImageUrl: previewImageUrl,
lastMessage: "마지막 대화 내용이 들어가는 부분 한줄만",
lastMessageAt: "2026-07-01T01:30:00Z"
),
ChatRoomListItemResponse(
roomId: 2,
chatType: "GROUP",
targetName: "소다",
targetImageUrl: previewImageUrl,
lastMessage: "다음 대화 내용입니다",
lastMessageAt: "2026-07-01T01:20:00Z"
)
]
)
.padding(.vertical, SodaSpacing.s20)
.background(Color.black)
.previewLayout(.sizeThatFits)
}
}

View File

@@ -4,17 +4,23 @@ struct MainHomeFollowingView: View {
let onTapLive: (Int) -> Void
let onTapCreator: (Int) -> Void
let onTapFollowingAll: () -> Void
let onTapChatTab: () -> Void
let onTapChatRoom: (Int) -> Void
@StateObject private var viewModel = MainHomeFollowingViewModel()
init(
onTapLive: @escaping (Int) -> Void = { _ in },
onTapCreator: @escaping (Int) -> Void = { _ in },
onTapFollowingAll: @escaping () -> Void = {}
onTapFollowingAll: @escaping () -> Void = {},
onTapChatTab: @escaping () -> Void = {},
onTapChatRoom: @escaping (Int) -> Void = { _ in }
) {
self.onTapLive = onTapLive
self.onTapCreator = onTapCreator
self.onTapFollowingAll = onTapFollowingAll
self.onTapChatTab = onTapChatTab
self.onTapChatRoom = onTapChatRoom
}
var body: some View {
@@ -30,6 +36,14 @@ struct MainHomeFollowingView: View {
onTapLive: onTapLive
)
if let recentChats = viewModel.response?.recentChats, !recentChats.isEmpty {
MainHomeFollowingChatSection(
recentChats: recentChats,
onTapTitle: onTapChatTab,
onTapChatRoom: onTapChatRoom
)
}
MainPlaceholderTabView(title: "팔로잉")
}
.onAppear {

View File

@@ -13,6 +13,8 @@ struct MainHomeView: View {
let onTapFollowAll: (@escaping () -> Void) -> Void
let onSelectFollowingTab: () -> Bool
let onTapFollowingAll: () -> Void
let onTapChatTab: () -> Void
let onTapChatRoom: (Int) -> Void
@State private var selectedTab: MainHomeTab = .recommendation
@@ -75,7 +77,9 @@ struct MainHomeView: View {
MainHomeFollowingView(
onTapLive: onTapLive,
onTapCreator: onTapCreator,
onTapFollowingAll: onTapFollowingAll
onTapFollowingAll: onTapFollowingAll,
onTapChatTab: onTapChatTab,
onTapChatRoom: onTapChatRoom
)
}
}
@@ -112,7 +116,9 @@ struct MainHomeView_Previews: PreviewProvider {
onTapBanner: { _ in },
onTapFollowAll: { action in action() },
onSelectFollowingTab: { true },
onTapFollowingAll: {}
onTapFollowingAll: {},
onTapChatTab: {},
onTapChatRoom: { _ in }
)
}
}

View File

@@ -165,7 +165,9 @@ struct MainView: View {
onTapBanner: handleRecommendationBannerTap,
onTapFollowAll: handleRecommendationFollowAllTap,
onSelectFollowingTab: handleFollowingTabSelection,
onTapFollowingAll: handleFollowingAllTap
onTapFollowingAll: handleFollowingAllTap,
onTapChatTab: handleFollowingChatTabTap,
onTapChatRoom: handleFollowingChatRoomTap
)
case .content:
MainPlaceholderTabView(title: MainTab.content.title)
@@ -490,6 +492,15 @@ struct MainView: View {
appState.setAppStep(step: .followingList)
}
private func handleFollowingChatTabTap() {
viewModel.currentTab = .chat
}
private func handleFollowingChatRoomTap(roomId: Int) {
guard roomId > 0 else { return }
appState.setAppStep(step: .chatRoom(id: roomId))
}
private func handleFollowingTabSelection() -> Bool {
let trimmed = token.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else {