크리에이터 채널 페이지 추가
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// CreatorNoticeWriteViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class CreatorNoticeWriteViewModel: ObservableObject {
|
||||
let repository = ExplorerRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var isLoading = false
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
|
||||
@Published var writeNotice = ""
|
||||
|
||||
var placeholder = "공지사항을 입력해 주세요"
|
||||
|
||||
func writeCreatorNotice() {
|
||||
isLoading = true
|
||||
|
||||
repository.writeCreatorNotice(notice: writeNotice.trimmingCharacters(in: .whitespacesAndNewlines) != placeholder ? writeNotice : "")
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { response in
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
|
||||
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
|
||||
if decoded.success {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
AppState.shared.back()
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
|
||||
self.isLoading = false
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user