diff --git a/SodaLive/Sources/App/AppStep.swift b/SodaLive/Sources/App/AppStep.swift index 0643c4e..84dce26 100644 --- a/SodaLive/Sources/App/AppStep.swift +++ b/SodaLive/Sources/App/AppStep.swift @@ -145,4 +145,6 @@ enum AppStep { case contentMain(startTab: ContentMainTab) case completedSeriesAll + + case newAlarmContentAll } diff --git a/SodaLive/Sources/Content/All/ContentNewAllView.swift b/SodaLive/Sources/Content/All/ContentNewAllView.swift index 94f9dd6..a92b506 100644 --- a/SodaLive/Sources/Content/All/ContentNewAllView.swift +++ b/SodaLive/Sources/Content/All/ContentNewAllView.swift @@ -38,7 +38,7 @@ struct ContentNewAllView: View { }, selectedTheme: $viewModel.selectedTheme ) - .padding(.horizontal, 13.3) + .padding(.horizontal, 20) HStack(spacing: 0) { Text("전체") diff --git a/SodaLive/Sources/Content/Main/V2/Alarm/All/ContentMainAlarmAllView.swift b/SodaLive/Sources/Content/Main/V2/Alarm/All/ContentMainAlarmAllView.swift new file mode 100644 index 0000000..ce62211 --- /dev/null +++ b/SodaLive/Sources/Content/Main/V2/Alarm/All/ContentMainAlarmAllView.swift @@ -0,0 +1,85 @@ +// +// ContentMainAlarmAllView.swift +// SodaLive +// +// Created by klaus on 2/22/25. +// + +import SwiftUI + +struct ContentMainAlarmAllView: View { + + @StateObject var viewModel = ContentMainAlarmAllViewModel() + + let columns = [ + GridItem(.flexible(), alignment: .top), + GridItem(.flexible(), alignment: .top), + GridItem(.flexible(), alignment: .top) + ] + + var body: some View { + NavigationView { + BaseView(isLoading: $viewModel.isLoading) { + VStack(alignment: .leading, spacing: 13.3) { + DetailNavigationBar(title: "새로운 알람") + + Text("※ 최근 2주간 등록된 새로운 알람 입니다.") + .font(.custom(Font.medium.rawValue, size: 14.7)) + .foregroundColor(.graybb) + .padding(.horizontal, 13.3) + .padding(.vertical, 8) + .frame(width: screenSize().width, alignment: .leading) + .background(Color.gray22) + + ContentMainNewContentThemeView( + themes: viewModel.themeList, + selectTheme: { + viewModel.selectedTheme = $0 + }, + selectedTheme: $viewModel.selectedTheme + ) + .padding(.horizontal, 20) + + HStack(spacing: 0) { + Text("전체") + .font(.custom(Font.medium.rawValue, size: 13.3)) + .foregroundColor(Color(hex: "e2e2e2")) + + Text("\(viewModel.totalCount)") + .font(.custom(Font.medium.rawValue, size: 13.3)) + .foregroundColor(Color(hex: "ff5c49")) + .padding(.leading, 8) + + Text("개") + .font(.custom(Font.medium.rawValue, size: 13.3)) + .foregroundColor(Color(hex: "e2e2e2")) + .padding(.leading, 2) + } + .padding(.horizontal, 13.3) + + ScrollView(.vertical, showsIndicators: false) { + LazyVGrid(columns: columns, spacing: 32) { + ForEach(0..() + + @Published var errorMessage = "" + @Published var isShowPopup = false + @Published var isLoading = false + + @Published var themeList = ["전체", "모닝콜", "슬립콜", "알람"] + @Published var newContentList = [GetAudioContentMainItem]() + + @Published var selectedTheme = "전체" { + didSet { + page = 1 + isLast = false + getContentMainAlarmAll() + } + } + @Published var totalCount = 0 + + var page = 1 + var isLast = false + private let pageSize = 20 + + func getContentMainAlarmAll() { + if (!isLast && !isLoading) { + isLoading = true + + repository.getContentMainAlarmAll( + theme: selectedTheme == "전체" ? "" : selectedTheme, + page: page, + size: pageSize + ) + .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.self, from: responseData) + self.isLoading = false + + if let data = decoded.data, decoded.success { + if page == 1 { + newContentList.removeAll() + } + + self.totalCount = data.totalCount + + if !data.items.isEmpty { + page += 1 + self.newContentList.append(contentsOf: data.items) + } else { + isLast = true + } + } else { + if let message = decoded.message { + self.errorMessage = message + } else { + self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." + } + + self.isShowPopup = true + } + } catch { + self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." + self.isShowPopup = true + self.isLoading = false + } + } + .store(in: &subscription) + } else { + isLoading = false + } + } +} diff --git a/SodaLive/Sources/Content/Main/V2/Alarm/ContentMainTabAlarmView.swift b/SodaLive/Sources/Content/Main/V2/Alarm/ContentMainTabAlarmView.swift index dc30c6a..de686b2 100644 --- a/SodaLive/Sources/Content/Main/V2/Alarm/ContentMainTabAlarmView.swift +++ b/SodaLive/Sources/Content/Main/V2/Alarm/ContentMainTabAlarmView.swift @@ -23,7 +23,10 @@ struct ContentMainTabAlarmView: View { if !viewModel.alarmThemeList.isEmpty { ContentMainNewContentViewV2( title: "새로운 알람", - onClickMore: {}, + onClickMore: { + AppState.shared + .setAppStep(step: .newAlarmContentAll) + }, themeList: viewModel.alarmThemeList, contentList: viewModel.newAlarmContentList ) { diff --git a/SodaLive/Sources/ContentView.swift b/SodaLive/Sources/ContentView.swift index 2d41142..64d2fd8 100644 --- a/SodaLive/Sources/ContentView.swift +++ b/SodaLive/Sources/ContentView.swift @@ -221,6 +221,9 @@ struct ContentView: View { case .completedSeriesAll: CompletedSeriesView() + case .newAlarmContentAll: + ContentMainAlarmAllView() + default: EmptyView() .frame(width: 0, height: 0, alignment: .topLeading)