Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 모임일정과 관련된 모듈을 재구성하고 리팩토링 합니다. #216

Merged
merged 15 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public extension ModulePath {
case Friend
case Category
case Home
case Moim
case Onboarding
case Calendar
case PlaceSearch
case Calendar
case Archive

case GroupTab
case Gathering
case FriendInvite
case LocationSearch

public static let name: String = "Feature"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct MainTabCoordinator {

enum Action: BindableAction {
case binding(BindingAction<State>)
case home(HomeCoordinator.Action)
case moim(MoimCoordinator.Action)
case home(HomeCoordinator.Action)
case group(GroupTabCoordinator.Action)

case viewOnAppear
// 카테고리 리스트 response
Expand All @@ -30,12 +30,11 @@ struct MainTabCoordinator {

@ObservableState
struct State: Equatable {
static let intialState = State(currentTab: .home, home: .initialState, moim: .initialState)
static let intialState = State(currentTab: .home, home: .initialState, group: .initialState)

var currentTab: Tab
var home: HomeCoordinator.State
var moim: MoimCoordinator.State

var group: GroupTabCoordinator.State

@Shared(.inMemory(SharedKeys.categories.rawValue)) var categories: [NamoCategory] = []
}
Expand All @@ -48,8 +47,8 @@ struct MainTabCoordinator {
Scope(state: \.home, action: \.home) {
HomeCoordinator()
}
Scope(state: \.moim, action: \.moim) {
MoimCoordinator()
Scope(state: \.group, action: \.group) {
GroupTabCoordinator()
}
Reduce { state, action in
switch action {
Expand All @@ -63,7 +62,6 @@ struct MainTabCoordinator {
// TODO: 에러 핸들링
print(error.localizedDescription)
}

}

case .getAllCategoryResponse(let categories):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ struct MainTabCoordinatorView: View {
WithPerceptionTracking {
TabView(selection: $store.currentTab) {
HomeCoordinatorView(store: store.scope(state: \.home, action: \.home))
.tag(Tab.home)
.tag(Tab.home)

MoimCoordinatorView(store: store.scope(state: \.moim, action: \.moim))
GroupTabCoordinatorView(store: store.scope(state: \.group, action: \.group))
.tag(Tab.group)
}
.overlay(alignment: .bottom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct AppCoordinator {

// mainTab 이동 - 로그인 체크 결과 goToMainScreen 시
case .router(.routeAction(_, action: .onboarding(.goToMainScreen))):
state.routes = [.root(.mainTab(.init(currentTab: .home, home: .initialState, moim: .initialState)), embedInNavigationView: true)]
state.routes = [.root(.mainTab(.init(currentTab: .home, home: .initialState, group: .initialState)), embedInNavigationView: true)]
return .none

// Notification 에러 핸들링
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by 정현우 on 10/24/24.
//

public struct Friend: Equatable {
public struct Friend: Equatable, Identifiable, Hashable {
public let memberId: Int
public var favoriteFriend: Bool
public let profileImage: String?
Expand All @@ -15,7 +15,7 @@ public struct Friend: Equatable {
public let bio: String
public let birthday: String
public let favoriteColorId: Int
public var id: Int { memberId }
public init(
memberId: Int,
favoriteFriend: Bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Foundation

import CoreNetwork
import DomainFriend


import SharedUtil

public extension MoimScheduleListResponseDTO {
Expand Down Expand Up @@ -76,14 +77,3 @@ public extension ParticipantsDto {
isOwner: isOwner)
}
}

public extension Friend {
func toParticipant() -> Participant {
.init(participantId: 0,
userId: memberId,
isGuest: false,
nickname: nickname,
colorId: favoriteColorId,
isOwner: false)
}
}
6 changes: 4 additions & 2 deletions Namo_SwiftUI/Projects/Domain/Moim/Sources/MoimUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
//

import Foundation
import ComposableArchitecture
import DomainMoimInterface

import CoreNetwork
import DomainMoimInterface
import SharedUtil

import ComposableArchitecture

// 모임 유즈케이스 구현체
extension MoimUseCase: DependencyKey {
public static let liveValue = MoimUseCase(
Expand Down
2 changes: 2 additions & 0 deletions Namo_SwiftUI/Projects/Domain/Sources/DomainExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
//

@_exported import DomainFriend
@_exported import DomainFriendInterface
@_exported import DomainCategory
@_exported import DomainSchedule
@_exported import DomainMoim
@_exported import DomainMoimInterface
@_exported import DomainAuth
@_exported import DomainAuthInterface
@_exported import DomainDiary
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import SwiftUI
import ComposableArchitecture
import SwiftUICalendar

import FeatureCalendar
import SharedUtil
import SharedDesignSystem
import FeatureCalendar


public struct ArchiveCalendarView: View {
@Perception.Bindable public var store: StoreOf<ArchiveCalendarStore>
Expand Down
Seokki-Kwon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// FriendInviteStore.swift
// FeatureFriendInvite
//
// Created by 권석기 on 11/21/24.
//

import Foundation

import Domain
import DomainFriendInterface

import ComposableArchitecture

public extension FriendInviteStore {
init() {
@Dependency(\.friendUseCase) var friendUseCase

let reducer: Reduce<State, Action> = Reduce { state, action in
switch action {
case .searchButtonTapped:
return .run { [state] send in
let response = try await friendUseCase.getFriends(page: 1, searchTerm: state.searchText)
await send(.searchResponse(response))
}
case let .searchResponse(response):
state.searchFriendList = IdentifiedArray(uniqueElements: response.friendList)
return .send(.loadFriendList)
case .loadFriendList:
let addedFriend = state.searchFriendList.filter { state.friendList.contains($0.memberId) }
state.addedFriendList.append(contentsOf: addedFriend)
return .none
case .toggleAddedFriendList:
state.showingFriendInvites.toggle()
return .none
case let .addFriend(friend):
guard !(state.addedFriendList.contains(where: { $0.memberId == friend.memberId })) else {
return .none
}
state.willAddFriendList.append(friend)
return .none
case .confirmAddFriend:
state.addedFriendList.append(contentsOf: state.willAddFriendList)
state.willAddFriendList.removeAll()
return .send(.updatedFriendList(state))
case let .removeFriend(memberId):
state.willAddFriendList.removeAll(where: {$0.id == memberId })
return .none
case .removeAllFriend:
state.willAddFriendList.removeAll()
return .none
default:
return .none
}
}

self.init(reducer: reducer)
}
}

Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
//
// FriendInviteStoreInterface.swift
// FeatureMoim
// FeatureFriendInvite
//
// Created by 권석기 on 11/3/24.
// Created by 권석기 on 11/21/24.
//

import Foundation

import DomainFriendInterface
import DomainFriend
import DomainFriendInterface

import ComposableArchitecture

/**
Reducer for FriendInvite(친구초대) Feature
*/
@Reducer
public struct FriendInviteStore {
private let reducer: Reduce<State, Action>
Expand All @@ -25,42 +22,38 @@ public struct FriendInviteStore {

@ObservableState
public struct State: Equatable {
public init() {}

/// 검색어
public var searchText = ""
public init(friendList: [Int] = []) {
self.friendList = friendList
}

/// 친구목록
public var friendList: [Friend] = []
internal let friendList: [Int]

/// 추가한 친구목록
public var addedFriend: [Friend] = []
public var searchText = ""
public var showingFriendInvites = false
public var searchFriendList: IdentifiedArrayOf<Friend> = []
public var addedFriendList: IdentifiedArrayOf<Friend> = []
public var willAddFriendList: IdentifiedArrayOf<Friend> = []
public var maxAvailableInvites: Int {
10 - addedFriendList.count
}
}

public enum Action: BindableAction {

/// 바인딩액션
case binding(BindingAction<State>)

/// 검색결과탭
case searchButtonTapped

/// 검색결과 응답
case searchResponse(FriendResponse)

/// 친구 추가
case backButtonTapped
case toggleAddedFriendList
case addFriend(Friend)

/// 초대친구 삭제
case confirmAddFriend
case addFriendConfirmButtonTapped
case updatedFriendList(FriendInviteStore.State)
case removeFriend(memberId: Int)

/// 뒤로가기
case backButtonTapped
case removeAllFriend
case loadFriendList
}

public var body: some ReducerOf<Self> {
BindingReducer()

reducer
}
}
Loading