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

merge :: notice list UI #116

Merged
merged 18 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
4 changes: 2 additions & 2 deletions Projects/App/Sources/Application/DI/AppComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public extension AppComponent {
var applyComponent: ApplyComponent {
ApplyComponent(parent: self)
}
var noticeComponent: NoticeComponent {
NoticeComponent(parent: self)
var noticeComponent: NoticeListComponent {
kimdaehee0824 marked this conversation as resolved.
Show resolved Hide resolved
NoticeListComponent(parent: self)
}
var myPageComponent: MyPageComponent {
MyPageComponent(parent: self)
Expand Down
38 changes: 26 additions & 12 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ private class MainTabDependency2826cdb310ed0b17a725Provider: MainTabDependency {
var homeComponent: HomeComponent {
return appComponent.homeComponent
}
var applyComponent: ApplyComponent {
return appComponent.applyComponent
}
var noticeComponent: NoticeListComponent {
return appComponent.noticeComponent
}
var myPageComponent: MyPageComponent {
return appComponent.myPageComponent
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
Expand Down Expand Up @@ -296,16 +305,18 @@ private class EnterInformationDependency9204f24c784151f429ddProvider: EnterInfor
private func factory359a960501e79e833f64f47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return EnterInformationDependency9204f24c784151f429ddProvider(appComponent: parent1(component) as! AppComponent)
}
private class NoticeDependencyaec92ef53617a421bdf3Provider: NoticeDependency {


init() {

private class NoticeDependency0e93eb53be8626c408e4Provider: NoticeDependency {
var fetchNoticeListUseCase: any FetchNoticeListUseCase {
return appComponent.fetchNoticeListUseCase
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
}
}
/// ^->AppComponent->NoticeComponent
private func factoryaf8e5665e5b9217918f5e3b0c44298fc1c149afb(_ component: NeedleFoundation.Scope) -> AnyObject {
return NoticeDependencyaec92ef53617a421bdf3Provider()
/// ^->AppComponent->NoticeListComponent
private func factory2ff025b7b4896593c80af47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return NoticeDependency0e93eb53be8626c408e4Provider(appComponent: parent1(component) as! AppComponent)
}
private class FindIDDependencyb481fe947a844cc29913Provider: FindIDDependency {
var findIDUseCase: any FindIDUseCase {
Expand Down Expand Up @@ -353,7 +364,7 @@ extension AppComponent: Registration {
localTable["mainTabComponent-MainTabComponent"] = { self.mainTabComponent as Any }
localTable["homeComponent-HomeComponent"] = { self.homeComponent as Any }
localTable["applyComponent-ApplyComponent"] = { self.applyComponent as Any }
localTable["noticeComponent-NoticeComponent"] = { self.noticeComponent as Any }
localTable["noticeComponent-NoticeListComponent"] = { self.noticeComponent as Any }
localTable["myPageComponent-MyPageComponent"] = { self.myPageComponent as Any }
localTable["remoteNoticeDataSource-any RemoteNoticeDataSource"] = { self.remoteNoticeDataSource as Any }
localTable["noticeRepository-any NoticeRepository"] = { self.noticeRepository as Any }
Expand Down Expand Up @@ -435,6 +446,9 @@ extension SignupProfileImageComponent: Registration {
extension MainTabComponent: Registration {
public func registerItems() {
keyPathToName[\MainTabDependency.homeComponent] = "homeComponent-HomeComponent"
keyPathToName[\MainTabDependency.applyComponent] = "applyComponent-ApplyComponent"
keyPathToName[\MainTabDependency.noticeComponent] = "noticeComponent-NoticeListComponent"
keyPathToName[\MainTabDependency.myPageComponent] = "myPageComponent-MyPageComponent"
}
}
extension MyPageComponent: Registration {
Expand Down Expand Up @@ -484,9 +498,9 @@ extension EnterInformationComponent: Registration {
keyPathToName[\EnterInformationDependency.authenticationEmailComponent] = "authenticationEmailComponent-AuthenticationEmailComponent"
}
}
extension NoticeComponent: Registration {
extension NoticeListComponent: Registration {
public func registerItems() {

keyPathToName[\NoticeDependency.fetchNoticeListUseCase] = "fetchNoticeListUseCase-any FetchNoticeListUseCase"
}
}
extension FindIDComponent: Registration {
Expand Down Expand Up @@ -529,7 +543,7 @@ private func register1() {
registerProviderFactory("^->AppComponent->AuthenticationEmailComponent", factory8798d0becd9d2870112af47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->ChangePasswordComponent", factoryab7c4d87dab53e0a51b9f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->EnterInformationComponent", factory359a960501e79e833f64f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->NoticeComponent", factoryaf8e5665e5b9217918f5e3b0c44298fc1c149afb)
registerProviderFactory("^->AppComponent->NoticeListComponent", factory2ff025b7b4896593c80af47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->FindIDComponent", factory8dd2f9e0b545ead35ecaf47b58f8f304c97af4d5)
}
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import NeedleFoundation
import SwiftUI
import HomeFeature
import ApplyFeature
import NoticeFeature
import MyPageFeature

public protocol MainTabDependency: Dependency {
var homeComponent: HomeComponent { get }
var applyComponent: ApplyComponent { get }
var noticeComponent: NoticeListComponent { get }
var myPageComponent: MyPageComponent { get }
}

public final class MainTabComponent: Component<MainTabDependency> {
public func makeView() -> some View {
MainTabView(
homeComponent: dependency.homeComponent
homeComponent: dependency.homeComponent,
applyComponent: dependency.applyComponent,
noticeComponent: dependency.noticeComponent,
myPageComponent: dependency.myPageComponent
)
}
}
24 changes: 19 additions & 5 deletions Projects/Features/MainTabFeature/Sources/MainTabView.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import SwiftUI
import DesignSystem
import HomeFeature
import ApplyFeature
import NoticeFeature
import MyPageFeature
import BaseFeature
import DesignSystem
import Utility

enum TabFlow: Int {
Expand All @@ -15,9 +18,20 @@ struct MainTabView: View {
@State var tabbarHidden = false

private let homeComponent: HomeComponent
private let applyComponent: ApplyComponent
private let noticeComponent: NoticeListComponent
private let myPageComponent: MyPageComponent

init(homeComponent: HomeComponent) {
init(
homeComponent: HomeComponent,
applyComponent: ApplyComponent,
noticeComponent: NoticeListComponent,
myPageComponent: MyPageComponent
) {
self.homeComponent = homeComponent
self.applyComponent = applyComponent
self.noticeComponent = noticeComponent
self.myPageComponent = myPageComponent
}

var body: some View {
Expand All @@ -26,13 +40,13 @@ struct MainTabView: View {
homeComponent.makeView()
.tag(TabFlow.home)

Text("1")
applyComponent.makeView()
.tag(TabFlow.apply)

Text("2")
noticeComponent.makeView()
.tag(TabFlow.notice)

Text("3")
myPageComponent.makeView()
.tag(TabFlow.myPage)
}
.environment(\.tabbarHidden, $tabbarHidden)
Expand Down
10 changes: 0 additions & 10 deletions Projects/Features/NoticeFeature/Sources/NoticeComponent.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import DomainModule
import NeedleFoundation
import SwiftUI

public protocol NoticeDependency: Dependency {
var fetchNoticeListUseCase: any FetchNoticeListUseCase { get }
}
kimdaehee0824 marked this conversation as resolved.
Show resolved Hide resolved

public final class NoticeListComponent: Component<NoticeDependency> {
public func makeView() -> some View {
NoticeListView(
viewModel: .init(
fetchNoticeListUseCase: dependency.fetchNoticeListUseCase
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import DesignSystem
import SwiftUI

struct NoticeListView: View {
@StateObject var viewModel: NoticeListViewModel
@State var isNavigateSignup = false
kimdaehee0824 marked this conversation as resolved.
Show resolved Hide resolved

init(
viewModel: NoticeListViewModel
) {
_viewModel = StateObject(wrappedValue: viewModel)
}

var body: some View {
NavigationView {
VStack {
HStack {
Spacer()

NoticeOrderButton(text: viewModel.orderTypeButtonName, color: .GrayScale.gray6) {
viewModel.orderTypeButtonDidTap()
}
.padding(.horizontal, 24)
}
.padding(.top, 12)

ScrollView {
VStack {
Spacer()
.frame(height: 10)

ForEach(viewModel.noticeList, id: \.self) { noticeList in
noticeListCellView(
title: noticeList.title,
content: viewModel.dateToString(date: noticeList.createdAt)
)
.padding(.top, 5)
.listRowInsets(EdgeInsets())

}
}
.padding(.horizontal, 24)

}
}
.navigationTitle("공지")
.navigationBarTitleDisplayMode(.inline)
}
}

@ViewBuilder
func noticeListCellView(title: String, content: String) -> some View {
ZStack {
Color.System.surface
.cornerRadius(6)

HStack {
VStack(alignment: .leading) {
Text(title)
.dmsFont(.text(.medium), color: .System.title)

Text(content)
.dmsFont(.text(.extraSmall), color: .System.text)
}
Spacer()
}
.padding(.horizontal, 16)
}
.frame(height: 68)
.shadow(color: .GrayScale.gray5.opacity(0.15), blur: 20)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import BaseFeature
import Foundation
import DomainModule
import ErrorModule
import Combine
import DataMappingModule

final class NoticeListViewModel: BaseViewModel {
@Published var noticeList: [NoticeEntity] = []
@Published var noticeOrderType: NoticeOrderType = .new
@Published var orderTypeButtonName: String = "최신순"

private let fetchNoticeListUseCase: any FetchNoticeListUseCase

init(
fetchNoticeListUseCase: any FetchNoticeListUseCase
) {
self.fetchNoticeListUseCase = fetchNoticeListUseCase
super.init()
fetchNoticeList()
}

func fetchNoticeList() {
addCancellable(
fetchNoticeListUseCase.execute(
order: noticeOrderType
)
) { [weak self] noticeList in
self?.noticeList = noticeList
}
}

func orderTypeButtonDidTap() {
if noticeOrderType == .new {
self.noticeOrderType = .old
self.orderTypeButtonName = "오래된순"
kimdaehee0824 marked this conversation as resolved.
Show resolved Hide resolved
fetchNoticeList()
} else if noticeOrderType == .old {
self.noticeOrderType = .new
self.orderTypeButtonName = "최신순"
fetchNoticeList()
kimdaehee0824 marked this conversation as resolved.
Show resolved Hide resolved
}
}

func dateToString(date: Date) -> String {
let dateFomatter = DateFormatter()
dateFomatter.dateFormat = "yyyy-MM-dd"
return dateFomatter.string(from: date)
kimdaehee0824 marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import SwiftUI
import DesignSystem

public struct NoticeOrderButton: View {
var text: String
var color: Color
var action: () -> Void

public init(
text: String = "",
color: Color = .blue,
action: @escaping () -> Void = {}
) {
self.text = text
self.color = color
self.action = action
}

public var body: some View {
Button(action: action) {
Text(text)
}
.buttonStyle(NoticeOrderButtonStyle())
}
}

public struct NoticeOrderButtonStyle: ButtonStyle {
public func makeBody(configuration: Configuration) -> some View {
return AnyView(OutlinedButton(configuration: configuration, color: .GrayScale.gray6))
}
}

// MARK: - Outlined
extension NoticeOrderButtonStyle {
struct OutlinedButton: View {
let configuration: ButtonStyle.Configuration
let color: Color
@Environment(\.isEnabled) private var isEnabled: Bool

var body: some View {
configuration.label
.padding(.vertical, 8.5)
.padding(.horizontal, 16)
.dmsFont(.button(.default))
.background(.clear)
.foregroundColor(color)
.overlay {
RoundedRectangle(cornerRadius: 5)
.stroke(color, lineWidth: 1)
}
.opacity(
isEnabled ?
configuration.isPressed ? 0.7 : 1.0 :
0.5
)
}
}
}
Loading