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

Remind 리펙토링 #130

Merged
merged 14 commits into from
Sep 29, 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
2 changes: 1 addition & 1 deletion Projects/App/Resources/Pokit-info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions Projects/App/Sources/MainTab/MainTabFeatureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ private extension MainTabView {
PokitHeaderItems(placement: .trailing) {
PokitToolbarButton(
.icon(.search),
action: { store.send(.remind(.view(.searchButtonTapped))) }
action: { store.send(.remind(.view(.검색_버튼_눌렀을때))) }
)
PokitToolbarButton(
.icon(.bell),
action: { store.send(.remind(.view(.bellButtonTapped))) }
action: { store.send(.remind(.view(.알림_버튼_눌렀을때))) }
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Projects/App/Sources/MainTab/MainTabPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public extension MainTabFeature {
case .pokit:
return .send(.pokit(.delegate(.미분류_카테고리_컨텐츠_조회)))
case .remind:
return .send(.remind(.delegate(.컨텐츠목록_조회)))
return .send(.remind(.delegate(.컨텐츠_상세보기_delegate_위임)))
}
}
switch lastPath {
Expand Down
131 changes: 66 additions & 65 deletions Projects/Feature/FeatureRemind/Sources/Remind/RemindFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// Created by 김도형 on 7/12/24.

import SwiftUI

import ComposableArchitecture
import Domain
import CoreKit
Expand Down Expand Up @@ -65,35 +67,36 @@ public struct RemindFeature {

public enum View: Equatable, BindableAction {
case binding(BindingAction<State>)
/// - Button Tapped
case bellButtonTapped
case searchButtonTapped
case linkCardTapped(content: BaseContentItem)
case kebabButtonTapped(content: BaseContentItem)
case unreadNavigationLinkTapped
case favoriteNavigationLinkTapped
case bottomSheetButtonTapped(
case bottomSheet(
delegate: PokitBottomSheet.Delegate,
content: BaseContentItem
)
case deleteAlertConfirmTapped(content: BaseContentItem)

/// - Button Tapped
case 알림_버튼_눌렀을때
case 검색_버튼_눌렀을때
case 컨텐츠_항목_눌렀을때(content: BaseContentItem)
case 컨텐츠_항목_케밥_버튼_눌렀을때(content: BaseContentItem)
case 안읽음_목록_버튼_눌렀을때
case 즐겨찾기_목록_버튼_눌렀을때
case 링크_삭제_눌렀을때(content: BaseContentItem)

case 링크_공유_완료

case remindViewOnAppeared
case 뷰가_나타났을때
}
public enum InnerAction: Equatable {
case dismissBottomSheet
case 오늘의_리마인드_조회(contents: [BaseContentItem])
case 읽지않음_컨텐츠_조회(contentList: BaseContentListInquiry)
case 즐겨찾기_링크모음_조회(contentList: BaseContentListInquiry)
case 컨텐츠_삭제_반영(id: Int)
case 바텀시트_해제
case 오늘의_리마인드_조회_API_반영(contents: [BaseContentItem])
case 읽지않음_컨텐츠_조회_API_반영(contentList: BaseContentListInquiry)
case 즐겨찾기_링크모음_조회_API_반영(contentList: BaseContentListInquiry)
case 컨텐츠_삭제_API_반영(id: Int)
}
public enum AsyncAction: Equatable {
case 오늘의_리마인드_조회
case 읽지않음_컨텐츠_조회
case 즐겨찾기_링크모음_조회
case 컨텐츠_삭제(id: Int)
case 오늘의_리마인드_조회_API
case 읽지않음_컨텐츠_조회_API
case 즐겨찾기_링크모음_조회_API
case 컨텐츠_삭제_API(id: Int)
}
public enum ScopeAction: Equatable {
case bottomSheet(
Expand All @@ -108,7 +111,7 @@ public struct RemindFeature {
case 링크수정(id: Int)
case 링크목록_안읽음
case 링크목록_즐겨찾기
case 컨텐츠목록_조회
case 컨텐츠_상세보기_delegate_위임
}
}
/// initiallizer
Expand Down Expand Up @@ -144,37 +147,31 @@ private extension RemindFeature {
/// - View Effect
func handleViewAction(_ action: Action.View, state: inout State) -> Effect<Action> {
switch action {
case .bellButtonTapped:
return .run { send in await send(.delegate(.alertButtonTapped)) }
case .searchButtonTapped:
return .run { send in await send(.delegate(.searchButtonTapped)) }
case .favoriteNavigationLinkTapped:
case .binding:
return .none
case .bottomSheet(let delegate, let content):
return .run { send in
await send(.inner(.바텀시트_해제))
await send(.scope(.bottomSheet(delegate: delegate, content: content)))
}
case .알림_버튼_눌렀을때:
return .send(.delegate(.alertButtonTapped))
case .검색_버튼_눌렀을때:
return .send(.delegate(.searchButtonTapped))
case .즐겨찾기_목록_버튼_눌렀을때:
return .send(.delegate(.링크목록_즐겨찾기))
case .unreadNavigationLinkTapped:
case .안읽음_목록_버튼_눌렀을때:
return .send(.delegate(.링크목록_안읽음))
case .kebabButtonTapped(let content):
case .컨텐츠_항목_케밥_버튼_눌렀을때(let content):
state.bottomSheetItem = content
return .none
case .linkCardTapped(let content):
case .컨텐츠_항목_눌렀을때(let content):
return .send(.delegate(.링크상세(content: content)))
case .bottomSheetButtonTapped(let delegate, let content):
return .run { send in
await send(.inner(.dismissBottomSheet))
await send(.scope(.bottomSheet(delegate: delegate, content: content)))
}
case .deleteAlertConfirmTapped:
case .링크_삭제_눌렀을때:
guard let id = state.alertItem?.id else { return .none }
return .run { [id] send in
await send(.async(.컨텐츠_삭제(id: id)))
}
case .binding:
return .none
case .remindViewOnAppeared:
return .run { send in
await send(.async(.오늘의_리마인드_조회), animation: .pokitDissolve)
await send(.async(.읽지않음_컨텐츠_조회), animation: .pokitDissolve)
await send(.async(.즐겨찾기_링크모음_조회), animation: .pokitDissolve)
}
return .send(.async(.컨텐츠_삭제_API(id: id)))
case .뷰가_나타났을때:
return allContentFetch(animation: .pokitDissolve)
case .링크_공유_완료:
state.shareSheetItem = nil
return .none
Expand All @@ -183,19 +180,19 @@ private extension RemindFeature {
/// - Inner Effect
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> {
switch action {
case .dismissBottomSheet:
case .바텀시트_해제:
state.bottomSheetItem = nil
return .none
case .오늘의_리마인드_조회(contents: let contents):
case .오늘의_리마인드_조회_API_반영(contents: let contents):
state.domain.recommendedList = contents
return .none
case .읽지않음_컨텐츠_조회(contentList: let contentList):
case .읽지않음_컨텐츠_조회_API_반영(contentList: let contentList):
state.domain.unreadList = contentList
return .none
case .즐겨찾기_링크모음_조회(contentList: let contentList):
case .즐겨찾기_링크모음_조회_API_반영(contentList: let contentList):
state.domain.favoriteList = contentList
return .none
case .컨텐츠_삭제_반영(id: let contentId):
case .컨텐츠_삭제_API_반영(id: let contentId):
state.alertItem = nil
state.domain.recommendedList?.removeAll { $0.id == contentId }
state.domain.unreadList.data?.removeAll { $0.id == contentId }
Expand All @@ -206,12 +203,12 @@ private extension RemindFeature {
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
switch action {
case .오늘의_리마인드_조회:
case .오늘의_리마인드_조회_API:
return .run { send in
let contents = try await remindClient.오늘의_리마인드_조회().map { $0.toDomain() }
await send(.inner(.오늘의_리마인드_조회(contents: contents)), animation: .pokitDissolve)
await send(.inner(.오늘의_리마인드_조회_API_반영(contents: contents)), animation: .pokitDissolve)
}
case .읽지않음_컨텐츠_조회:
case .읽지않음_컨텐츠_조회_API:
return .run { [pageable = state.domain.unreadListPageable] send in
let contentList = try await remindClient.읽지않음_컨텐츠_조회(
BasePageableRequest(
Expand All @@ -220,9 +217,9 @@ private extension RemindFeature {
sort: pageable.sort
)
).toDomain()
await send(.inner(.읽지않음_컨텐츠_조회(contentList: contentList)), animation: .pokitDissolve)
await send(.inner(.읽지않음_컨텐츠_조회_API_반영(contentList: contentList)), animation: .pokitDissolve)
}
case .즐겨찾기_링크모음_조회:
case .즐겨찾기_링크모음_조회_API:
return .run { [pageable = state.domain.favoriteListPageable] send in
let contentList = try await remindClient.즐겨찾기_링크모음_조회(
BasePageableRequest(
Expand All @@ -231,12 +228,12 @@ private extension RemindFeature {
sort: pageable.sort
)
).toDomain()
await send(.inner(.즐겨찾기_링크모음_조회(contentList: contentList)), animation: .pokitDissolve)
await send(.inner(.즐겨찾기_링크모음_조회_API_반영(contentList: contentList)), animation: .pokitDissolve)
}
case .컨텐츠_삭제(id: let id):
return .run { [id] send in
case .컨텐츠_삭제_API(id: let id):
return .run { send in
let _ = try await contentClient.컨텐츠_삭제("\(id)")
await send(.inner(.컨텐츠_삭제_반영(id: id)), animation: .pokitSpring)
await send(.inner(.컨텐츠_삭제_API_반영(id: id)), animation: .pokitSpring)
}
}
}
Expand All @@ -262,13 +259,17 @@ private extension RemindFeature {
/// - Delegate Effect
func handleDelegateAction(_ action: Action.DelegateAction, state: inout State) -> Effect<Action> {
switch action {
case .컨텐츠목록_조회:
return .run { send in
await send(.async(.오늘의_리마인드_조회))
await send(.async(.읽지않음_컨텐츠_조회))
await send(.async(.즐겨찾기_링크모음_조회))
}
case .컨텐츠_상세보기_delegate_위임:
return allContentFetch()
default: return .none
}
}

func allContentFetch(animation: Animation? = nil) -> Effect<Action> {
return .run { send in
await send(.async(.오늘의_리마인드_조회_API), animation: animation)
await send(.async(.읽지않음_컨텐츠_조회_API), animation: animation)
await send(.async(.즐겨찾기_링크모음_조회_API), animation: animation)
}
}
}
22 changes: 11 additions & 11 deletions Projects/Feature/FeatureRemind/Sources/Remind/RemindView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public extension RemindView {
PokitBottomSheet(
items: [.share, .edit, .delete],
height: 224
) { send(.bottomSheetButtonTapped(delegate: $0, content: content)) }
) { send(.bottomSheet(delegate: $0, content: content)) }
}
.sheet(item: $store.shareSheetItem) { content in
if let shareURL = URL(string: content.data) {
Expand All @@ -51,9 +51,9 @@ public extension RemindView {
"링크를 정말 삭제하시겠습니까?",
message: "함께 저장한 모든 정보가 삭제되며, \n복구하실 수 없습니다.",
confirmText: "삭제"
) { send(.deleteAlertConfirmTapped(content: content)) }
) { send(.링크_삭제_눌렀을때(content: content)) }
}
.task { await send(.remindViewOnAppeared, animation: .pokitDissolve).finish() }
.task { await send(.뷰가_나타났을때, animation: .pokitDissolve).finish() }
}
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ extension RemindView {

@ViewBuilder
private func recommendedContentCell(content: BaseContentItem) -> some View {
Button(action: { send(.linkCardTapped(content: content)) }) {
Button(action: { send(.컨텐츠_항목_눌렀을때(content: content)) }) {
recommendedContentCellLabel(content: content)
}

Expand Down Expand Up @@ -186,7 +186,7 @@ extension RemindView {
Spacer()

kebabButton {
send(.kebabButtonTapped(content: content))
send(.컨텐츠_항목_케밥_버튼_눌렀을때(content: content))
}
.foregroundStyle(.pokit(.icon(.inverseWh)))
.zIndex(1)
Expand Down Expand Up @@ -243,7 +243,7 @@ extension RemindView {
VStack(spacing: 0) {
VStack(spacing: 0) {
listNavigationLink("한번도 읽지 않았어요") {
send(.unreadNavigationLinkTapped)
send(.안읽음_목록_버튼_눌렀을때)
}
.padding(.bottom, 16)
}
Expand All @@ -254,8 +254,8 @@ extension RemindView {

PokitLinkCard(
link: content,
action: { send(.linkCardTapped(content: content)) },
kebabAction: { send(.kebabButtonTapped(content: content)) }
action: { send(.컨텐츠_항목_눌렀을때(content: content)) },
kebabAction: { send(.컨텐츠_항목_케밥_버튼_눌렀을때(content: content)) }
)
.divider(isFirst: isFirst, isLast: isLast)
}
Expand All @@ -270,7 +270,7 @@ extension RemindView {
) -> some View {
VStack(spacing: 0) {
listNavigationLink("즐겨찾기 링크만 모았어요") {
send(.favoriteNavigationLinkTapped)
send(.즐겨찾기_목록_버튼_눌렀을때)
}
.padding(.bottom, 16)

Expand All @@ -288,8 +288,8 @@ extension RemindView {

PokitLinkCard(
link: content,
action: { send(.linkCardTapped(content: content)) },
kebabAction: { send(.kebabButtonTapped(content: content)) }
action: { send(.컨텐츠_항목_눌렀을때(content: content)) },
kebabAction: { send(.컨텐츠_항목_케밥_버튼_눌렀을때(content: content)) }
)
.divider(isFirst: isFirst, isLast: isLast)
}
Expand Down