Skip to content

Commit

Permalink
some minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisho committed Dec 28, 2019
1 parent 9f81d19 commit f19c0fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
13 changes: 9 additions & 4 deletions Papr/Custom UI/PaprNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ class PaprNavigationController: UINavigationController {
topViewController?.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: nil, action: nil)

service.getMe()
.flatMap { result -> Observable<User> in
guard case let .success(user) = result else { return .empty() }
profileImage.isHidden = false
return .just(user)
.map { result -> User? in
switch result {
case let .success(user):
profileImage.isHidden = false
return user
case .failure:
return nil
}
}
.unwrap()
.map { $0.profileImage?.medium }
.unwrap()
.mapToURL()
Expand Down
2 changes: 1 addition & 1 deletion Papr/Services/PhotoService/PhotoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct PhotoService: PhotoServiceType {
.catchError { _ in
let accessToken = UserDefaults.standard.string(forKey: Papr.Unsplash.clientID)
guard accessToken == nil else {
return .just(.failure(.other(message: "Failed to like")))
return .just(.failure(.other(message: "Failed to unlike")))
}
return .just(.failure(.noAccessToken))
}
Expand Down
5 changes: 1 addition & 4 deletions Papr/Utils/Extentions/Rx/ObservableType+Extras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ extension ObservableType {

}
extension Observable where Element == String {

func mapToURL() -> Observable<URL> {
return map { URL(string: $0) }
.filter { $0 != nil }
.map { $0! }
return map { URL(string: $0) }.compactMap { $0 }
}
}
extension Observable where Element == Data {
Expand Down

0 comments on commit f19c0fc

Please sign in to comment.