Files
sodalive-ios/SodaLive/Sources/V2/CreatorChannel/Home/Components/CreatorChannelFanTalkSection.swift

143 lines
5.1 KiB
Swift

import SwiftUI
struct CreatorChannelFanTalkSection: View {
let fanTalk: CreatorChannelFanTalkSummaryResponse
let showsWriteButton: Bool
let onSelectTab: (CreatorChannelTab) -> Void
let onTapWrite: () -> Void
var body: some View {
VStack(alignment: .leading, spacing: SodaSpacing.s14) {
SectionTitle(title: I18n.CreatorChannelHome.fanTalk) {
onSelectTab(.fanTalk)
}
if let latestFanTalk = fanTalk.latestFanTalk {
CreatorChannelFanTalkCard(
totalCount: fanTalk.totalCount,
latestFanTalk: latestFanTalk
)
.padding(.horizontal, SodaSpacing.s14)
} else {
CreatorChannelFanTalkEmptyCard(
showsWriteButton: showsWriteButton,
onTapWrite: onTapWrite
)
.padding(.horizontal, SodaSpacing.s14)
}
}
.padding(.top, SodaSpacing.s20)
}
}
private struct CreatorChannelFanTalkEmptyCard: View {
let showsWriteButton: Bool
let onTapWrite: () -> Void
var body: some View {
VStack(alignment: .leading, spacing: 0) {
Text(I18n.CreatorChannelHome.fanTalkEmptyMessage)
.appFont(size: 24, weight: .bold)
.foregroundColor(.white)
.lineSpacing(0)
.padding(.top, SodaSpacing.s20)
.padding(.leading, SodaSpacing.s20)
Spacer(minLength: 0)
if showsWriteButton {
Button(action: onTapWrite) {
HStack(spacing: SodaSpacing.s6) {
Image("ic_plus_no_bg")
.resizable()
.renderingMode(.template)
.foregroundColor(.black)
.scaledToFit()
.frame(width: 20, height: 20)
Text(I18n.CreatorChannelFanTalk.writeAction)
.appFont(size: 16, weight: .medium)
.foregroundColor(.black)
.lineLimit(1)
}
.frame(maxWidth: .infinity)
.padding(SodaSpacing.s12)
.background(Color.white)
.clipShape(Capsule())
}
.buttonStyle(.plain)
.padding(.horizontal, SodaSpacing.s20)
.padding(.bottom, SodaSpacing.s20)
}
}
.frame(height: 196)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.gray900)
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
}
}
private struct CreatorChannelFanTalkCard: View {
let totalCount: Int
let latestFanTalk: CreatorChannelFanTalkResponse
var body: some View {
VStack(alignment: .leading, spacing: SodaSpacing.s8) {
HStack(spacing: SodaSpacing.s4) {
Text("전체")
.appFont(size: 16, weight: .medium)
.foregroundColor(.white)
Text("\(totalCount)")
.appFont(size: 16, weight: .medium)
.foregroundColor(Color.gray500)
}
HStack(alignment: .center, spacing: SodaSpacing.s14) {
DownsampledKFImage(
url: URL(string: latestFanTalk.profileImageUrl),
size: CGSize(width: 28, height: 28)
)
.background(Color.white.opacity(0.9))
.clipShape(Circle())
Text(latestFanTalk.content)
.appFont(size: 14, weight: .regular)
.foregroundColor(.white)
.lineLimit(2)
.truncationMode(.tail)
.frame(maxWidth: .infinity, minHeight: 40, alignment: .leading)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.padding(SodaSpacing.s14)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.gray900)
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
}
}
struct CreatorChannelFanTalkSection_Previews: PreviewProvider {
static var previews: some View {
CreatorChannelFanTalkSection(
fanTalk: CreatorChannelFanTalkSummaryResponse(
totalCount: 23,
latestFanTalk: CreatorChannelFanTalkResponse(
fanTalkId: 1,
memberId: 10,
nickname: "팬 닉네임",
profileImageUrl: "https://picsum.photos/120/120",
content: "팬이 쓴 응원이 보이는 부분입니다. 두 줄까지만 보여주고 초과 시 말줄임 처리합니다.",
languageCode: "ko",
createdAtUtc: "2026-07-03T03:44:00Z"
)
),
showsWriteButton: true,
onSelectTab: { _ in },
onTapWrite: {}
)
.background(Color.black)
.previewLayout(.sizeThatFits)
}
}