-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from juandahurt/place
feat: add place module with basic ui
- Loading branch information
Showing
13 changed files
with
346 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+24.7 KB
(110%)
...proj/project.xcworkspace/xcuserdata/juandahurt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// PYPlace.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
|
||
struct PYPlace: Decodable { | ||
var title: String | ||
var subtitle: String | ||
var image: String | ||
var description: String? | ||
} | ||
|
||
extension PYPlace { | ||
static let empty = PYPlace(title: "", subtitle: "", image: "") | ||
} |
28 changes: 28 additions & 0 deletions
28
Payan/App/Domain Modules/Place/Interactor/PYPlaceInteractor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// PYPlaceInteractor.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
|
||
class PYPlaceInteractor: PYPlaceBusinessLogic { | ||
var worker: PYPlaceDataAccessLogic | ||
|
||
init(worker: PYPlaceDataAccessLogic = PYPlaceNetworkWorker()) { | ||
self.worker = worker | ||
} | ||
|
||
func getPlace(identifiedBy id: String, completion: @escaping (Result<PYPlace, Error>) -> Void) { | ||
worker.fecthPlace(id: id) { res in | ||
DispatchQueue.main.async { | ||
switch res { | ||
case .success(let place): | ||
completion(.success(place)) | ||
case .failure(_): break | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// PYPlaceModule.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
final class PYPlaceModule: PYModule { | ||
var host: String = "place" | ||
|
||
func getViewController(params: [URLQueryItem]) -> UIViewController? { | ||
guard !params.isEmpty, params[0].name == "id", let placeId = params[0].value else { return nil } | ||
return UIHostingController(rootView: PYPlacePageView(placeId: placeId)) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Payan/App/Domain Modules/Place/Protocols/PYPlaceBusinessLogic.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// PYPlaceBusinessLogic.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol PYPlaceBusinessLogic { | ||
var worker: PYPlaceDataAccessLogic { get } | ||
|
||
func getPlace(identifiedBy id: String, completion: @escaping (Result<PYPlace,Error>) -> Void) | ||
} |
12 changes: 12 additions & 0 deletions
12
Payan/App/Domain Modules/Place/Protocols/PYPlaceDataAccessLogic.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// PYPlaceDataAccessLogic.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol PYPlaceDataAccessLogic { | ||
func fecthPlace(id: String, completion: @escaping (Result<PYPlace,Error>) -> Void) | ||
} |
12 changes: 12 additions & 0 deletions
12
Payan/App/Domain Modules/Place/Protocols/PYPlaceViewLogic.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// PYPlaceViewLogic.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol PYPlaceViewLogic { | ||
var placeId: String { get } | ||
} |
78 changes: 78 additions & 0 deletions
78
Payan/App/Domain Modules/Place/UI/Page/PYPlacePageView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// PYPlacePageView.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import Purace | ||
|
||
struct PYPlacePageView: View, PYPlaceViewLogic { | ||
var placeId: String | ||
|
||
@StateObject var viewModel = PYPlaceViewModel() | ||
|
||
init(placeId: String) { | ||
self.placeId = placeId | ||
} | ||
|
||
var navBar: some View { | ||
HStack(alignment: .center) { | ||
Image(systemName: "chevron.left") | ||
.foregroundColor(.white) | ||
.scaleEffect(1.2) | ||
.onTapGesture { | ||
PYRoutingManager.shared.pop() | ||
} | ||
Spacer() | ||
}.padding() | ||
.frame(height: 50) | ||
} | ||
|
||
var image: some View { | ||
let url = URL(string: viewModel.place.image) | ||
return ZStack { | ||
PuraceImageView(url: url) | ||
.aspectRatio(contentMode: .fill) | ||
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height * 0.35) | ||
.clipped() | ||
LinearGradient(colors: [.black.opacity(0.55), .clear], startPoint: .top, endPoint: .center) | ||
}.frame(height: UIScreen.main.bounds.height * 0.35) | ||
} | ||
|
||
var title: some View { | ||
VStack(spacing: 10) { | ||
PuraceTextView(viewModel.place.title, fontSize: 18, weight: .medium) | ||
PuraceTextView(viewModel.place.subtitle, fontSize: 12, textColor: PuraceStyle.Color.N4) | ||
} | ||
} | ||
|
||
var description: some View { | ||
PuraceTextView(viewModel.place.description ?? "") | ||
} | ||
|
||
var body: some View { | ||
ZStack { | ||
ScrollView { | ||
VStack { | ||
image | ||
title | ||
.padding(.top) | ||
description | ||
.padding() | ||
Spacer() | ||
} | ||
} | ||
VStack { | ||
navBar | ||
Spacer() | ||
} | ||
} | ||
.navigationBarHidden(true) | ||
.onFirstAppear { | ||
viewModel.getPlace(id: placeId) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Payan/App/Domain Modules/Place/UI/View Model/PYPlaceViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// PYPlaceViewModel.swift | ||
// Payan | ||
// | ||
// Created by Juan Hurtado on 28/05/22. | ||
// | ||
|
||
import Foundation | ||
|
||
class PYPlaceViewModel: ObservableObject { | ||
@Published var place: PYPlace = .empty | ||
let interactor: PYPlaceBusinessLogic | ||
|
||
init(interactor: PYPlaceBusinessLogic = PYPlaceInteractor()) { | ||
self.interactor = interactor | ||
} | ||
|
||
func getPlace(id: String) { | ||
interactor.getPlace(identifiedBy: id) { [weak self] res in | ||
guard let self = self else { return } | ||
switch res { | ||
case .success(let place): | ||
self.place = place | ||
case .failure(_): break | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.