Skip to content

Commit

Permalink
[feat] #157 링크팝업 핸들링 변경사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeKim98 committed Nov 30, 2024
1 parent c4878b6 commit 9f85b99
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 24 deletions.
32 changes: 28 additions & 4 deletions Projects/App/Sources/MainTab/MainTabFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public struct MainTabFeature {
@Presents var contentDetail: ContentDetailFeature.State?
@Shared(.inMemory("SelectCategory")) var categoryId: Int?
@Shared(.inMemory("PushTapped")) var isPushTapped: Bool = false
var savedContentId: Int?

public init() {
self.pokit = .init()
Expand All @@ -65,7 +66,7 @@ public struct MainTabFeature {
public enum View: Equatable {
case addButtonTapped
case addSheetTypeSelected(TabAddSheetType)
case linkCopyButtonTapped
case 링크팝업_버튼_눌렀을때
case onAppear
case onOpenURL(url: URL)
case 경고_확인버튼_클릭
Expand All @@ -76,6 +77,7 @@ public struct MainTabFeature {
case 공유포킷_이동(sharedCategory: CategorySharing.SharedCategory)
case 경고_띄움(BaseError)
case errorSheetPresented(Bool)
case 링크팝업_활성화(PokitLinkPopup.PopupType)
}
public enum AsyncAction: Equatable {
case 공유받은_카테고리_조회(categoryId: Int)
Expand All @@ -94,6 +96,10 @@ public struct MainTabFeature {
/// - Reducer Core
private func core(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case .binding(\.linkPopup):
guard state.linkPopup == nil else { return .none }
state.savedContentId = nil
return .none
case .binding:
return .none
case let .pushAlertTapped(isTapped):
Expand Down Expand Up @@ -157,9 +163,8 @@ private extension MainTabFeature {
case .포킷추가: return .send(.delegate(.포킷추가하기))
}

case .linkCopyButtonTapped:
state.linkPopup = nil
return .run { send in await send(.delegate(.링크추가하기)) }
case .링크팝업_버튼_눌렀을때:
return linkPopupButtonTapped(state: &state)

case .onAppear:
if state.isPushTapped {
Expand Down Expand Up @@ -213,6 +218,10 @@ private extension MainTabFeature {
case let .errorSheetPresented(isPresented):
state.isErrorSheetPresented = isPresented
return .none

case let .링크팝업_활성화(type):
state.linkPopup = type
return .none

default: return .none
}
Expand Down Expand Up @@ -242,4 +251,19 @@ private extension MainTabFeature {
func handleDelegateAction(_ action: Action.DelegateAction, state: inout State) -> Effect<Action> {
return .none
}

func linkPopupButtonTapped(state: inout State) -> Effect<Action> {
switch state.linkPopup {
case .link:
state.linkPopup = nil
return .send(.delegate(.링크추가하기))
case .success:
state.linkPopup = nil
state.contentDetail = .init(contentId: state.savedContentId)
state.savedContentId = nil
return .none
case .error, .text, .warning, .none:
return .none
}
}
}
4 changes: 2 additions & 2 deletions Projects/App/Sources/MainTab/MainTabFeatureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public extension MainTabView {
if self.store.linkPopup != nil {
PokitLinkPopup(
type: $store.linkPopup,
action: { send(.linkCopyButtonTapped) }
action: { send(.링크팝업_버튼_눌렀을때, animation: .pokitSpring) }
)
}
}
Expand All @@ -95,7 +95,7 @@ private extension MainTabView {
if store.linkPopup != nil {
PokitLinkPopup(
type: $store.linkPopup,
action: { send(.linkCopyButtonTapped) }
action: { send(.링크팝업_버튼_눌렀을때, animation: .pokitSpring) }
)
.padding(.bottom, 20)
}
Expand Down
10 changes: 7 additions & 3 deletions Projects/App/Sources/MainTab/MainTabPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ public extension MainTabFeature {
return .none

/// - 링크추가 및 수정에서 저장하기 눌렀을 때
case let .path(.element(stackElementId, action: .링크추가및수정(.delegate(.저장하기_완료)))):
case let .path(.element(stackElementId, action: .링크추가및수정(.delegate(.저장하기_완료(contentId))))):
state.savedContentId = contentId
state.path.removeLast()
switch state.path.last {
case .검색:
return .send(.path(.element(id: stackElementId, action: .검색(.delegate(.컨텐츠_검색)))))
return .merge(
.send(.path(.element(id: stackElementId, action: .검색(.delegate(.컨텐츠_검색))))),
.send(.inner(.링크팝업_활성화(.success(title: "링크 저장 완료"))), animation: .pokitSpring)
)
default:
return .none
return .send(.inner(.링크팝업_활성화(.success(title: "링크 저장 완료"))), animation: .pokitSpring)
}
/// - 각 화면에서 링크 복사 감지했을 때 (링크 추가 및 수정 화면 제외)
case let .path(.element(_, action: .알림함(.delegate(.linkCopyDetected(url))))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public struct ContentSettingFeature {
case 뷰가_나타났을때
case 저장_버튼_눌렀을때
case 포킷추가_버튼_눌렀을때
case 링크복사_버튼_눌렀을때
case 링크팝업_버튼_눌렀을때
case 링크지우기_버튼_눌렀을때
case 제목지우기_버튼_눌렀을때
case 뒤로가기_버튼_눌렀을때
Expand All @@ -111,6 +111,7 @@ public struct ContentSettingFeature {
case 카테고리_상세_조회_API_반영(category: BaseCategory)
case 카테고리_목록_조회_API_반영(categoryList: BaseCategoryListInquiry)
case 선택한_포킷_인메모리_삭제
case 링크팝업_활성화(PokitLinkPopup.PopupType)
}

public enum AsyncAction: Equatable {
Expand All @@ -125,7 +126,7 @@ public struct ContentSettingFeature {
public enum ScopeAction: Equatable { case 없음 }

public enum DelegateAction: Equatable {
case 저장하기_완료
case 저장하기_완료(contentId: Int)
case 포킷추가하기
case dismiss
}
Expand Down Expand Up @@ -200,6 +201,7 @@ private extension ContentSettingFeature {
if state.domain.title == "제목을 입력해주세요" {
state.domain.title = state.title
}
state.saveIsLoading = true

return isEdit
? .send(.async(.컨텐츠_수정_API))
Expand All @@ -216,7 +218,8 @@ private extension ContentSettingFeature {
return state.isShareExtension
? .send(.delegate(.dismiss))
: .run { _ in await dismiss() }
case .링크복사_버튼_눌렀을때:
case .링크팝업_버튼_눌렀을때:
guard case .link = state.linkPopup else { return .none }
return .send(.inner(.링크복사_반영(state.link)))
case .링크지우기_버튼_눌렀을때:
state.domain.data = ""
Expand Down Expand Up @@ -325,6 +328,10 @@ private extension ContentSettingFeature {
case .선택한_포킷_인메모리_삭제:
state.selectedPokit = nil
return .none
case let .링크팝업_활성화(type):
state.linkPopup = type
state.saveIsLoading = false
return .none
}
}

Expand Down Expand Up @@ -372,11 +379,20 @@ private extension ContentSettingFeature {
alertYn: state.domain.alertYn.rawValue,
thumbNail: state.domain.thumbNail
)
return .concatenate(
contentEdit(request: request, contentId: contentId),
.send(.inner(.선택한_포킷_인메모리_삭제)),
.send(.delegate(.저장하기_완료))
)
return .run { send in
let _ = try await contentClient.컨텐츠_수정(
"\(contentId)",
request
)
await send(.inner(.선택한_포킷_인메모리_삭제))
await send(.delegate(.저장하기_완료(contentId: contentId)))
} catch: { error, send in
guard let errorResponse = error as? ErrorResponse else { return }
await send(
.inner(.링크팝업_활성화(.error(title: errorResponse.message))),
animation: .pokitSpring
)
}
case .컨텐츠_추가_API:
guard let categoryId = state.selectedPokit?.id else {
return .none
Expand All @@ -389,11 +405,17 @@ private extension ContentSettingFeature {
alertYn: state.domain.alertYn.rawValue,
thumbNail: state.domain.thumbNail
)
return .concatenate(
.run { _ in let _ = try await contentClient.컨텐츠_추가(request) },
.send(.inner(.선택한_포킷_인메모리_삭제)),
.send(.delegate(.저장하기_완료))
)
return .run { send in
let content = try await contentClient.컨텐츠_추가(request)
await send(.inner(.선택한_포킷_인메모리_삭제))
await send(.delegate(.저장하기_완료(contentId: content.contentId)))
} catch: { error, send in
guard let errorResponse = error as? ErrorResponse else { return }
await send(
.inner(.링크팝업_활성화(.error(title: errorResponse.message))),
animation: .pokitSpring
)
}
case .클립보드_감지:
return .run { send in
for await _ in self.pasteboard.changes() {
Expand All @@ -420,6 +442,12 @@ private extension ContentSettingFeature {
"\(contentId)",
request
)
} catch: { error, send in
guard let errorResponse = error as? ErrorResponse else { return }
await send(
.inner(.링크팝업_활성화(.error(title: errorResponse.message))),
animation: .pokitSpring
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public extension ContentSettingView {
if store.linkPopup != nil {
PokitLinkPopup(
type: $store.linkPopup,
action: { send(.링크복사_버튼_눌렀을때, animation: .pokitSpring) }
action: { send(.링크팝업_버튼_눌렀을때, animation: .pokitSpring) }
)
.animation(.pokitSpring, value: store.linkPopup)
}
}
.pokitMaxWidth()
Expand Down

0 comments on commit 9f85b99

Please sign in to comment.