fix(live-room): 라이브 상세 SNS 링크 아이콘 매핑을 신규 필드에 맞춘다
This commit is contained in:
@@ -32,8 +32,9 @@ struct GetRoomDetailManager: Decodable {
|
||||
let introduce: String
|
||||
let youtubeUrl: String?
|
||||
let instagramUrl: String?
|
||||
let websiteUrl: String?
|
||||
let blogUrl: String?
|
||||
let fancimmUrl: String?
|
||||
let xUrl: String?
|
||||
let kakaoOpenChatUrl: String?
|
||||
let profileImageUrl: String
|
||||
let isCreator: Bool
|
||||
}
|
||||
|
||||
@@ -152,46 +152,20 @@ struct LiveDetailView: View {
|
||||
.clipShape(Circle())
|
||||
|
||||
VStack(spacing: 16.7) {
|
||||
HStack(spacing: 6.7) {
|
||||
HStack(spacing: 8) {
|
||||
Text(manager.nickname)
|
||||
.appFont(size: 16.7, weight: .medium)
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
|
||||
Spacer()
|
||||
|
||||
if let websiteUrl = manager.websiteUrl, let url = URL(string: websiteUrl), UIApplication.shared.canOpenURL(url) {
|
||||
Image("ic_website_blue")
|
||||
|
||||
ForEach(makeSnsItems(from: manager)) { item in
|
||||
Image(item.iconName)
|
||||
.resizable()
|
||||
.frame(width: 33.3, height: 33.3)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}
|
||||
|
||||
if let blogUrl = manager.blogUrl, let url = URL(string: blogUrl), UIApplication.shared.canOpenURL(url) {
|
||||
Image("ic_blog_blue")
|
||||
.resizable()
|
||||
.frame(width: 33.3, height: 33.3)
|
||||
.onTapGesture {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}
|
||||
|
||||
if let instagramUrl = manager.instagramUrl, let url = URL(string: instagramUrl), UIApplication.shared.canOpenURL(url) {
|
||||
Image("ic_instagram_blue")
|
||||
.resizable()
|
||||
.frame(width: 33.3, height: 33.3)
|
||||
.onTapGesture {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}
|
||||
|
||||
if let youtubeUrl = manager.youtubeUrl, let url = URL(string: youtubeUrl), UIApplication.shared.canOpenURL(url) {
|
||||
Image("ic_youtube_play_blue")
|
||||
.resizable()
|
||||
.frame(width: 33.3, height: 33.3)
|
||||
.onTapGesture {
|
||||
UIApplication.shared.open(url)
|
||||
openSnsLink(item.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,4 +468,59 @@ struct LiveDetailView: View {
|
||||
AppState.shared.back()
|
||||
}
|
||||
}
|
||||
|
||||
private func makeSnsItems(from manager: GetRoomDetailManager) -> [LiveDetailSnsItem] {
|
||||
var items = [LiveDetailSnsItem]()
|
||||
|
||||
appendSnsItem(items: &items, iconName: "ic_sns_youtube", url: manager.youtubeUrl)
|
||||
appendSnsItem(items: &items, iconName: "ic_sns_instagram", url: manager.instagramUrl)
|
||||
appendSnsItem(items: &items, iconName: "ic_sns_x", url: manager.xUrl)
|
||||
appendSnsItem(items: &items, iconName: "ic_sns_fancimm", url: manager.fancimmUrl)
|
||||
appendSnsItem(items: &items, iconName: "ic_sns_kakao", url: manager.kakaoOpenChatUrl)
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
private func appendSnsItem(items: inout [LiveDetailSnsItem], iconName: String, url: String?) {
|
||||
guard let url else {
|
||||
return
|
||||
}
|
||||
|
||||
let trimmed = url.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
guard !trimmed.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
items.append(LiveDetailSnsItem(iconName: iconName, url: trimmed))
|
||||
}
|
||||
|
||||
private func openSnsLink(_ urlString: String) {
|
||||
guard let url = normalizedUrl(urlString), UIApplication.shared.canOpenURL(url) else {
|
||||
return
|
||||
}
|
||||
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
|
||||
private func normalizedUrl(_ urlString: String) -> URL? {
|
||||
let trimmed = urlString.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
guard !trimmed.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if trimmed.hasPrefix("http://") || trimmed.hasPrefix("https://") {
|
||||
return URL(string: trimmed)
|
||||
}
|
||||
|
||||
return URL(string: "https://\(trimmed)")
|
||||
}
|
||||
}
|
||||
|
||||
private struct LiveDetailSnsItem: Identifiable {
|
||||
let iconName: String
|
||||
let url: String
|
||||
|
||||
var id: String { "\(iconName)-\(url)" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user