콘텐츠 전체보기
- 카테고리 추가
This commit is contained in:
45
SodaLive/Sources/Content/Category/CategoryApi.swift
Normal file
45
SodaLive/Sources/Content/Category/CategoryApi.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// CategoryApi.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2/7/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Moya
|
||||
|
||||
enum CategoryApi {
|
||||
case getCategoryList(creatorId: Int)
|
||||
}
|
||||
|
||||
extension CategoryApi: TargetType {
|
||||
var baseURL: URL {
|
||||
return URL(string: BASE_URL)!
|
||||
}
|
||||
|
||||
var path: String {
|
||||
switch self {
|
||||
case .getCategoryList:
|
||||
return "/category"
|
||||
}
|
||||
}
|
||||
|
||||
var method: Moya.Method {
|
||||
switch self {
|
||||
case .getCategoryList:
|
||||
return .get
|
||||
}
|
||||
}
|
||||
|
||||
var task: Moya.Task {
|
||||
switch self {
|
||||
case .getCategoryList(let creatorId):
|
||||
let parameters = ["creatorId": creatorId] as [String : Any]
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
|
||||
}
|
||||
}
|
||||
|
||||
var headers: [String : String]? {
|
||||
return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// ContentListCategoryView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2/7/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentListCategoryView: View {
|
||||
let categoryList: [GetCategoryListResponse]
|
||||
let selectCategory: (Int) -> Void
|
||||
|
||||
@Binding var selectedCategory: String
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: 8) {
|
||||
ForEach(0..<categoryList.count, id: \.self) { index in
|
||||
let category = categoryList[index]
|
||||
Text(category.category)
|
||||
.font(.custom(Font.medium.rawValue, size: 14.7))
|
||||
.foregroundColor(Color(hex: selectedCategory == category.category ? "3bb9f1" : "777777"))
|
||||
.padding(.horizontal, 13.3)
|
||||
.padding(.vertical, 9.3)
|
||||
.border(
|
||||
Color(hex: selectedCategory == category.category ? "3bb9f1" : "eeeeee"),
|
||||
width: 0.5
|
||||
)
|
||||
.cornerRadius(16.7)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: CGFloat(16.7))
|
||||
.stroke(lineWidth: 0.5)
|
||||
.foregroundColor(Color(hex: selectedCategory == category.category ? "3bb9f1" : "eeeeee"))
|
||||
)
|
||||
.onTapGesture {
|
||||
if selectedCategory != category.category {
|
||||
selectedCategory = category.category
|
||||
selectCategory(category.categoryId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
||||
ContentListCategoryView(
|
||||
categoryList: [
|
||||
GetCategoryListResponse(categoryId: 0, category: "전체"),
|
||||
GetCategoryListResponse(categoryId: 1, category: "test"),
|
||||
GetCategoryListResponse(categoryId: 0, category: "test2")
|
||||
],
|
||||
selectCategory: { _ in },
|
||||
selectedCategory: .constant("전체")
|
||||
)
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// GetCategoryListResponse.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2/7/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetCategoryListResponse: Decodable {
|
||||
let categoryId: Int
|
||||
let category: String
|
||||
}
|
Reference in New Issue
Block a user