Skip to content

Commit 0195728

Browse files
committed
wip
1 parent 97888eb commit 0195728

File tree

4 files changed

+122
-36
lines changed

4 files changed

+122
-36
lines changed

Examples/Examples.xcodeproj/project.pbxproj

+17
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
7956406A2955AFBD0088A06F /* ErrorText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 795640692955AFBD0088A06F /* ErrorText.swift */; };
3434
7956406D2955B3500088A06F /* SwiftUINavigation in Frameworks */ = {isa = PBXBuildFile; productRef = 7956406C2955B3500088A06F /* SwiftUINavigation */; };
3535
795640702955B5190088A06F /* IdentifiedCollections in Frameworks */ = {isa = PBXBuildFile; productRef = 7956406F2955B5190088A06F /* IdentifiedCollections */; };
36+
79615DF92C3DA92C005AE6E0 /* CustomDump in Frameworks */ = {isa = PBXBuildFile; productRef = 79615DF82C3DA92C005AE6E0 /* CustomDump */; };
3637
796298992AEBBA77000AA957 /* MFAFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796298982AEBBA77000AA957 /* MFAFlow.swift */; };
3738
7962989D2AEBC6F9000AA957 /* SVGView in Frameworks */ = {isa = PBXBuildFile; productRef = 7962989C2AEBC6F9000AA957 /* SVGView */; };
3839
79719ECE2ADF26C400737804 /* Supabase in Frameworks */ = {isa = PBXBuildFile; productRef = 79719ECD2ADF26C400737804 /* Supabase */; };
@@ -163,6 +164,7 @@
163164
buildActionMask = 2147483647;
164165
files = (
165166
792404E32C3473EC002959B3 /* Supabase in Frameworks */,
167+
79615DF92C3DA92C005AE6E0 /* CustomDump in Frameworks */,
166168
);
167169
runOnlyForDeploymentPostprocessing = 0;
168170
};
@@ -400,6 +402,7 @@
400402
name = SupaDrive;
401403
packageProductDependencies = (
402404
792404E22C3473EC002959B3 /* Supabase */,
405+
79615DF82C3DA92C005AE6E0 /* CustomDump */,
403406
);
404407
productName = SupaDrive;
405408
productReference = 792404B72C3454A9002959B3 /* SupaDrive.app */;
@@ -509,6 +512,7 @@
509512
7956406E2955B5190088A06F /* XCRemoteSwiftPackageReference "swift-identified-collections" */,
510513
7962989B2AEBC6F9000AA957 /* XCRemoteSwiftPackageReference "SVGView" */,
511514
79E2B5562B97890F0042CD21 /* XCRemoteSwiftPackageReference "GoogleSignIn-iOS" */,
515+
79615DF72C3DA92C005AE6E0 /* XCRemoteSwiftPackageReference "swift-custom-dump" */,
512516
);
513517
productRefGroup = 793895C72954ABFF0044F2B8 /* Products */;
514518
projectDirPath = "";
@@ -1136,6 +1140,14 @@
11361140
minimumVersion = 1.0.0;
11371141
};
11381142
};
1143+
79615DF72C3DA92C005AE6E0 /* XCRemoteSwiftPackageReference "swift-custom-dump" */ = {
1144+
isa = XCRemoteSwiftPackageReference;
1145+
repositoryURL = "https://github.com/pointfreeco/swift-custom-dump";
1146+
requirement = {
1147+
kind = upToNextMajorVersion;
1148+
minimumVersion = 1.3.0;
1149+
};
1150+
};
11391151
7962989B2AEBC6F9000AA957 /* XCRemoteSwiftPackageReference "SVGView" */ = {
11401152
isa = XCRemoteSwiftPackageReference;
11411153
repositoryURL = "https://github.com/exyte/SVGView";
@@ -1169,6 +1181,11 @@
11691181
package = 7956406E2955B5190088A06F /* XCRemoteSwiftPackageReference "swift-identified-collections" */;
11701182
productName = IdentifiedCollections;
11711183
};
1184+
79615DF82C3DA92C005AE6E0 /* CustomDump */ = {
1185+
isa = XCSwiftPackageProductDependency;
1186+
package = 79615DF72C3DA92C005AE6E0 /* XCRemoteSwiftPackageReference "swift-custom-dump" */;
1187+
productName = CustomDump;
1188+
};
11721189
7962989C2AEBC6F9000AA957 /* SVGView */ = {
11731190
isa = XCSwiftPackageProductDependency;
11741191
package = 7962989B2AEBC6F9000AA957 /* XCRemoteSwiftPackageReference "SVGView" */;

Examples/SupaDrive/AppView.swift

+55-23
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
// Created by Guilherme Souza on 02/07/24.
66
//
77

8+
import CustomDump
89
import Supabase
910
import SwiftUI
1011

1112
enum Item: Identifiable, Hashable {
12-
case folder(Folder)
13-
case file(File)
13+
case folder(FileObject)
14+
case file(FileObject)
1415

15-
var id: String {
16+
var id: String? {
1617
switch self {
1718
case let .file(file): file.id
1819
case let .folder(folder): folder.id
@@ -37,16 +38,17 @@ enum Item: Identifiable, Hashable {
3738
}
3839
}
3940

40-
struct Folder: Identifiable, Hashable {
41-
let id: String
42-
let name: String
43-
let items: [Item]
44-
}
45-
46-
struct File: Identifiable, Hashable {
47-
let id: String
48-
let name: String
49-
}
41+
//
42+
// struct Folder: Identifiable, Hashable {
43+
// let id: String
44+
// let name: String
45+
// let items: [Item]
46+
// }
47+
//
48+
// struct File: Identifiable, Hashable {
49+
// let id: String
50+
// let name: String
51+
// }
5052

5153
struct AppView: View {
5254
@State var path: [String]
@@ -85,16 +87,27 @@ struct AppView: View {
8587
let selectedItem = selectedItemPerPath[lastPath],
8688
case let .file(file) = selectedItem
8789
{
88-
ScrollView {
89-
VStack {
90-
Text(file.name)
90+
Form {
91+
Text(file.name)
92+
.font(.title2)
93+
Divider()
94+
95+
if let contentLenth = file.metadata?["contentLength"]?.intValue {
96+
LabeledContent("Size", value: "\(contentLenth)")
97+
}
98+
99+
if let mimeType = file.metadata?["mimetype"]?.stringValue {
100+
LabeledContent("MIME Type", value: mimeType)
91101
}
92-
.frame(width: 200)
93-
.padding()
94102
}
95-
.background(Color.secondary)
103+
.frame(width: 300)
104+
.frame(maxHeight: .infinity, alignment: .top)
105+
.padding()
106+
.background(Color(NSColor.controlBackgroundColor))
107+
.transition(.move(edge: .trailing))
96108
}
97109
}
110+
.animation(.default, value: path.last)
98111
}
99112
}
100113

@@ -125,7 +138,7 @@ struct PanelView: View {
125138
do {
126139
let files = try await supabase.storage.from("main").list(path: path)
127140

128-
items = files.map(Item.init)
141+
items = files.compactMap(Item.init)
129142
} catch {
130143
dump(error)
131144
}
@@ -154,19 +167,38 @@ struct PanelView: View {
154167
Color.gray.opacity(0.2)
155168
}
156169
}
170+
.contextMenu {
171+
Button("New folder") {
172+
Task {
173+
try! await supabase.storage.from("main")
174+
.upload(path: "\(path)/Untiltled/.dummy", file: Data())
175+
reload = UUID()
176+
}
177+
}
178+
}
157179
}
158180
}
159181

160182
extension Item {
161-
init(file: FileObject) {
183+
init?(file: FileObject) {
184+
if file.name.hasPrefix(".") { return nil }
185+
162186
if file.id == nil {
163-
self = .folder(Folder(id: file.name, name: file.name, items: []))
187+
self = .folder(file)
164188
} else {
165-
self = .file(File(id: file.id!, name: file.name))
189+
self = .file(file)
166190
}
167191
}
168192
}
169193

194+
extension FileObject {
195+
var metadataDump: String {
196+
var output = ""
197+
customDump(metadata, to: &output)
198+
return output
199+
}
200+
}
201+
170202
#Preview {
171203
AppView(path: [])
172204
}

Examples/SupaDrive/AuthView.swift

+47-12
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,63 @@
55
// Created by Guilherme Souza on 02/07/24.
66
//
77

8+
import Supabase
89
import SwiftUI
910

10-
struct AuthView: View {
11-
@State var userId: String?
11+
struct AuthView<Content: View>: View {
12+
@ViewBuilder var content: (Session) -> Content
13+
14+
@State var session: Session?
1215

1316
var body: some View {
1417
Group {
15-
if let userId {
16-
AppView(path: [userId.lowercased()])
18+
if let session {
19+
content(session)
20+
.environment(\.supabaseSession, session)
1721
} else {
18-
ProgressView()
19-
.task {
20-
do {
21-
userId = try? await supabase.auth.session.user.id.uuidString
22-
if userId == nil {
23-
userId = try await supabase.auth.signIn(email: "[email protected]", password: "The.pass@00!").user.id.uuidString
22+
LoginView()
23+
}
24+
}
25+
.task {
26+
for await (_, session) in supabase.auth.authStateChanges {
27+
self.session = session
28+
}
29+
}
30+
}
31+
32+
struct LoginView: View {
33+
@State var email = ""
34+
@State var password = ""
35+
36+
var body: some View {
37+
Form {
38+
Section {
39+
TextField("Email", text: $email)
40+
SecureField("Password", text: $password)
41+
}
42+
Section {
43+
Button("Sign in") {
44+
Task {
45+
do {
46+
try await supabase.auth.signIn(email: email, password: password)
47+
} catch {
48+
try await supabase.auth.signUp(email: email, password: password)
2449
}
25-
} catch {
26-
dump(error)
2750
}
2851
}
52+
}
2953
}
3054
}
3155
}
3256
}
57+
58+
enum SupabaseSesstionEnvironmentKey: EnvironmentKey {
59+
static var defaultValue: Session?
60+
}
61+
62+
extension EnvironmentValues {
63+
var supabaseSession: Session? {
64+
get { self[SupabaseSesstionEnvironmentKey.self] }
65+
set { self[SupabaseSesstionEnvironmentKey.self] = newValue }
66+
}
67+
}

Examples/SupaDrive/SupaDriveApp.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ struct AppLogger: SupabaseLogger {
2424
struct SupaDriveApp: App {
2525
var body: some Scene {
2626
WindowGroup {
27-
AuthView()
27+
AuthView { session in
28+
AppView(path: [session.user.id.uuidString.lowercased()])
29+
}
2830
}
2931
}
3032
}

0 commit comments

Comments
 (0)