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

πŸ”€ :: [#395] κ°•μ˜ μž₯μ†Œ 우편번호 검색 κΈ°λŠ₯ μΆ”κ°€ #409

Merged
merged 3 commits into from
Aug 16, 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 @@ -17,7 +17,10 @@ final class InputLectureViewModel: BaseViewModel {
lectureDates: [],
lectureType: "μƒν˜Έν•™μ μΈμ •κ΅μœ‘κ³Όμ •",
credit: 0,
maxRegisteredUser: 0
maxRegisteredUser: 0,
address: "",
locationDetails: "",
essentialComplete: true
)

let lectureID: String
Expand Down Expand Up @@ -66,7 +69,10 @@ final class InputLectureViewModel: BaseViewModel {
lectureDates: detailInfo.lectureDates,
lectureType: detailInfo.lectureType,
credit: detailInfo.credit,
maxRegisteredUser: detailInfo.maxRegisteredUser
maxRegisteredUser: detailInfo.maxRegisteredUser,
address: detailInfo.address,
locationDetails: detailInfo.locationDetails,
essentialComplete: detailInfo.essentialComplete
)
}

Expand Down Expand Up @@ -106,7 +112,10 @@ final class InputLectureViewModel: BaseViewModel {
},
lectureType: response.lectureType,
credit: response.credit,
maxRegisteredUser: response.credit
maxRegisteredUser: response.credit,
address: response.address,
locationDetails: response.locationDetails,
essentialComplete: response.essentialComplete
)
}

Expand Down Expand Up @@ -154,7 +163,10 @@ final class InputLectureViewModel: BaseViewModel {
},
lectureType: lectureInfo.lectureType,
credit: lectureInfo.credit,
maxRegisteredUser: lectureInfo.maxRegisteredUser
maxRegisteredUser: lectureInfo.maxRegisteredUser,
address: lectureInfo.address,
locationDetails: lectureInfo.locationDetails,
essentialComplete: lectureInfo.essentialComplete
)
)
}
Expand All @@ -181,7 +193,10 @@ final class InputLectureViewModel: BaseViewModel {
},
lectureType: lectureInfo.lectureType,
credit: lectureInfo.credit,
maxRegisteredUser: lectureInfo.maxRegisteredUser
maxRegisteredUser: lectureInfo.maxRegisteredUser,
address: lectureInfo.address,
locationDetails: lectureInfo.locationDetails,
essentialComplete: lectureInfo.essentialComplete
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public struct LectureDataModel: Equatable {
let lectureType: String
let credit: Int
let maxRegisteredUser: Int
let address: String
let locationDetails: String
let essentialComplete: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct ApplicationPeriodView: View {

VStack(alignment: .leading, spacing: 8) {
BitgouelText(
text: "마감일",
text: "μ‹ μ²­ 마감일",
font: .text1
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import SwiftUI

struct LectureLocationView: View {
@Binding var isShowingPostCodeSheet: Bool
@Binding var address: String
@Binding var locationDetail: String

var body: some View {
VStack(alignment: .leading, spacing: 8) {
BitgouelText(
text: "κ°•μ˜ μž₯μ†Œ",
font: .text1
)

PickerTextField(
"μ§€λ²ˆ, λ„λ‘œλͺ… μ£Όμ†Œ 검색",
text: address
) {
isShowingPostCodeSheet = true
}

BitgouelTextField(
"상세 μ£Όμ†Œ μž…λ ₯",
text: $locationDetail
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ struct LectureDetailSettingView: View {
)
)

LectureLocationView(
isShowingPostCodeSheet: $viewModel.isShowingPostCodeSheet,
address: $viewModel.selectedAddress,
locationDetail: $viewModel.enteredLocationDetail
)

LectureDatesView(
lectureDatesList: viewModel.lectureDatesList
) { completeDate, index in
Expand Down Expand Up @@ -217,6 +223,15 @@ struct LectureDetailSettingView: View {
viewModel.resetKeyword()
}
}
.sheet(isPresented: $viewModel.isShowingPostCodeSheet) {
if let url = viewModel.postCodeWebURL {
KakaoPostCodeView(
request: URLRequest(url: url),
isShowingKakaoWebSheet: $viewModel.isShowingPostCodeSheet,
address: $viewModel.selectedAddress
)
}
}
.onTapGesture {
hideKeyboard()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ final class LectureDetailSettingViewModel: BaseViewModel {
@Published var selectedMaxRegisteredUser: Int = 0
@Published var isShowingMaxRegisteredUserBottomSheet: Bool = false

// MARK: Location
@Published var isShowingPostCodeSheet: Bool = false
@Published var selectedAddress: String = ""
@Published var enteredLocationDetail: String = ""

@Published var isEssential: Bool = true
@Published var keyword: String = ""
@Published var detailInfo: LectureDataModel
let completion: (LectureDataModel) -> Void
let postCodeWebURL: URL? = URL(string: "https://uuuunseo.github.io/DaumWeb/")

private let searchInstructorUseCase: any SearchInstructorUseCase
private let searchLineUseCase: any SearchLineUseCase
Expand Down Expand Up @@ -240,7 +246,10 @@ final class LectureDetailSettingViewModel: BaseViewModel {
lectureDates: lectureDatesList,
lectureType: lectureTypeString,
credit: selectedCredit,
maxRegisteredUser: selectedMaxRegisteredUser
maxRegisteredUser: selectedMaxRegisteredUser,
address: selectedAddress,
locationDetails: enteredLocationDetail,
essentialComplete: isEssential
)

completion(detailInfo)
Expand All @@ -258,6 +267,7 @@ final class LectureDetailSettingViewModel: BaseViewModel {
updateLectureType(lectureType: detailInfo.lectureType)
updateCredit(credit: detailInfo.credit)
updateMaxRegisterUser(maxRegisterUser: detailInfo.maxRegisteredUser)
updateIsEssential(isEssential: detailInfo.essentialComplete)
}

@MainActor
Expand Down
90 changes: 90 additions & 0 deletions App/Sources/Utils/View/KakaoPostCodeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import SwiftUI
import WebKit

struct KakaoPostCodeView: UIViewRepresentable {
let request: URLRequest
var webView: WKWebView?
@Binding var isShowingKakaoWebSheet: Bool
@Binding var address: String

init(
request: URLRequest,
isShowingKakaoWebSheet: Binding<Bool>,
address: Binding<String>
) {
self.webView = WKWebView()
self.request = request
self._isShowingKakaoWebSheet = isShowingKakaoWebSheet
self._address = address
self.webView?.configuration.userContentController.add(KakaoWebController(isShowingkakaoWebSheet: _isShowingKakaoWebSheet, address: _address), name: "callBackHandler")
}

func makeUIView(context: Context) -> WKWebView {
return webView!
}

func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}

func makeCoordinator() -> Coordinator {
Coordinator(parent: self)
}

class Coordinator: NSObject, WKNavigationDelegate {
let parent: KakaoPostCodeView

init(parent: KakaoPostCodeView) {
self.parent = parent
}
}
}

class KakaoWebController: NSObject, WKScriptMessageHandler {
@Binding var isShowingKakaoWebSheet: Bool
@Binding var address: String

init(
isShowingkakaoWebSheet: Binding<Bool>,
address: Binding<String>
) {
self._isShowingKakaoWebSheet = isShowingkakaoWebSheet
self._address = address
}

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "callBackHandler", let data = message.body as? [String: Any] {
if message.name == "callBackHandler" {
print("message name : \(message.name)")
print("post Message : \(message.body)")

if let roadAddress = (data["roadAddress"]) as? String {
print("roadAddress: \(roadAddress)")
address = roadAddress
print(address)
}
isShowingKakaoWebSheet.toggle()
}
}
}
}


extension KakaoPostCodeView {
func callJS(_ args: Any = "") {
webView?.evaluateJavaScript("postMessageToiOS('\(args)')") { result, error in
if let error {
print("Error \(error.localizedDescription)")
return
}

if result == nil {
print("It's void function")
return
}

print("Received Data \(result ?? "")")
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public struct InputLectureRequestDTO: Encodable {
public let lectureType: String
public let credit: Int
public let maxRegisteredUser: Int
public let address: String
public let locationDetails: String
public let essentialComplete: Bool

public init(
name: String,
Expand All @@ -28,7 +31,10 @@ public struct InputLectureRequestDTO: Encodable {
lectureDates: [LectureDateInfo],
lectureType: String,
credit: Int,
maxRegisteredUser: Int
maxRegisteredUser: Int,
address: String,
locationDetails: String,
essentialComplete: Bool
) {
self.name = name
self.content = content
Expand All @@ -43,6 +49,9 @@ public struct InputLectureRequestDTO: Encodable {
self.lectureType = lectureType
self.credit = credit
self.maxRegisteredUser = maxRegisteredUser
self.address = address
self.locationDetails = locationDetails
self.essentialComplete = essentialComplete
}

enum CodingKeys: String, CodingKey {
Expand All @@ -59,6 +68,9 @@ public struct InputLectureRequestDTO: Encodable {
case lectureType
case credit
case maxRegisteredUser
case address
case locationDetails
case essentialComplete
}

public struct LectureDateInfo: Encodable {
Expand Down
Loading