Skip to content

Commit

Permalink
Send login email
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTreguier committed Aug 13, 2024
1 parent 0f214a6 commit e7ea96a
Show file tree
Hide file tree
Showing 32 changed files with 874 additions and 344 deletions.
92 changes: 49 additions & 43 deletions Fyreplace.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions Fyreplace/Commands/DestinationCommands.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import Combine
import SwiftUI

struct DestinationCommands: Commands {
var subject: PassthroughSubject<Destination, Never>
let eventBus: EventBus

var body: some Commands {
CommandGroup(after: .sidebar) {
Divider()

ForEach(Destination.all) { destination in
Button(destination.titleKey) {
subject.send(destination)
Task {
await eventBus.send(.navigationShortcut(to: destination))
}
}
.keyboardShortcut(destination.keyboardShortcut)
}
Expand All @@ -19,14 +20,3 @@ struct DestinationCommands: Commands {
}
}
}

struct DestinationCommandEnvironmentKey: EnvironmentKey {
static let defaultValue = AnyPublisher<Destination, Never>.empty
}

extension EnvironmentValues {
var destinationCommands: AnyPublisher<Destination, Never> {
get { self[DestinationCommandEnvironmentKey.self] }
set { self[DestinationCommandEnvironmentKey.self] = newValue }
}
}
23 changes: 17 additions & 6 deletions Fyreplace/Config/Config.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import OpenAPIURLSession
import SwiftUI

struct Config {
Expand Down Expand Up @@ -54,24 +55,34 @@ struct Config {
struct Api {
let main: URL
let dev: URL
let local: URL?
#if DEBUG
let local: URL
#endif

init(_ data: [String: Any]) {
main = data.url("Main")!
dev = data.url("Dev")!
local = data.url("Local")
#if DEBUG
local = data.url("Local")!
#endif
}

func url(for environment: ServerEnvironment) -> URL? {
switch environment {
func url(for environment: ServerEnvironment) -> URL {
return switch environment {
case .main:
main
case .dev:
dev
case .local:
local
#if DEBUG
case .local:
local
#endif
}
}

func client(for environment: ServerEnvironment) -> Client {
return Client(serverURL: url(for: environment), transport: URLSessionTransport())
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions Fyreplace/Data/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import SwiftUI
enum ServerEnvironment: String, CaseIterable, Identifiable {
case main
case dev
case local
#if DEBUG
case local
#endif

var id: String { rawValue }

Expand All @@ -13,8 +15,10 @@ enum ServerEnvironment: String, CaseIterable, Identifiable {
.init(localized: "Environment.Main")
case .dev:
.init(localized: "Environment.Dev")
case .local:
.init(localized: "Environment.Local")
#if DEBUG
case .local:
.init(localized: "Environment.Local")
#endif
}
}

Expand Down
36 changes: 36 additions & 0 deletions Fyreplace/Events/Event.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import SwiftUI

protocol Event {}

struct ErrorEvent: Event {
let error: UnexpectedError

init(_ error: UnexpectedError) {
self.error = error
}
}

extension Event {
typealias error = ErrorEvent
}

struct FailureEvent: Event {
let title: LocalizedStringKey
let text: LocalizedStringKey
}

extension Event {
typealias failure = FailureEvent
}

struct NavigationShortcutEvent: Event {
let destination: Destination

init(to destination: Destination) {
self.destination = destination
}
}

extension Event {
typealias navigationShortcut = NavigationShortcutEvent
}
17 changes: 17 additions & 0 deletions Fyreplace/Events/EventBus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Combine
import SwiftUI

class EventBus: ObservableObject {
private let subject = PassthroughSubject<Event, Never>()

let events: AnyPublisher<Event, Never>

init() {
events = subject.eraseToAnyPublisher()
}

@MainActor
func send(_ event: Event) {
subject.send(event)
}
}
7 changes: 0 additions & 7 deletions Fyreplace/Extensions/AnyPublisher.swift

This file was deleted.

2 changes: 0 additions & 2 deletions Fyreplace/Extensions/Array+RawRepresentable.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation

extension Array: RawRepresentable where Element: Codable {
public typealias RawValue = String

public init?(rawValue: String) {
self.init()
guard let data = rawValue.data(using: .utf8),
Expand Down
Loading

0 comments on commit e7ea96a

Please sign in to comment.