설정 페이지 추가
This commit is contained in:
19
SodaLive/Sources/Settings/Notice/GetNoticeResponse.swift
Normal file
19
SodaLive/Sources/Settings/Notice/GetNoticeResponse.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// GetNoticeResponse.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetNoticeResponse: Decodable {
|
||||
let totalCount: Int
|
||||
let noticeList: [NoticeItem]
|
||||
}
|
||||
|
||||
struct NoticeItem: Decodable, Hashable {
|
||||
let title: String
|
||||
let content: String
|
||||
let date: String
|
||||
}
|
45
SodaLive/Sources/Settings/Notice/NoticeApi.swift
Normal file
45
SodaLive/Sources/Settings/Notice/NoticeApi.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// NoticeApi.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Moya
|
||||
|
||||
enum NoticeApi {
|
||||
case getNotices
|
||||
}
|
||||
|
||||
extension NoticeApi: TargetType {
|
||||
var baseURL: URL {
|
||||
return URL(string: BASE_URL)!
|
||||
}
|
||||
|
||||
var path: String {
|
||||
switch self {
|
||||
case .getNotices:
|
||||
return "/notice"
|
||||
}
|
||||
}
|
||||
|
||||
var method: Moya.Method {
|
||||
return .get
|
||||
}
|
||||
|
||||
var task: Task {
|
||||
switch self {
|
||||
case .getNotices:
|
||||
let parameters = ["timezone": TimeZone.current.identifier] as [String: Any]
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
|
||||
}
|
||||
}
|
||||
|
||||
var headers: [String : String]? {
|
||||
switch self {
|
||||
default:
|
||||
return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
|
||||
}
|
||||
}
|
||||
}
|
57
SodaLive/Sources/Settings/Notice/NoticeDetailView.swift
Normal file
57
SodaLive/Sources/Settings/Notice/NoticeDetailView.swift
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// NoticeDetailView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import RichText
|
||||
|
||||
struct NoticeDetailView: View {
|
||||
|
||||
let notice: NoticeItem
|
||||
|
||||
var body: some View {
|
||||
BaseView {
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: "공지사항 상세")
|
||||
|
||||
VStack(alignment: .leading, spacing: 6.7) {
|
||||
Text(notice.title)
|
||||
.font(.custom(Font.medium.rawValue, size: 14.7))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
Text(notice.date)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "525252"))
|
||||
.padding(.horizontal, 13.3)
|
||||
}
|
||||
.padding(.horizontal, 13.3)
|
||||
.padding(.vertical, 21.7)
|
||||
.frame(width: screenSize().width - 26.7, alignment: .leading)
|
||||
.background(Color(hex: "222222"))
|
||||
.cornerRadius(6.7)
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
RichText(html: notice.content)
|
||||
.padding(.horizontal, 33.3)
|
||||
.padding(.vertical, 26.7)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NoticeDetailView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NoticeDetailView(
|
||||
notice: NoticeItem(
|
||||
title: "제목",
|
||||
content: "<h1>콘텐츠</h1>",
|
||||
date: "2022.03.03"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
82
SodaLive/Sources/Settings/Notice/NoticeListView.swift
Normal file
82
SodaLive/Sources/Settings/Notice/NoticeListView.swift
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// NoticeListView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import RichText
|
||||
|
||||
struct NoticeListView: View {
|
||||
@ObservedObject var viewModel = NoticeListViewModel()
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: "공지사항")
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(viewModel.notices, id: \.self) { notice in
|
||||
VStack(alignment: .leading, spacing: 6.7) {
|
||||
Spacer()
|
||||
|
||||
Text(notice.title)
|
||||
.font(.custom(Font.medium.rawValue, size: 14.7))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
Text(notice.date)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "525252"))
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
Spacer()
|
||||
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(Color(hex: "909090").opacity(0.5))
|
||||
}
|
||||
.padding(.horizontal, 13.3)
|
||||
.frame(width: screenSize().width, height: 80)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
AppState.shared.setAppStep(step: .noticeDetail(notice: notice))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 13.3)
|
||||
}
|
||||
}
|
||||
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
|
||||
GeometryReader { geo in
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(viewModel.errorMessage)
|
||||
.padding(.vertical, 13.3)
|
||||
.padding(.horizontal, 6.7)
|
||||
.frame(width: geo.size.width - 66.7, alignment: .center)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.background(Color(hex: "9970ff"))
|
||||
.foregroundColor(Color.white)
|
||||
.multilineTextAlignment(.leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(20)
|
||||
.padding(.top, 66.7)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.getNotices()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NoticeListView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NoticeListView()
|
||||
}
|
||||
}
|
59
SodaLive/Sources/Settings/Notice/NoticeListViewModel.swift
Normal file
59
SodaLive/Sources/Settings/Notice/NoticeListViewModel.swift
Normal file
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// NoticeListViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class NoticeListViewModel: ObservableObject {
|
||||
|
||||
private let repository = NoticeRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var notices = [NoticeItem]()
|
||||
|
||||
func getNotices() {
|
||||
isLoading = true
|
||||
|
||||
repository.getNotices()
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<GetNoticeResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.notices.append(contentsOf: data.noticeList)
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
21
SodaLive/Sources/Settings/Notice/NoticeRepository.swift
Normal file
21
SodaLive/Sources/Settings/Notice/NoticeRepository.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// NoticeRepository.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CombineMoya
|
||||
import Combine
|
||||
import Moya
|
||||
|
||||
final class NoticeRepository {
|
||||
|
||||
private let api = MoyaProvider<NoticeApi>()
|
||||
|
||||
func getNotices() -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.getNotices)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user