Skip to content

Commit

Permalink
[2.0.0] 온보딩 상태에서 구독로직 (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgvv authored Apr 13, 2024
1 parent bd8491e commit 5edc3a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions KuringApp/KuringApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
Expand Down
7 changes: 3 additions & 4 deletions package-kuring/Sources/Caches/Dependency/Departments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,19 @@ extension Departments {
var departments = Self.selections

if departments.isEmpty {
// 학과 추가시 학과가 0개인 경우에는 current를 처음 학과로 설정
// 학과 추가시 학과가 0개인 경우에는 current를 처음 학과로 설정
current = departments.first
}

departments.append(noticeProvider)
Self.selections = departments

}, remove: { id in
var departments = Self.selections

Self.selections.removeAll { $0.id == id }

if Self.current?.id == id {
// 삭제한 학과가 현재 선택한 학과일 경우 새로운 학과 정보로 업데이트
// 삭제한 학과가 현재 선택한 학과일 경우 새로운 학과 정보로 업데이트
Self.current = nil
Self.current = Self.selections.first
}
Expand Down
9 changes: 8 additions & 1 deletion package-kuring/Sources/Caches/Dependency/Subscriptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation
import Dependencies

public struct KuringSubscriptions {
/// 구독한 공지 리스트에 단일 객체 추가
public var add: (_ noticeProvider: NoticeProvider) -> Void
/// 구독한 공지 리스트 업데이트
public var update: (_ noticeProvider: Set<NoticeProvider>) -> Void
/// 구독한 모든 공지 카테고리
Expand All @@ -28,7 +30,12 @@ public struct KuringSubscriptions {

extension KuringSubscriptions {
public static let `default` = Self(
update: { noticeProviders in
add: { noticeProvider in
var subscriptions = Self.subscriptions
subscriptions.insert(noticeProvider)
Self.subscriptions = subscriptions

}, update: { noticeProviders in
Self.subscriptions = noticeProviders

}, getAll: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import Caches
import Models
import SwiftUI
import ColorSet
import Networks
import Dependencies

struct MyDepartmentSelector: View {
@Environment(\.dismiss) private var dismiss
@State private var currentStep: Step.ID = .searchDepartment.id
@State private var selectedDepartment: NoticeProvider? = nil

@Dependency(\.kuringLink) var kuringLink
@Dependency(\.departments) var departments
@Dependency(\.subscriptions) var subscriptions

var body: some View {
VStack {
// 메인 영역
Expand All @@ -35,9 +40,17 @@ struct MyDepartmentSelector: View {
if currentStep == .selectDepartment {
Button(StringSet.button_complete.rawValue) {
if let selectedDepartment {
@Dependency(\.departments) var departments
// 로컬 저장소에 학과 추가
NoticeProvider.addedDepartments.append(selectedDepartment)
departments.add(selectedDepartment)

Task(priority: .background) {
// 추가한 학과 구독, 단 api 성공시에만 구독정보 저장
do {
try await kuringLink.subscribeDepartments([selectedDepartment.hostPrefix])
subscriptions.add(selectedDepartment)
}
}
}
currentStep = .addedDepartment.id
}
Expand Down

0 comments on commit 5edc3a9

Please sign in to comment.