From 865537f66bb83233c48c0609a7b018f70bf7fbcb Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 2 Feb 2024 23:06:39 +0100 Subject: [PATCH] base commit --- PadelClub.xcodeproj/project.pbxproj | 20 ++++++++++++++++++++ PadelClub/ContentView.swift | 20 +++++++++++++++++--- PadelClub/Data/Club.swift | 13 +++++++++++++ PadelClub/Data/DataStore.swift | 12 +++++++----- PadelClub/PadelClubApp.swift | 10 ++++++++++ 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index c75bca6..c270d80 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -15,6 +15,9 @@ C425D41C2B6D249E002A7B48 /* PadelClubUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C425D41B2B6D249E002A7B48 /* PadelClubUITests.swift */; }; C425D41E2B6D249E002A7B48 /* PadelClubUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C425D41D2B6D249E002A7B48 /* PadelClubUITestsLaunchTests.swift */; }; C425D45A2B6D255B002A7B48 /* LeStorage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C425D4542B6D24E2002A7B48 /* LeStorage.framework */; }; + C4A47D5A2B6D383C00ADC637 /* Tournament.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A47D592B6D383C00ADC637 /* Tournament.swift */; }; + C4A47D5E2B6D38EC00ADC637 /* DataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A47D5D2B6D38EC00ADC637 /* DataStore.swift */; }; + C4A47D632B6D3D6500ADC637 /* Club.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A47D622B6D3D6500ADC637 /* Club.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -60,6 +63,9 @@ C425D41B2B6D249E002A7B48 /* PadelClubUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PadelClubUITests.swift; sourceTree = ""; }; C425D41D2B6D249E002A7B48 /* PadelClubUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PadelClubUITestsLaunchTests.swift; sourceTree = ""; }; C425D44E2B6D24E1002A7B48 /* LeStorage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LeStorage.xcodeproj; path = ../../LeStorage/LeStorage.xcodeproj; sourceTree = ""; }; + C4A47D592B6D383C00ADC637 /* Tournament.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tournament.swift; sourceTree = ""; }; + C4A47D5D2B6D38EC00ADC637 /* DataStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStore.swift; sourceTree = ""; }; + C4A47D622B6D3D6500ADC637 /* Club.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Club.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -115,6 +121,7 @@ C425D44E2B6D24E1002A7B48 /* LeStorage.xcodeproj */, C425D4002B6D249D002A7B48 /* PadelClubApp.swift */, C425D4022B6D249D002A7B48 /* ContentView.swift */, + C4A47D5F2B6D3B2D00ADC637 /* Data */, C425D4042B6D249E002A7B48 /* Assets.xcassets */, C425D4062B6D249E002A7B48 /* Preview Content */, ); @@ -162,6 +169,16 @@ name = Frameworks; sourceTree = ""; }; + C4A47D5F2B6D3B2D00ADC637 /* Data */ = { + isa = PBXGroup; + children = ( + C4A47D5D2B6D38EC00ADC637 /* DataStore.swift */, + C4A47D592B6D383C00ADC637 /* Tournament.swift */, + C4A47D622B6D3D6500ADC637 /* Club.swift */, + ); + path = Data; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -315,6 +332,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C4A47D5A2B6D383C00ADC637 /* Tournament.swift in Sources */, + C4A47D5E2B6D38EC00ADC637 /* DataStore.swift in Sources */, + C4A47D632B6D3D6500ADC637 /* Club.swift in Sources */, C425D4032B6D249D002A7B48 /* ContentView.swift in Sources */, C425D4012B6D249D002A7B48 /* PadelClubApp.swift in Sources */, ); diff --git a/PadelClub/ContentView.swift b/PadelClub/ContentView.swift index c2049d1..2a940bb 100644 --- a/PadelClub/ContentView.swift +++ b/PadelClub/ContentView.swift @@ -9,19 +9,33 @@ import SwiftUI import LeStorage struct ContentView: View { + + @ObservedObject var dataStore = DataStore() + var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") + + List(self.dataStore.clubs.items) { club in + Text(club.name).id(club.id) + } + + Button("add") { + self._add() + }.padding() + .buttonStyle(.bordered) } - .padding() } - func test() { - let s = Store() + func _add() { + let id = (0...1000000).randomElement()! + let club: Club = Club(name: "test\(id)") + self.dataStore.clubs.addOrUpdate(instance: club) } + } #Preview { diff --git a/PadelClub/Data/Club.swift b/PadelClub/Data/Club.swift index 5f47fc6..a00f56b 100644 --- a/PadelClub/Data/Club.swift +++ b/PadelClub/Data/Club.swift @@ -6,3 +6,16 @@ // import Foundation +import LeStorage + +class Club : Storable, ObservableObject { + static var resourceName: String = "clubs" + + var id: String = UUID().uuidString + var name: String + + init(name: String) { + self.name = name + } + +} diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 87eb65f..c7a351d 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -7,17 +7,19 @@ import Foundation import LeStorage +import SwiftUI -class DataStore { +class DataStore : ObservableObject { - static let main: DataStore = DataStore() fileprivate var _store: Store - fileprivate(set) var tournaments: StoredCollection + @ObservedObject fileprivate(set) var tournaments: StoredCollection + @ObservedObject fileprivate(set) var clubs: StoredCollection init() { - let store = Store(synchronizationApiURL: "http://127.0.0.1:8000/") - self.tournaments = store.registerCollection(synchronized: true) + let store = Store(synchronizationApiURL: "https://padelclub.app/api/") + self.tournaments = store.registerCollection(synchronized: false) + self.clubs = store.registerCollection(synchronized: false) self._store = store } diff --git a/PadelClub/PadelClubApp.swift b/PadelClub/PadelClubApp.swift index 2566644..fd2d028 100644 --- a/PadelClub/PadelClubApp.swift +++ b/PadelClub/PadelClubApp.swift @@ -6,12 +6,22 @@ // import SwiftUI +import LeStorage @main struct PadelClubApp: App { var body: some Scene { WindowGroup { ContentView() + .onAppear { + self._onAppear() + } } } + + fileprivate func _onAppear() { + let docURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] + Logger.log("doc dir = \(docURL.absoluteString)") + } + }