diff --git a/.gitignore b/.gitignore index b16dae7..727ee42 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,6 @@ fastlane/test_output # https://github.com/johnno1962/injectionforxcode iOSInjectionProject/ + +# Private Info +Shared/API.plist diff --git a/README.md b/README.md index 9525043..051cd01 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ To show off SwiftUI's strength in cross-platform development, I did **not** use Mac Catalyst for this project. Instead, common UI code is shared between iOS, macOS, and watchOS. +## Setup +To use this app, you need to create an app for the Reddit API. You can do that [here](https://www.reddit.com/prefs/apps). Choose "Installed app", and set the redirect URI to `redditswiftui://oauth_callback`. Then input the information you got there into the `Shared/API.plist` file. Set the scope in the plist to whatever scope you need. Start with `read,identity,vote` and add more scopes as needed. + ## Project Structure * `Shared` - Models, helpers, API, and any shared Views. * `Reddit-[PLATFORM]` - Each target folder contains a `Views` and `Representable` folder. `Views` holds platform-specific views, and `Representable` contains `UIViewRepresentables` or `NSViewRepresentables`. diff --git a/Reddit-iOS/AppDelegate.swift b/Reddit-iOS/AppDelegate.swift index 2e29d5a..43aa2ca 100644 --- a/Reddit-iOS/AppDelegate.swift +++ b/Reddit-iOS/AppDelegate.swift @@ -21,6 +21,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } + + // MARK: URL Scheme + func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { + print(url) + return true + } // MARK: UISceneSession Lifecycle diff --git a/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Contents.json b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Contents.json new file mode 100644 index 0000000..8d8f4bb --- /dev/null +++ b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "ItunesArtwork@2x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-20x20@1x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-20x20@2x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-20x20@3x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-29x29@1x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-29x29@2x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-29x29@3x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-40x40@1x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-40x40@2x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-40x40@3x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-60x60@2x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-60x60@3x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-76x76@1x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-76x76@2x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/ItunesArtwork@2x.png similarity index 100% rename from Reddit-iOS/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png rename to Reddit-iOS/Assets.xcassets/AppIcon-old.appiconset/ItunesArtwork@2x.png diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Contents.json b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Contents.json index 8d8f4bb..52bff2f 100644 --- a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -3,115 +3,109 @@ { "size" : "20x20", "idiom" : "iphone", - "filename" : "Icon-App-20x20@2x.png", + "filename" : "icon_20@2x.png", "scale" : "2x" }, { "size" : "20x20", "idiom" : "iphone", - "filename" : "Icon-App-20x20@3x.png", + "filename" : "icon_20@3x.png", "scale" : "3x" }, { "size" : "29x29", "idiom" : "iphone", - "filename" : "Icon-App-29x29@1x.png", - "scale" : "1x" - }, - { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "Icon-App-29x29@2x.png", + "filename" : "icon_29@2x.png", "scale" : "2x" }, { "size" : "29x29", "idiom" : "iphone", - "filename" : "Icon-App-29x29@3x.png", + "filename" : "icon_29@3x.png", "scale" : "3x" }, { "size" : "40x40", "idiom" : "iphone", - "filename" : "Icon-App-40x40@2x.png", + "filename" : "icon_40@2x.png", "scale" : "2x" }, { "size" : "40x40", "idiom" : "iphone", - "filename" : "Icon-App-40x40@3x.png", + "filename" : "icon_40@3x.png", "scale" : "3x" }, { "size" : "60x60", "idiom" : "iphone", - "filename" : "Icon-App-60x60@2x.png", + "filename" : "icon_60@2x.png", "scale" : "2x" }, { "size" : "60x60", "idiom" : "iphone", - "filename" : "Icon-App-60x60@3x.png", + "filename" : "icon_60@3x.png", "scale" : "3x" }, { "size" : "20x20", "idiom" : "ipad", - "filename" : "Icon-App-20x20@1x.png", + "filename" : "icon_20@1x.png", "scale" : "1x" }, { "size" : "20x20", "idiom" : "ipad", - "filename" : "Icon-App-20x20@2x.png", + "filename" : "icon_20@2x.png", "scale" : "2x" }, { "size" : "29x29", "idiom" : "ipad", - "filename" : "Icon-App-29x29@1x.png", + "filename" : "icon_29@1x.png", "scale" : "1x" }, { "size" : "29x29", "idiom" : "ipad", - "filename" : "Icon-App-29x29@2x.png", + "filename" : "icon_29@2x.png", "scale" : "2x" }, { "size" : "40x40", "idiom" : "ipad", - "filename" : "Icon-App-40x40@1x.png", + "filename" : "icon_40@1x.png", "scale" : "1x" }, { "size" : "40x40", "idiom" : "ipad", - "filename" : "Icon-App-40x40@2x.png", + "filename" : "icon_40@2x.png", "scale" : "2x" }, { "size" : "76x76", "idiom" : "ipad", - "filename" : "Icon-App-76x76@1x.png", + "filename" : "icon_76@1x.png", "scale" : "1x" }, { "size" : "76x76", "idiom" : "ipad", - "filename" : "Icon-App-76x76@2x.png", + "filename" : "icon_76@2x.png", "scale" : "2x" }, { "size" : "83.5x83.5", "idiom" : "ipad", - "filename" : "Icon-App-83.5x83.5@2x.png", + "filename" : "icon_83.5@2x.png", "scale" : "2x" }, { "size" : "1024x1024", "idiom" : "ios-marketing", - "filename" : "ItunesArtwork@2x.png", + "filename" : "icon_1024@1x.png", "scale" : "1x" } ], diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_1024@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_1024@1x.png new file mode 100644 index 0000000..375f5a1 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_1024@1x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@1x.png new file mode 100644 index 0000000..633f6e7 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@1x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@2x.png new file mode 100644 index 0000000..d01e1c7 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@2x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@3x.png new file mode 100644 index 0000000..63da2b1 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_20@3x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@1x.png new file mode 100644 index 0000000..48090a4 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@1x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@2x.png new file mode 100644 index 0000000..2249f94 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@2x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@3x.png new file mode 100644 index 0000000..b9d16ad Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_29@3x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@1x.png new file mode 100644 index 0000000..d01e1c7 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@1x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@2x.png new file mode 100644 index 0000000..b983ddd Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@2x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@3x.png new file mode 100644 index 0000000..938dbdd Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_40@3x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_60@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_60@2x.png new file mode 100644 index 0000000..938dbdd Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_60@2x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_60@3x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_60@3x.png new file mode 100644 index 0000000..f2cf3d8 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_60@3x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_76@1x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_76@1x.png new file mode 100644 index 0000000..d4c376f Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_76@1x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_76@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_76@2x.png new file mode 100644 index 0000000..71ee235 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_76@2x.png differ diff --git a/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_83.5@2x.png b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_83.5@2x.png new file mode 100644 index 0000000..318a5c2 Binary files /dev/null and b/Reddit-iOS/Assets.xcassets/AppIcon.appiconset/icon_83.5@2x.png differ diff --git a/Reddit-iOS/ContentView.swift b/Reddit-iOS/ContentView.swift index 7e8d409..9a32d2b 100644 --- a/Reddit-iOS/ContentView.swift +++ b/Reddit-iOS/ContentView.swift @@ -8,6 +8,7 @@ import SwiftUI import Request +import Json struct ContentView : View { @State private var subreddit: String = "swift" @@ -17,49 +18,60 @@ struct ContentView : View { @State private var showSubredditSheet: Bool = false var body: some View { - NavigationView { - /// Load the posts - PostList(subreddit: subreddit, sortBy: sortBy) - /// Force inline `NavigationBar` - .navigationBarTitle(Text(""), displayMode: .inline) - .navigationBarItems(leading: HStack { - Button(action: { - self.showSubredditSheet.toggle() - }) { - Text("r/\(self.subreddit)") - } - }, trailing: HStack { - Button(action: { - self.showSortSheet.toggle() - }) { - HStack { - Image(systemName: "arrow.up.arrow.down") - Text(self.sortBy.rawValue) + TabView { + NavigationView { + /// Load the posts + PostList(subreddit: subreddit, sortBy: sortBy) + /// Force inline `NavigationBar` + .navigationBarTitle(Text(""), displayMode: .inline) + .navigationBarItems(leading: HStack { + Button(action: { + self.showSubredditSheet.toggle() + }) { + Text("r/\(self.subreddit)") } - } - }) - /// Sorting method `ActionSheet` - .actionSheet(isPresented: $showSortSheet) { - ActionSheet(title: Text("Sort By:"), buttons: [SortBy.hot, SortBy.top, SortBy.new, SortBy.controversial, SortBy.rising].map { method in - ActionSheet.Button.default(Text(method.rawValue.prefix(1).uppercased() + method.rawValue.dropFirst())) { - self.sortBy = method + }, trailing: HStack { + Button(action: { + self.showSortSheet.toggle() + }) { + HStack { + Image(systemName: "arrow.up.arrow.down") + Text(self.sortBy.rawValue) + } } }) - } - /// Subreddit selection `Popover` - .popover(isPresented: $showSubredditSheet, attachmentAnchor: .point(UnitPoint(x: 20, y: 20))) { - HStack(spacing: 0) { - Text("r/") - TextField("Subreddit", text: self.$subreddit) { - self.showSubredditSheet.toggle() + /// Sorting method `ActionSheet` + .actionSheet(isPresented: $showSortSheet) { + ActionSheet(title: Text("Sort By:"), buttons: [SortBy.hot, SortBy.top, SortBy.new, SortBy.controversial, SortBy.rising].map { method in + ActionSheet.Button.default(Text(method.rawValue.prefix(1).uppercased() + method.rawValue.dropFirst())) { + self.sortBy = method + } + }) + } + /// Subreddit selection `Popover` + .popover(isPresented: $showSubredditSheet, attachmentAnchor: .point(UnitPoint(x: 20, y: 20))) { + HStack(spacing: 0) { + Text("r/") + TextField("Subreddit", text: self.$subreddit) { + self.showSubredditSheet.toggle() + } } + .frame(width: 200) + .padding() + .background(Color("popover")) + .cornerRadius(10) } - .frame(width: 200) - .padding() - .background(Color("popover")) - .cornerRadius(10) + Text("Select a post") + } + .tabItem { + Image(systemName: "list.bullet.below.rectangle") + Text("Feed") + } + ProfileView() + .tabItem { + Image(systemName: "person.crop.circle") + Text("Profile") } - Text("Select a post") } } } diff --git a/Reddit-iOS/Info.plist b/Reddit-iOS/Info.plist index ce77778..10d35ea 100644 --- a/Reddit-iOS/Info.plist +++ b/Reddit-iOS/Info.plist @@ -2,11 +2,6 @@ - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable @@ -21,10 +16,28 @@ $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString 1.0 + CFBundleURLTypes + + + CFBundleTypeRole + Viewer + CFBundleURLName + com.carsonkatri.RedditSwiftUI + CFBundleURLSchemes + + redditswiftui + + + CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes diff --git a/Reddit-iOS/Representable/SafariView.swift b/Reddit-iOS/Representable/SafariView.swift new file mode 100644 index 0000000..7f2bf0c --- /dev/null +++ b/Reddit-iOS/Representable/SafariView.swift @@ -0,0 +1,20 @@ +// +// SafariView.swift +// Reddit +// +// Created by Carson Katri on 8/14/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI +import SafariServices + +struct SafariView: UIViewControllerRepresentable { + let url: URL + + func makeUIViewController(context: UIViewControllerRepresentableContext) -> SFSafariViewController { + SFSafariViewController(url: url) + } + + func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext) {} +} diff --git a/Reddit-iOS/SceneDelegate.swift b/Reddit-iOS/SceneDelegate.swift index d42e7d3..120bee0 100644 --- a/Reddit-iOS/SceneDelegate.swift +++ b/Reddit-iOS/SceneDelegate.swift @@ -21,10 +21,18 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // Use a UIHostingController as window root view controller let window = UIWindow(windowScene: scene as! UIWindowScene) - window.rootViewController = UIHostingController(rootView: ContentView()) + window.rootViewController = UIHostingController(rootView: ContentView().environmentObject(KeyboardObserver())) self.window = window window.makeKeyAndVisible() } + + func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { + if let url = URLComponents(string: URLContexts.first!.url.absoluteString) { + let state = url.queryItems?.first(where: { $0.name == "state" })?.value ?? "" + let code = url.queryItems?.first(where: { $0.name == "code" })?.value ?? "" + API.default.saveToken(code, state: state) + } + } func sceneDidDisconnect(_ scene: UIScene) { // Called as the scene is being released by the system. diff --git a/Reddit-iOS/Views/AddCommentView.swift b/Reddit-iOS/Views/AddCommentView.swift new file mode 100644 index 0000000..7e1aedf --- /dev/null +++ b/Reddit-iOS/Views/AddCommentView.swift @@ -0,0 +1,42 @@ +// +// AddCommentView.swift +// Reddit +// +// Created by Carson Katri on 8/14/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI + +struct AddCommentView: View { + @Binding var text: String + let parentName: String + + var body: some View { + HStack { + TextField("Add Comment", text: $text) + .cornerRadius(4) + Image(systemName: "arrow.up.circle.fill") + .resizable() + .frame(width: 30, height: 30) + .foregroundColor(.blue) + .onTapGesture { + API.default.comment(self.text, on: self.parentName) { + self.text = "" + } + } + } + .padding(10) + .background(Color("popover")) + //.cornerRadius(5) + } +} + +#if DEBUG +struct AddCommentView_Previews: PreviewProvider { + static var previews: some View { + AddCommentView(text: .constant(""), parentName: "t3_helloworld") + //.environment(\.colorScheme, .dark) + } +} +#endif diff --git a/Reddit-iOS/Views/PostList.swift b/Reddit-iOS/Views/PostList.swift index 628dc66..e356f6a 100644 --- a/Reddit-iOS/Views/PostList.swift +++ b/Reddit-iOS/Views/PostList.swift @@ -15,10 +15,7 @@ struct PostList: View { var body: some View { /// Load posts from web and decode as `Listing` - RequestView(Listing.self, Request { - Url(API.subredditURL(subreddit, sortBy)) - Query(["raw_json":"1"]) - }) { listing in + RequestView(Listing.self, API.default.posts(subreddit, sortBy)) { listing in /// List of `PostView`s when loaded List(listing != nil ? listing!.data.children.map { $0.data } : []) { post in NavigationLink(destination: PostDetailView(post: post)) { diff --git a/Reddit-macOS/AppDelegate.swift b/Reddit-macOS/AppDelegate.swift index 85687d7..bdd44cc 100644 --- a/Reddit-macOS/AppDelegate.swift +++ b/Reddit-macOS/AppDelegate.swift @@ -17,7 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSToolbarDelegate, NSTextFie var toolbar: NSToolbar! @ObservedObject var state = ContentViewState() - + func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application window = NSWindow( @@ -36,8 +36,49 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSToolbarDelegate, NSTextFie self.window.toolbar = toolbar window.makeKeyAndOrderFront(nil) + + if API.default.loggedIn { + loginItem.title = "View Profile" + } } - + + func application(_ application: NSApplication, open urls: [URL]) { + if let url = URLComponents(string: urls.first!.absoluteString) { + let state = url.queryItems?.first(where: { $0.name == "state" })?.value ?? "" + let code = url.queryItems?.first(where: { $0.name == "code" })?.value ?? "" + API.default.saveToken(code, state: state) + } + } + + /// OAuth login menu item + @IBOutlet weak var loginItem: NSMenuItem! + @IBAction func login(_ sender: Any) { + let controller = DetailWindowController(rootView: ProfileView(), width: 600, height: 500) + controller.window?.title = "Account" + controller.showWindow(nil) + } + @IBAction func logout(_ sender: Any) { + API.default.logout() + } + + // TODO: Implement this + @IBAction func newPost(_ sender: Any) { + + } + // TODO: Implement this + @IBAction func sendComment(_ sender: Any) { + + } + // TODO: Implement this + @IBAction func upvote(_ sender: Any) { + print("Upvoted command") + } + // TODO: Implement this + @IBAction func downvote(_ sender: Any) { + print("Downvoted command") + } + + func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } diff --git a/Reddit-macOS/Base.lproj/Main.storyboard b/Reddit-macOS/Base.lproj/Main.storyboard index 8825a08..61be279 100644 --- a/Reddit-macOS/Base.lproj/Main.storyboard +++ b/Reddit-macOS/Base.lproj/Main.storyboard @@ -54,64 +54,48 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + + + + + + + + - + - + - + - - - + - + - + + +DQ + - + @@ -673,7 +657,11 @@ - + + + + + diff --git a/Reddit-macOS/ContentView.swift b/Reddit-macOS/ContentView.swift index 7b23bc9..a773d31 100644 --- a/Reddit-macOS/ContentView.swift +++ b/Reddit-macOS/ContentView.swift @@ -15,8 +15,6 @@ struct ContentView : View { @State private var showSortSheet: Bool = false @State private var showSubredditSheet: Bool = false - @State private var selectedPost: String? = nil - @EnvironmentObject private var state: ContentViewState var body: some View { diff --git a/Reddit-macOS/Info.plist b/Reddit-macOS/Info.plist index 8f9941c..0f8c46f 100644 --- a/Reddit-macOS/Info.plist +++ b/Reddit-macOS/Info.plist @@ -18,6 +18,19 @@ $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString 1.0 + CFBundleURLTypes + + + CFBundleTypeRole + Viewer + CFBundleURLName + com.carsonkatri.RedditSwiftUI + CFBundleURLSchemes + + redditswiftui + + + CFBundleVersion 1 LSMinimumSystemVersion diff --git a/Reddit-macOS/Reddit_macOS.entitlements b/Reddit-macOS/Reddit_macOS.entitlements index 6f0a227..0c67376 100644 --- a/Reddit-macOS/Reddit_macOS.entitlements +++ b/Reddit-macOS/Reddit_macOS.entitlements @@ -1,5 +1,5 @@ - + diff --git a/Reddit-macOS/Representable/WebView.swift b/Reddit-macOS/Representable/WebView.swift index f5c6910..a8a1f9f 100644 --- a/Reddit-macOS/Representable/WebView.swift +++ b/Reddit-macOS/Representable/WebView.swift @@ -20,3 +20,4 @@ struct WebView : NSViewRepresentable { nsView.load(URLRequest(url: url)) } } + diff --git a/Reddit-macOS/Views/AddCommentView.swift b/Reddit-macOS/Views/AddCommentView.swift new file mode 100644 index 0000000..0b0eecd --- /dev/null +++ b/Reddit-macOS/Views/AddCommentView.swift @@ -0,0 +1,39 @@ +// +// AddCommentView.swift +// Reddit-macOS +// +// Created by Carson Katri on 8/14/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI + +struct AddCommentView: View { + @Binding var text: String + let parentName: String + + var body: some View { + HStack { + TextField("Add Comment", text: $text) + .cornerRadius(4) + Button(action: { + API.default.comment(self.text, on: self.parentName) { + self.text = "" + } + }) { + Text("Send") + } + } + .padding(10) + .background(Color("popover")) + } +} + +#if DEBUG +struct AddCommentView_Previews: PreviewProvider { + static var previews: some View { + AddCommentView(text: .constant(""), parentName: "t3_helloworld") + .environment(\.colorScheme, .dark) + } +} +#endif diff --git a/Reddit-macOS/Views/Helpers/DetailWindowController.swift b/Reddit-macOS/Views/Helpers/DetailWindowController.swift index c008786..aeb9e53 100644 --- a/Reddit-macOS/Views/Helpers/DetailWindowController.swift +++ b/Reddit-macOS/Views/Helpers/DetailWindowController.swift @@ -11,10 +11,14 @@ import SwiftUI /// A class to handle opening windows for posts when doubling clicking the entry class DetailWindowController: NSWindowController { - convenience init(rootView: RootView) { - let hostingController = NSHostingController(rootView: rootView.frame(width: 400, height: 500)) + convenience init(rootView: RootView, width: CGFloat? = 400, height: CGFloat? = 500) { + let hostingController = NSHostingController(rootView: rootView.frame(width: width, height: height)) let window = NSWindow(contentViewController: hostingController) - window.setContentSize(NSSize(width: 400, height: 500)) + if let width = width, let height = height { + window.setContentSize(NSSize(width: width, height: height)) + } else { + window.contentMinSize = NSSize(width: 400, height: 500) + } self.init(window: window) } } diff --git a/Reddit-macOS/Views/PostList.swift b/Reddit-macOS/Views/PostList.swift index 92605b2..115df39 100644 --- a/Reddit-macOS/Views/PostList.swift +++ b/Reddit-macOS/Views/PostList.swift @@ -13,19 +13,21 @@ struct PostList: View { let subreddit: String let sortBy: SortBy + //@Binding var currentPost: Post? + var body: some View { List { Section(header: Text("\(subreddit) | \(sortBy.rawValue)")) { /// Load posts from web and decode as `Listing` - RequestView(Listing.self, Request { - Url(API.subredditURL(subreddit, sortBy)) - Query(["raw_json":"1"]) - }) { listing in + RequestView(Listing.self, API.default.posts(subreddit, sortBy)) { listing in /// List of `PostView`s when loaded ForEach(listing != nil ? listing!.data.children.map { $0.data } : []) { post in NavigationLink(destination: PostDetailView(post: post)) { PostView(post: post) .tag(post.id) + /*.onTapGesture { + self.currentPost = post + }*/ /// Double-click to open a new window for the `PostDetailView` .onTapGesture(count: 2) { let controller = DetailWindowController(rootView: PostDetailView(post: post)) diff --git a/Reddit-watchOS WatchKit Extension/ContentView.swift b/Reddit-watchOS WatchKit Extension/ContentView.swift index 8a89d47..ca18130 100644 --- a/Reddit-watchOS WatchKit Extension/ContentView.swift +++ b/Reddit-watchOS WatchKit Extension/ContentView.swift @@ -17,10 +17,7 @@ struct ContentView: View { var body: some View { /// Load the `Post`s - RequestView(Listing.self, Request { - Url(API.subredditURL(subreddit, sortBy)) - Query(["raw_json":"1"]) - }) { listing in + RequestView(Listing.self, API.default.posts(subreddit, sortBy)) { listing in /// List of `PostView`s when loaded List { /// Settings `Button` diff --git a/Reddit-watchOS WatchKit Extension/Views/CommentsView.swift b/Reddit-watchOS WatchKit Extension/Views/CommentsView.swift index 8f9b968..2702abd 100644 --- a/Reddit-watchOS WatchKit Extension/Views/CommentsView.swift +++ b/Reddit-watchOS WatchKit Extension/Views/CommentsView.swift @@ -28,10 +28,7 @@ struct CommentsView: View { var body: some View { // Load the comments - RequestView([CommentListing].self, Request { - Url(API.postURL(post.subreddit, post.id)) - Header.Accept(.json) - }) { listings in + RequestView([CommentListing].self, API.default.post(post.subreddit, post.id)) { listings in if listings != nil { // `dropFirst` because `first` is the actual post if listings!.dropFirst().map({ $0.data.children }).flatMap({ $0.map { $0.data } }).count > 0 { diff --git a/Reddit.xcodeproj/project.pbxproj b/Reddit.xcodeproj/project.pbxproj index cdfe60e..ee8135d 100644 --- a/Reddit.xcodeproj/project.pbxproj +++ b/Reddit.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 26C1D7FB22E33FD40057DED1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 26C1D7FA22E33FD40057DED1 /* Assets.xcassets */; }; 26C1D7FE22E33FD40057DED1 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 26C1D7FD22E33FD40057DED1 /* Preview Assets.xcassets */; }; 26C1D80122E33FD40057DED1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 26C1D7FF22E33FD40057DED1 /* LaunchScreen.storyboard */; }; + 26EC1892233AA2A1007456B7 /* privacy_policy.md in Resources */ = {isa = PBXBuildFile; fileRef = 26EC1891233AA2A1007456B7 /* privacy_policy.md */; }; B508E10022F8F6F7002C4C76 /* banner.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = B508E0FF22F8F6F7002C4C76 /* banner.jpeg */; }; B5145A1F22EFD4E6009237BD /* CommentsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26746F0A22ECD4DC00A57918 /* CommentsView.swift */; }; B5145A2122EFD557009237BD /* MetadataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E60CB522EFD2A000A0075B /* MetadataView.swift */; }; @@ -44,9 +45,29 @@ B533A69322F2533900FD3FB2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B533A69122F2533900FD3FB2 /* Main.storyboard */; }; B538997122EFB0CD0008A937 /* SpinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B538996F22EFB0CD0008A937 /* SpinnerView.swift */; }; B538997222EFB0CD0008A937 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B538997022EFB0CD0008A937 /* WebView.swift */; }; + B53F238923037CD60038F5F5 /* UserComments.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F238823037CD60038F5F5 /* UserComments.swift */; }; + B53F238A23037CD60038F5F5 /* UserComments.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F238823037CD60038F5F5 /* UserComments.swift */; }; + B5422495230649F600265473 /* VoteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5422494230649F600265473 /* VoteView.swift */; }; + B5422496230649F600265473 /* VoteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5422494230649F600265473 /* VoteView.swift */; }; + B5422497230649F600265473 /* VoteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5422494230649F600265473 /* VoteView.swift */; }; + B542249923064B0A00265473 /* Votable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542249823064B0A00265473 /* Votable.swift */; }; + B542249A23064B0A00265473 /* Votable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542249823064B0A00265473 /* Votable.swift */; }; + B542249B23064B0A00265473 /* Votable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542249823064B0A00265473 /* Votable.swift */; }; + B542249D23064BAA00265473 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542249C23064BAA00265473 /* Thing.swift */; }; + B542249E23064BAA00265473 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542249C23064BAA00265473 /* Thing.swift */; }; + B542249F23064BAA00265473 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542249C23064BAA00265473 /* Thing.swift */; }; + B54242702304C42E00A1B313 /* AddCommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542426F2304C42E00A1B313 /* AddCommentView.swift */; }; + B54242722304C5B300A1B313 /* AddCommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54242712304C5B300A1B313 /* AddCommentView.swift */; }; + B557366B2303319100E41BE7 /* API.plist in Resources */ = {isa = PBXBuildFile; fileRef = B557366A2303319100E41BE7 /* API.plist */; }; + B557366C2303319700E41BE7 /* API.plist in Resources */ = {isa = PBXBuildFile; fileRef = B557366A2303319100E41BE7 /* API.plist */; }; + B557366D2303319800E41BE7 /* API.plist in Resources */ = {isa = PBXBuildFile; fileRef = B557366A2303319100E41BE7 /* API.plist */; }; + B557366E2303319900E41BE7 /* API.plist in Resources */ = {isa = PBXBuildFile; fileRef = B557366A2303319100E41BE7 /* API.plist */; }; + B557366F2303319900E41BE7 /* API.plist in Resources */ = {isa = PBXBuildFile; fileRef = B557366A2303319100E41BE7 /* API.plist */; }; B561DE3422F3965E003AB95B /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = B561DE3322F3965E003AB95B /* API.swift */; }; B561DE3522F3965E003AB95B /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = B561DE3322F3965E003AB95B /* API.swift */; }; B561DE3622F3965E003AB95B /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = B561DE3322F3965E003AB95B /* API.swift */; }; + B56D30442304625C00CFCF2E /* SafariView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56D30432304625C00CFCF2E /* SafariView.swift */; }; + B56D30482304ABAC00CFCF2E /* KeyboardObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56D30472304ABAC00CFCF2E /* KeyboardObserver.swift */; }; B5712B9A22F2604D00DFF152 /* SharedAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B5712B9922F2604D00DFF152 /* SharedAssets.xcassets */; }; B5712B9B22F2606000DFF152 /* SharedAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B5712B9922F2604D00DFF152 /* SharedAssets.xcassets */; }; B5712B9C22F2606100DFF152 /* SharedAssets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B5712B9922F2604D00DFF152 /* SharedAssets.xcassets */; }; @@ -60,6 +81,7 @@ B57D131A22FD8F3500E7642E /* FlairView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57D131922FD8F3500E7642E /* FlairView.swift */; }; B57D131B22FD8F3A00E7642E /* FlairView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57D131922FD8F3500E7642E /* FlairView.swift */; }; B57D131C22FD8F3B00E7642E /* FlairView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57D131922FD8F3500E7642E /* FlairView.swift */; }; + B589D8842306E29B0034777C /* SFSymbols.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589D8832306E29B0034777C /* SFSymbols.swift */; }; B597CBA022FCC86200389DF6 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B597CB9F22FCC86200389DF6 /* SettingsView.swift */; }; B5A7594822EE8EBA001FD4F1 /* Json in Frameworks */ = {isa = PBXBuildFile; productRef = B5A7594722EE8EBA001FD4F1 /* Json */; }; B5A7594A22EE8EBA001FD4F1 /* Request in Frameworks */ = {isa = PBXBuildFile; productRef = B5A7594922EE8EBA001FD4F1 /* Request */; }; @@ -83,6 +105,14 @@ B5A7599822EFA696001FD4F1 /* Request in Frameworks */ = {isa = PBXBuildFile; productRef = B5A7599722EFA696001FD4F1 /* Request */; }; B5A7599B22EFA797001FD4F1 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A7599A22EFA797001FD4F1 /* WebView.swift */; }; B5A7599D22EFAAF0001FD4F1 /* SpinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A7599C22EFAAF0001FD4F1 /* SpinnerView.swift */; }; + B5C8389323035FB0003AF9FF /* KarmaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389223035FB0003AF9FF /* KarmaView.swift */; }; + B5C8389523035FB3003AF9FF /* KarmaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389223035FB0003AF9FF /* KarmaView.swift */; }; + B5C8389723036387003AF9FF /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389623036387003AF9FF /* ProfileView.swift */; }; + B5C838982303638C003AF9FF /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389623036387003AF9FF /* ProfileView.swift */; }; + B5C8389B23036936003AF9FF /* UserPosts.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389A23036936003AF9FF /* UserPosts.swift */; }; + B5C8389C23036936003AF9FF /* UserPosts.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389A23036936003AF9FF /* UserPosts.swift */; }; + B5C8389E23036B7B003AF9FF /* Me.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389D23036B7B003AF9FF /* Me.swift */; }; + B5C8389F23036B7B003AF9FF /* Me.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C8389D23036B7B003AF9FF /* Me.swift */; }; B5E60CB322EFCC5500A0075B /* PostDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E60CB222EFCC5500A0075B /* PostDetailView.swift */; }; B5E60CB722EFD2FB00A0075B /* MetadataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E60CB522EFD2A000A0075B /* MetadataView.swift */; }; /* End PBXBuildFile section */ @@ -138,7 +168,7 @@ 26B69D1C22E52B7F001AD18F /* PostView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostView.swift; sourceTree = ""; }; 26B69D2022E53213001AD18F /* SortBy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortBy.swift; sourceTree = ""; }; 26BBF27022E66EAD006CC669 /* PostDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailView.swift; sourceTree = ""; }; - 26C1D7F122E33FD30057DED1 /* Reddit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Reddit.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 26C1D7F122E33FD30057DED1 /* Homepage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Homepage.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26C1D7F422E33FD30057DED1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 26C1D7F622E33FD30057DED1 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 26C1D7F822E33FD30057DED1 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -146,6 +176,7 @@ 26C1D7FD22E33FD40057DED1 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 26C1D80022E33FD40057DED1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26C1D80222E33FD40057DED1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 26EC1891233AA2A1007456B7 /* privacy_policy.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = privacy_policy.md; sourceTree = ""; }; B508E0FF22F8F6F7002C4C76 /* banner.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = banner.jpeg; sourceTree = ""; }; B508E10322F8FA16002C4C76 /* SpinnerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinnerView.swift; sourceTree = ""; }; B508E10422F8FA16002C4C76 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = ""; }; @@ -162,7 +193,16 @@ B533A69522F2533900FD3FB2 /* Reddit_macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Reddit_macOS.entitlements; sourceTree = ""; }; B538996F22EFB0CD0008A937 /* SpinnerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinnerView.swift; sourceTree = ""; }; B538997022EFB0CD0008A937 /* WebView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = ""; }; + B53F238823037CD60038F5F5 /* UserComments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserComments.swift; sourceTree = ""; }; + B5422494230649F600265473 /* VoteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoteView.swift; sourceTree = ""; }; + B542249823064B0A00265473 /* Votable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Votable.swift; sourceTree = ""; }; + B542249C23064BAA00265473 /* Thing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Thing.swift; sourceTree = ""; }; + B542426F2304C42E00A1B313 /* AddCommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddCommentView.swift; sourceTree = ""; }; + B54242712304C5B300A1B313 /* AddCommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddCommentView.swift; sourceTree = ""; }; + B557366A2303319100E41BE7 /* API.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = API.plist; sourceTree = ""; }; B561DE3322F3965E003AB95B /* API.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = ""; }; + B56D30432304625C00CFCF2E /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = ""; }; + B56D30472304ABAC00CFCF2E /* KeyboardObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardObserver.swift; sourceTree = ""; }; B5712B9922F2604D00DFF152 /* SharedAssets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = SharedAssets.xcassets; sourceTree = ""; }; B5712BA022F2610200DFF152 /* DetailWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailWindowController.swift; sourceTree = ""; }; B5712BA222F261F100DFF152 /* PostList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostList.swift; sourceTree = ""; }; @@ -170,6 +210,7 @@ B5712BAF22F2807800DFF152 /* ContentViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentViewState.swift; sourceTree = ""; }; B574DF0B22EFB53B00A80981 /* PostView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostView.swift; sourceTree = ""; }; B57D131922FD8F3500E7642E /* FlairView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlairView.swift; sourceTree = ""; }; + B589D8832306E29B0034777C /* SFSymbols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SFSymbols.swift; sourceTree = ""; }; B597CB9F22FCC86200389DF6 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = ""; }; B59DE46B22F8CBD800D8BD1C /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; B5A7595822EF97D6001FD4F1 /* Reddit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Reddit.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -189,6 +230,10 @@ B5A7597F22EF97D9001FD4F1 /* PushNotificationPayload.apns */ = {isa = PBXFileReference; lastKnownFileType = text; path = PushNotificationPayload.apns; sourceTree = ""; }; B5A7599A22EFA797001FD4F1 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = ""; }; B5A7599C22EFAAF0001FD4F1 /* SpinnerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinnerView.swift; sourceTree = ""; }; + B5C8389223035FB0003AF9FF /* KarmaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KarmaView.swift; sourceTree = ""; }; + B5C8389623036387003AF9FF /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = ""; }; + B5C8389A23036936003AF9FF /* UserPosts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPosts.swift; sourceTree = ""; }; + B5C8389D23036B7B003AF9FF /* Me.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Me.swift; sourceTree = ""; }; B5E60CB222EFCC5500A0075B /* PostDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailView.swift; sourceTree = ""; }; B5E60CB522EFD2A000A0075B /* MetadataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetadataView.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -227,6 +272,8 @@ 26B69D1622E51448001AD18F /* Models */ = { isa = PBXGroup; children = ( + B54224A023064BAF00265473 /* Protocols */, + B5C8388C23035257003AF9FF /* OAuth */, 26B69D1722E51451001AD18F /* Post.swift */, 26B69D1922E51E96001AD18F /* Listing.swift */, 26746F0E22ECD94B00A57918 /* Comment.swift */, @@ -239,6 +286,7 @@ isa = PBXGroup; children = ( B59DE46B22F8CBD800D8BD1C /* README.md */, + 26EC1891233AA2A1007456B7 /* privacy_policy.md */, B511A2EB22EE8A2D0062B8D4 /* Shared */, 26C1D7F322E33FD30057DED1 /* Reddit-iOS */, B5A7595F22EF97D6001FD4F1 /* Reddit-watchOS WatchKit App */, @@ -253,7 +301,7 @@ 26C1D7F222E33FD30057DED1 /* Products */ = { isa = PBXGroup; children = ( - 26C1D7F122E33FD30057DED1 /* Reddit.app */, + 26C1D7F122E33FD30057DED1 /* Homepage.app */, B5A7595822EF97D6001FD4F1 /* Reddit.app */, B5A7595B22EF97D6001FD4F1 /* Reddit-watchOS WatchKit App.app */, B5A7596A22EF97D8001FD4F1 /* Reddit-watchOS WatchKit Extension.appex */, @@ -307,6 +355,7 @@ isa = PBXGroup; children = ( B561DE3322F3965E003AB95B /* API.swift */, + B557366A2303319100E41BE7 /* API.plist */, B5712BA622F262A300DFF152 /* Helpers */, 26B69D1622E51448001AD18F /* Models */, B511A2EC22EE8A900062B8D4 /* Views */, @@ -318,6 +367,7 @@ B511A2EC22EE8A900062B8D4 /* Views */ = { isa = PBXGroup; children = ( + B5C8389123035FA4003AF9FF /* OAuth */, 26B69D1C22E52B7F001AD18F /* PostView.swift */, 26BBF27022E66EAD006CC669 /* PostDetailView.swift */, 26746F0A22ECD4DC00A57918 /* CommentsView.swift */, @@ -332,6 +382,7 @@ children = ( B538996F22EFB0CD0008A937 /* SpinnerView.swift */, B538997022EFB0CD0008A937 /* WebView.swift */, + B56D30432304625C00CFCF2E /* SafariView.swift */, ); path = Representable; sourceTree = ""; @@ -357,6 +408,7 @@ children = ( B5712B9F22F260E400DFF152 /* Helpers */, B5712BAD22F2731600DFF152 /* PostList.swift */, + B54242712304C5B300A1B313 /* AddCommentView.swift */, ); path = Views; sourceTree = ""; @@ -386,6 +438,15 @@ path = "Preview Content"; sourceTree = ""; }; + B54224A023064BAF00265473 /* Protocols */ = { + isa = PBXGroup; + children = ( + B542249C23064BAA00265473 /* Thing.swift */, + B542249823064B0A00265473 /* Votable.swift */, + ); + path = Protocols; + sourceTree = ""; + }; B5712B9F22F260E400DFF152 /* Helpers */ = { isa = PBXGroup; children = ( @@ -398,6 +459,8 @@ isa = PBXGroup; children = ( 267E3D9A22ECED9C00675AC7 /* Helpers.swift */, + B56D30472304ABAC00CFCF2E /* KeyboardObserver.swift */, + B589D8832306E29B0034777C /* SFSymbols.swift */, ); path = Helpers; sourceTree = ""; @@ -406,6 +469,7 @@ isa = PBXGroup; children = ( B5712BA222F261F100DFF152 /* PostList.swift */, + B542426F2304C42E00A1B313 /* AddCommentView.swift */, ); path = Views; sourceTree = ""; @@ -467,6 +531,34 @@ path = Representable; sourceTree = ""; }; + B5C8388C23035257003AF9FF /* OAuth */ = { + isa = PBXGroup; + children = ( + B5C8389D23036B7B003AF9FF /* Me.swift */, + ); + path = OAuth; + sourceTree = ""; + }; + B5C8389123035FA4003AF9FF /* OAuth */ = { + isa = PBXGroup; + children = ( + B5C8389923036902003AF9FF /* UserInfo */, + B5C8389623036387003AF9FF /* ProfileView.swift */, + B5C8389223035FB0003AF9FF /* KarmaView.swift */, + B5422494230649F600265473 /* VoteView.swift */, + ); + path = OAuth; + sourceTree = ""; + }; + B5C8389923036902003AF9FF /* UserInfo */ = { + isa = PBXGroup; + children = ( + B5C8389A23036936003AF9FF /* UserPosts.swift */, + B53F238823037CD60038F5F5 /* UserComments.swift */, + ); + path = UserInfo; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -488,7 +580,7 @@ B5A7594922EE8EBA001FD4F1 /* Request */, ); productName = Reddit; - productReference = 26C1D7F122E33FD30057DED1 /* Reddit.app */; + productReference = 26C1D7F122E33FD30057DED1 /* Homepage.app */; productType = "com.apple.product-type.application"; }; B533A68522F2533800FD3FB2 /* Reddit-macOS */ = { @@ -625,6 +717,8 @@ buildActionMask = 2147483647; files = ( 26C1D80122E33FD40057DED1 /* LaunchScreen.storyboard in Resources */, + 26EC1892233AA2A1007456B7 /* privacy_policy.md in Resources */, + B557366B2303319100E41BE7 /* API.plist in Resources */, 26C1D7FE22E33FD40057DED1 /* Preview Assets.xcassets in Resources */, B508E10022F8F6F7002C4C76 /* banner.jpeg in Resources */, 26C1D7FB22E33FD40057DED1 /* Assets.xcassets in Resources */, @@ -640,6 +734,7 @@ B533A69022F2533900FD3FB2 /* Preview Assets.xcassets in Resources */, B533A68D22F2533900FD3FB2 /* Assets.xcassets in Resources */, B5712B9B22F2606000DFF152 /* SharedAssets.xcassets in Resources */, + B557366F2303319900E41BE7 /* API.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -648,6 +743,7 @@ buildActionMask = 2147483647; files = ( B5712B9E22F2606200DFF152 /* SharedAssets.xcassets in Resources */, + B557366C2303319700E41BE7 /* API.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -656,6 +752,7 @@ buildActionMask = 2147483647; files = ( B5712B9D22F2606200DFF152 /* SharedAssets.xcassets in Resources */, + B557366D2303319800E41BE7 /* API.plist in Resources */, B5A7596422EF97D8001FD4F1 /* Assets.xcassets in Resources */, B5A7596222EF97D6001FD4F1 /* Interface.storyboard in Resources */, ); @@ -666,6 +763,7 @@ buildActionMask = 2147483647; files = ( B5712B9C22F2606100DFF152 /* SharedAssets.xcassets in Resources */, + B557366E2303319900E41BE7 /* API.plist in Resources */, B5A7597D22EF97D9001FD4F1 /* Preview Assets.xcassets in Resources */, B5A7597A22EF97D9001FD4F1 /* Assets.xcassets in Resources */, ); @@ -682,18 +780,29 @@ 26BBF27122E66EAD006CC669 /* PostDetailView.swift in Sources */, B5712BA422F2622500DFF152 /* PostList.swift in Sources */, 26C1D7F522E33FD30057DED1 /* AppDelegate.swift in Sources */, + B53F238923037CD60038F5F5 /* UserComments.swift in Sources */, 26C1D7F722E33FD30057DED1 /* SceneDelegate.swift in Sources */, 26B69D2122E53213001AD18F /* SortBy.swift in Sources */, 26B69D1A22E51E96001AD18F /* Listing.swift in Sources */, 26C1D7F922E33FD30057DED1 /* ContentView.swift in Sources */, B5145A1F22EFD4E6009237BD /* CommentsView.swift in Sources */, + B56D30482304ABAC00CFCF2E /* KeyboardObserver.swift in Sources */, B538997222EFB0CD0008A937 /* WebView.swift in Sources */, + B5422495230649F600265473 /* VoteView.swift in Sources */, B5E60CB722EFD2FB00A0075B /* MetadataView.swift in Sources */, + B5C8389E23036B7B003AF9FF /* Me.swift in Sources */, + B56D30442304625C00CFCF2E /* SafariView.swift in Sources */, + B5C8389723036387003AF9FF /* ProfileView.swift in Sources */, B538997122EFB0CD0008A937 /* SpinnerView.swift in Sources */, + B54242702304C42E00A1B313 /* AddCommentView.swift in Sources */, + B542249923064B0A00265473 /* Votable.swift in Sources */, + B542249D23064BAA00265473 /* Thing.swift in Sources */, 26746F0F22ECD94B00A57918 /* Comment.swift in Sources */, + B5C8389323035FB0003AF9FF /* KarmaView.swift in Sources */, 26B69D1D22E52B7F001AD18F /* PostView.swift in Sources */, 26B69D1822E51451001AD18F /* Post.swift in Sources */, B561DE3422F3965E003AB95B /* API.swift in Sources */, + B5C8389B23036936003AF9FF /* UserPosts.swift in Sources */, 267E3D9B22ECED9C00675AC7 /* Helpers.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -705,20 +814,30 @@ B51542DE22F253C7000ADC16 /* SortBy.swift in Sources */, B5712BAE22F2731600DFF152 /* PostList.swift in Sources */, B51542E122F253C7000ADC16 /* MetadataView.swift in Sources */, + B5422497230649F600265473 /* VoteView.swift in Sources */, B51542F122F25C80000ADC16 /* ContentView.swift in Sources */, B51542EC22F25C0E000ADC16 /* PostDetailView.swift in Sources */, + B53F238A23037CD60038F5F5 /* UserComments.swift in Sources */, B51542E022F253C7000ADC16 /* Helpers.swift in Sources */, + B589D8842306E29B0034777C /* SFSymbols.swift in Sources */, B5712BA122F2610200DFF152 /* DetailWindowController.swift in Sources */, B51542DF22F253C7000ADC16 /* Comment.swift in Sources */, B5712BB022F2807800DFF152 /* ContentViewState.swift in Sources */, + B542249B23064B0A00265473 /* Votable.swift in Sources */, B51542DC22F253C7000ADC16 /* Post.swift in Sources */, + B542249F23064BAA00265473 /* Thing.swift in Sources */, B51542E722F25B75000ADC16 /* SpinnerView.swift in Sources */, + B5C8389F23036B7B003AF9FF /* Me.swift in Sources */, B51542DD22F253C7000ADC16 /* Listing.swift in Sources */, + B5C838982303638C003AF9FF /* ProfileView.swift in Sources */, B533A68922F2533800FD3FB2 /* AppDelegate.swift in Sources */, B51542ED22F25C14000ADC16 /* CommentsView.swift in Sources */, + B5C8389523035FB3003AF9FF /* KarmaView.swift in Sources */, B51542EB22F25C05000ADC16 /* PostView.swift in Sources */, B561DE3622F3965E003AB95B /* API.swift in Sources */, B51542EF22F25C23000ADC16 /* WebView.swift in Sources */, + B5C8389C23036936003AF9FF /* UserPosts.swift in Sources */, + B54242722304C5B300A1B313 /* AddCommentView.swift in Sources */, B57D131C22FD8F3B00E7642E /* FlairView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -741,10 +860,13 @@ B5A7597422EF97D8001FD4F1 /* ExtensionDelegate.swift in Sources */, B5145A2122EFD557009237BD /* MetadataView.swift in Sources */, B5A7598E22EFA627001FD4F1 /* Comment.swift in Sources */, + B542249E23064BAA00265473 /* Thing.swift in Sources */, B5A7597822EF97D8001FD4F1 /* NotificationView.swift in Sources */, B5E60CB322EFCC5500A0075B /* PostDetailView.swift in Sources */, + B542249A23064B0A00265473 /* Votable.swift in Sources */, B574DF0C22EFB53B00A80981 /* PostView.swift in Sources */, B561DE3522F3965E003AB95B /* API.swift in Sources */, + B5422496230649F600265473 /* VoteView.swift in Sources */, B5A7599B22EFA797001FD4F1 /* WebView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -914,6 +1036,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = "Reddit-iOS/Preview\\ Content"; DEVELOPMENT_TEAM = FH9CW55WY5; ENABLE_PREVIEWS = YES; @@ -922,8 +1045,8 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.carsonkatri.Reddit; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_BUNDLE_IDENTIFIER = com.carsonkatri.RedditSwiftUI; + PRODUCT_NAME = Homepage; PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTS_MACCATALYST = NO; SWIFT_VERSION = 5.0; @@ -939,6 +1062,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = "Reddit-iOS/Preview\\ Content"; DEVELOPMENT_TEAM = FH9CW55WY5; ENABLE_PREVIEWS = YES; @@ -947,8 +1071,8 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.carsonkatri.Reddit; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_BUNDLE_IDENTIFIER = com.carsonkatri.RedditSwiftUI; + PRODUCT_NAME = Homepage; PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTS_MACCATALYST = NO; SWIFT_VERSION = 5.0; @@ -1183,7 +1307,7 @@ repositoryURL = "https://github.com/carson-katri/swift-request"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 1.1.1; + minimumVersion = 1.2.2; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/Reddit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Reddit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index b1a2783..cdd893d 100644 --- a/Reddit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Reddit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/carson-katri/swift-request", "state": { "branch": null, - "revision": "5de85a849f22e56471af6cb0367bd575519b131f", - "version": "1.1.1" + "revision": "8d297a4cb8913beb463843c99751fd5671b35cef", + "version": "1.2.2" } } ] diff --git a/Shared/API.plist b/Shared/API.plist new file mode 100644 index 0000000..2c6ae23 --- /dev/null +++ b/Shared/API.plist @@ -0,0 +1,12 @@ + + + + + scope + read,identity,vote + redirectUri + + clientId + + + diff --git a/Shared/API.swift b/Shared/API.swift index def2163..a29dc9a 100644 --- a/Shared/API.swift +++ b/Shared/API.swift @@ -7,13 +7,202 @@ // import Foundation +import Request -struct API { - static func subredditURL(_ subreddit: String, _ sortBy: SortBy) -> String { - return "https://www.reddit.com/r/\(subreddit)/\(sortBy.rawValue).json" +class API { + static let `default` = API() + + init() { + if let refreshToken = self.refreshToken { + Request { + Url("https://www.reddit.com/api/v1/access_token") + Method(.post) + Header.Authorization(.basic(username: clientId, password: "")) + Query(["grant_type":"refresh_token","refresh_token":refreshToken]) + } + .onJson { json in + print(json) + if let token = json.access_token.stringOptional { + self.token = token + } + } + .call() + } + } + + func posts(_ subreddit: String, _ sortBy: SortBy) -> Request { + if loggedIn { + return authedRequest("https://oauth.reddit.com/r/\(subreddit)/\(sortBy.rawValue)") + } else { + return Request { + Url("https://www.reddit.com/r/\(subreddit)/\(sortBy.rawValue).json") + Query(["raw_json":"1"]) + } + } + } + + func userPostsURL(for username: String) -> String { + return "https://www.reddit.com/user/\(username)/submitted.json" + } + + func post(_ subreddit: String, _ id: String) -> Request { + if loggedIn { + return authedRequest("https://oauth.reddit.com/r/\(subreddit)/comments/\(id)") + } else { + return Request { + Url("https://www.reddit.com/r/\(subreddit)/\(id).json") + Query(["raw_json":"1"]) + } + } + } + + func userCommentsURL(for username: String) -> String { + return "https://www.reddit.com/user/\(username)/comments.json" + } + + // MARK: OAuth + private static let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + let randomString: String = String((0..<10).map{ _ in letters.randomElement()! }) + + var config: [String:AnyObject] { + var format = PropertyListSerialization.PropertyListFormat.xml + let path = Bundle.main.path(forResource: "API", ofType: "plist") + if let xml = FileManager.default.contents(atPath: path!) { + do { + return try PropertyListSerialization.propertyList(from: xml, options: .mutableContainersAndLeaves, format: &format) as! [String:AnyObject] + } catch { + print(error) + } + } + return [:] + } + + var clientId: String { + config["clientId"] as! String + } + + var redirectUri: String { + config["redirectUri"] as! String + } + + var scope: String { + config["scope"] as! String + } + + func oauthLoginURL() -> String { + return "https://www.reddit.com/api/v1/authorize.compact?client_id=\(clientId)&response_type=code&state=\(randomString)&redirect_uri=\(redirectUri)&duration=permanent&scope=\(scope)" + } + + var token: String? { + get { + UserDefaults.standard.string(forKey: "oauth_token") + } + set { + UserDefaults.standard.set(newValue, forKey: "oauth_token") + } + } + + var refreshToken: String? { + get { + UserDefaults.standard.string(forKey: "refresh_token") + } + set { + UserDefaults.standard.set(newValue, forKey: "refresh_token") + } + } + + func saveToken(_ code: String, state: String) { + if state == randomString { + Request { + Url("https://www.reddit.com/api/v1/access_token") + Method(.post) + Header.Authorization(.basic(username: clientId, password: "")) + Query(["grant_type":"authorization_code","code":code,"redirect_uri":redirectUri]) + } + .onJson { json in + if let token = json.access_token.stringOptional { + self.token = token + } + if let refreshToken = json.refresh_token.stringOptional { + self.refreshToken = refreshToken + } + } + .call() + } else { + print("\(state) doesn't match \(randomString)") + } + } + + var loggedIn: Bool { + return token != nil && refreshToken != nil + } + + func logout() { + token = nil + refreshToken = nil + } + + func authedRequest(_ url: String) -> Request { + Request { + Url(url) + Header.Authorization(.bearer(API.default.token!)) + } + } + + var karma: Request { + authedRequest("https://oauth.reddit.com/api/v1/me/karma") + } + + var me: Request { + authedRequest("https://oauth.reddit.com/api/v1/me") + } + + func comment(_ text: String, on parentId: String, complete: @escaping (() -> Void)) { + Request { + Url("https://oauth.reddit.com/api/comment") + Method(.post) + Header.Authorization(.bearer(API.default.token!)) + Query([ + "api_type": "json", + "thing_id": parentId, + "text": text + ]) + Header.Any(key: "User-Agent", value: "Reddit SwiftUI/v1") + } + .onData { _ in + complete() + } + .call() + } + + // MARK: Voting + private func vote(_ id: String, direction: Int, complete: @escaping (() -> Void)) { + Request { + Url("https://oauth.reddit.com/api/vote") + Method(.post) + Header.Authorization(.bearer(API.default.token!)) + Query([ + "id": id, + "dir": "\(direction)", + "rank": "2" + ]) + Header.Any(key: "User-Agent", value: "Reddit SwiftUI/v1") + } + .onData { _ in + complete() + } + .call() + } + + func upvote(_ id: String, complete: @escaping (() -> Void)) { + vote(id, direction: 1, complete: complete) + } + + func downvote(_ id: String, complete: @escaping (() -> Void)) { + vote(id, direction: -1, complete: complete) } - static func postURL(_ subreddit: String, _ id: String) -> String { - return "https://www.reddit.com/r/\(subreddit)/\(id).json" + func unvote(_ id: String, complete: @escaping (() -> Void)) { + vote(id, direction: 0, complete: complete) } } diff --git a/Shared/Helpers/Helpers.swift b/Shared/Helpers/Helpers.swift index 5f2bdd9..1bd9c91 100644 --- a/Shared/Helpers/Helpers.swift +++ b/Shared/Helpers/Helpers.swift @@ -17,9 +17,8 @@ func timeSince(_ interval: TimeInterval) -> String { /// `SwiftUI` compatibility #if os(macOS) -extension Image { - init(systemName: String) { - self.init(nsImage: NSImage()) - } +func Image(systemName: String) -> some View { + SFSymbol.named(systemName) + .frame(width: 15, height: 15) } #endif diff --git a/Shared/Helpers/KeyboardObserver.swift b/Shared/Helpers/KeyboardObserver.swift new file mode 100644 index 0000000..21b80e9 --- /dev/null +++ b/Shared/Helpers/KeyboardObserver.swift @@ -0,0 +1,31 @@ +// +// KeyboardObserver.swift +// Reddit +// +// Created by Carson Katri on 8/14/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI +import Combine + +/// Watch for changes in the keyboard to adjust content positioning to fit onscreen. +final class KeyboardObserver: ObservableObject { + @Published var keyboardHeight: CGFloat = 0 + + init() { + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + } + + @objc func keyboardWillShow(_ notification: Notification) { + if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + let keyboardRectangle = keyboardFrame.cgRectValue + keyboardHeight = keyboardRectangle.height + } + } + + @objc func keyboardWillHide(_ notification: Notification) { + keyboardHeight = 0 + } +} diff --git a/Shared/Helpers/SFSymbols.swift b/Shared/Helpers/SFSymbols.swift new file mode 100644 index 0000000..5f78dd1 --- /dev/null +++ b/Shared/Helpers/SFSymbols.swift @@ -0,0 +1,133 @@ +// +// SFSymbols.swift +// Reddit-macOS +// +// Created by Carson Katri on 8/16/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI + +struct SFSymbol { + static func named(_ name: String) -> AnyView { + switch name { + case "arrow.up": + return AnyView(UpArrow()) + case "arrow.down": + return AnyView(DownArrow()) + case "pin.fill": + return AnyView(Pin()) + case "text.bubble": + return AnyView(Bubble()) + case "clock": + return AnyView(Clock()) + default: + return AnyView(Text("")) + } + } + + struct UpArrow : View { + var body: some View { + ZStack { + Rectangle() + .frame(width: 15, height: 15) + .foregroundColor(Color.primary.opacity(0.1)) + .cornerRadius(4) + Rectangle() + .frame(width: 1, height: 8) + .cornerRadius(0.5) + Rectangle() + .frame(width: 1, height: 5) + .cornerRadius(0.5) + .offset(x: -3, y: -1) + .rotationEffect(Angle(degrees: 45)) + Rectangle() + .frame(width: 1, height: 5) + .cornerRadius(0.5) + .offset(x: 3, y: -1) + .rotationEffect(Angle(degrees: -45)) + } + } + } + struct DownArrow : View { + var body: some View { + UpArrow() + .rotationEffect(Angle(degrees: 180)) + } + } + + struct Pin : View { + var body: some View { + ZStack { + Path { path in + path.move(to: CGPoint(x: 4, y: 0)) + path.addLine(to: CGPoint(x: 8, y: 0)) + path.addLine(to: CGPoint(x: 6, y: 2)) + path.addLine(to: CGPoint(x: 5.5, y: 4)) + path.addLine(to: CGPoint(x: 7, y: 6)) + path.addLine(to: CGPoint(x: 4.5, y: 6)) + path.addLine(to: CGPoint(x: 4.5, y: 10)) + path.addLine(to: CGPoint(x: 3.5, y: 10)) + path.addLine(to: CGPoint(x: 3.5, y: 6)) + path.addLine(to: CGPoint(x: 1, y: 6)) + path.addLine(to: CGPoint(x: 2.5, y: 4)) + path.addLine(to: CGPoint(x: 2, y: 2)) + path.addLine(to: CGPoint(x: 0, y: 0)) + } + } + } + } + + struct Bubble : View { + var body: some View { + ZStack { + Rectangle() + .frame(width: 8, height: 7) + .foregroundColor(Color.primary.opacity(0)) + .border(Color.primary) + .cornerRadius(2) + Rectangle() + .frame(width: 1, height: 2) + .offset(x: -2, y: 4) + } + } + } + + struct Clock : View { + var body: some View { + ZStack { + Rectangle() + .frame(width: 10, height: 10) + .foregroundColor(Color.primary.opacity(0)) + .border(Color.primary) + .cornerRadius(3) + Rectangle() + .frame(width: 1, height: 5) + .offset(y: -2.5) + Rectangle() + .frame(width: 1, height: 5) + .offset(y: -2.5) + .rotationEffect(Angle(degrees: 90)) + } + } + } +} + +#if DEBUG +struct SFSymbols_Previews: PreviewProvider { + static var previews: some View { + Group { + SFSymbol.UpArrow() + .frame(width: 10, height: 10) + SFSymbol.DownArrow() + .frame(width: 10, height: 10) + SFSymbol.Pin() + .frame(width: 10, height: 10) + SFSymbol.Bubble() + .frame(width: 10, height: 10) + SFSymbol.Clock() + .frame(width: 10, height: 10) + } + } +} +#endif diff --git a/Shared/Models/Comment.swift b/Shared/Models/Comment.swift index a8ba8d2..e51e95e 100644 --- a/Shared/Models/Comment.swift +++ b/Shared/Models/Comment.swift @@ -6,30 +6,40 @@ // Copyright © 2019 Carson Katri. All rights reserved. // -import Foundation - /// A comment from the Reddit API -struct Comment: Decodable { +struct Comment: Thing, Decodable { let id: String + let name: String let author: String let score: Int + var likes: Bool? let body: String? + let parent_id: String? + let stickied: Bool let replies: CommentListing? enum CommentKeys: String, CodingKey { case id + case name case author case score + case likes case body case replies + case parent_id + case stickied } init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CommentKeys.self) id = try values.decode(String.self, forKey: .id) + name = try values.decode(String.self, forKey: .name) author = try values.decode(String.self, forKey: .author) score = try values.decode(Int.self, forKey: .score) + likes = try? values.decode(Bool.self, forKey: .likes) body = try? values.decode(String.self, forKey: .body) + stickied = try values.decode(Bool.self, forKey: .stickied) + parent_id = try? values.decode(String.self, forKey: .parent_id) if let replies = try? values.decode(CommentListing.self, forKey: .replies) { self.replies = replies diff --git a/Shared/Models/OAuth/Me.swift b/Shared/Models/OAuth/Me.swift new file mode 100644 index 0000000..7860ecf --- /dev/null +++ b/Shared/Models/OAuth/Me.swift @@ -0,0 +1,15 @@ +// +// Me.swift +// Reddit +// +// Created by Carson Katri on 8/13/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +struct Me: Decodable { + let name: String + let id: String + let comment_karma: Int + let link_karma: Int + let coins: Int +} diff --git a/Shared/Models/Post.swift b/Shared/Models/Post.swift index 99065df..1ab03ab 100644 --- a/Shared/Models/Post.swift +++ b/Shared/Models/Post.swift @@ -9,7 +9,7 @@ import Foundation /// A post from the Reddit API -struct Post: Decodable, Identifiable { +struct Post: Thing, Decodable, Identifiable { let title: String let name: String let id: String @@ -21,6 +21,7 @@ struct Post: Decodable, Identifiable { let author: String let subreddit: String let score: Int + var likes: Bool? let num_comments: Int let stickied: Bool let created_utc: Double diff --git a/Shared/Models/Protocols/Thing.swift b/Shared/Models/Protocols/Thing.swift new file mode 100644 index 0000000..0383a6d --- /dev/null +++ b/Shared/Models/Protocols/Thing.swift @@ -0,0 +1,13 @@ +// +// Thing.swift +// Reddit +// +// Created by Carson Katri on 8/15/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +protocol Thing: Votable { + var name: String { get } + var id: String { get } + var stickied: Bool { get } +} diff --git a/Shared/Models/Protocols/Votable.swift b/Shared/Models/Protocols/Votable.swift new file mode 100644 index 0000000..82a2b1f --- /dev/null +++ b/Shared/Models/Protocols/Votable.swift @@ -0,0 +1,12 @@ +// +// Votable.swift +// Reddit +// +// Created by Carson Katri on 8/15/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +protocol Votable { + var score: Int { get } + var likes: Bool? { get set } +} diff --git a/Shared/Views/CommentsView.swift b/Shared/Views/CommentsView.swift index 774814a..6d42a52 100644 --- a/Shared/Views/CommentsView.swift +++ b/Shared/Views/CommentsView.swift @@ -19,10 +19,7 @@ struct CommentsView: View { var body: some View { // Load the comments - RequestView([CommentListing].self, Request { - Url(API.postURL(post.subreddit, post.id)) - Header.Accept(.json) - }) { listings in + RequestView([CommentListing].self, API.default.post(post.subreddit, post.id)) { listings in if listings != nil { // `dropFirst` because `first` is the actual post if listings!.dropFirst().map({ $0.data.children }).flatMap({ $0.map { $0.data } }).count > 0 { @@ -41,11 +38,11 @@ struct CommentsView: View { } struct CommentView: View { - let comment: Comment + @State var comment: Comment let nestLevel: Int var body: some View { - Group { + return Group { HStack { /// Left border for nested comments if nestLevel > 0 { @@ -57,8 +54,7 @@ struct CommentView: View { VStack(alignment: .leading) { HStack { Text(comment.author) - Image(systemName: "arrow.up") - Text("\(comment.score)") + VoteView(votable: $comment) } .font(.caption) .opacity(0.75) @@ -66,7 +62,7 @@ struct CommentView: View { } } .padding(.leading, CGFloat(self.nestLevel * 10)) - .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: Alignment.topLeading) + .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading) /// Recursive comments if comment.replies != nil { ForEach(comment.replies!.data.children.map { $0.data }, id: \.id) { reply in diff --git a/Shared/Views/MetadataView.swift b/Shared/Views/MetadataView.swift index 58a31e7..32f1228 100644 --- a/Shared/Views/MetadataView.swift +++ b/Shared/Views/MetadataView.swift @@ -9,7 +9,7 @@ import SwiftUI struct MetadataView: View { - let post: Post + @State var post: Post let spaced: Bool var stickied: some View { @@ -33,8 +33,9 @@ struct MetadataView: View { Spacer() } stickied + VoteView(votable: $post) /// Tuples store the SF Symbols, text, and color - ForEach([("arrow.up", "\(post.score)", Color.orange), ("text.bubble", "\(post.num_comments)", Color.primary), ("clock", "\(timeSince(post.created_utc))", Color.primary)], id: \.0) { data in + ForEach([("text.bubble", "\(post.num_comments)", Color.primary), ("clock", "\(timeSince(post.created_utc))", Color.primary)], id: \.0) { data in Group { Image(systemName: data.0) Text(data.1) diff --git a/Shared/Views/OAuth/KarmaView.swift b/Shared/Views/OAuth/KarmaView.swift new file mode 100644 index 0000000..f6938ec --- /dev/null +++ b/Shared/Views/OAuth/KarmaView.swift @@ -0,0 +1,36 @@ +// +// KarmaView.swift +// Reddit +// +// Created by Carson Katri on 8/13/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI + +struct KarmaView: View { + let link: Int + let comment: Int + + var body: some View { + HStack { + ForEach([("Post", link), ("Comment", comment)], id: \.0) { karma in + VStack { + Text("\(karma.1)") + .font(.largeTitle) + .bold() + Text("\(karma.0) Karma") + .foregroundColor(.secondary) + } + } + } + } +} + +#if DEBUG +struct KarmaView_Previews: PreviewProvider { + static var previews: some View { + return KarmaView(link: 2520, comment: 10) + } +} +#endif diff --git a/Shared/Views/OAuth/ProfileView.swift b/Shared/Views/OAuth/ProfileView.swift new file mode 100644 index 0000000..b2c7c05 --- /dev/null +++ b/Shared/Views/OAuth/ProfileView.swift @@ -0,0 +1,70 @@ +// +// ProfileView.swift +// Reddit +// +// Created by Carson Katri on 8/13/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI +import Request + +struct ProfileView: View { + var body: some View { + NavigationView { + if API.default.loggedIn { + RequestView(Me.self, API.default.me) { me in + var list: AnyView! + if me != nil { + list = AnyView(List { + Section(header: Text("Karma")) { + KarmaView(link: me!.link_karma, comment: me!.comment_karma) + .frame(maxWidth: .infinity) + } + Section(header: Text("Overview")) { + ForEach([ + (name: "Posts", icon: "list.bullet.below.rectangle", destination: AnyView(UserPosts(username: me!.name))), + (name: "Comments", icon: "text.bubble", destination: AnyView(UserComments(username: me!.name))) + ], id: \.name) { item in + NavigationLink(destination: item.destination) { + HStack { + Image(systemName: item.icon) + Text(item.name) + } + } + } + } + Section { + Button(action: { + print("Logout") + API.default.logout() + }) { + Text("Logout") + } + } + }) + } else { + list = AnyView(SpinnerView()) + } + #if !os(macOS) + list = AnyView(list.navigationBarTitle(me != nil ? me!.name : "")) + #endif + return TupleView<(AnyView, SpinnerView)>((list, SpinnerView())) + } + } else { + #if os(macOS) + Button(action: { + NSWorkspace.shared.open(URL(string: API.default.oauthLoginURL())!) + }) { + Text("Login") + } + #else + SafariView(url: URL(string: API.default.oauthLoginURL())!) + .navigationBarTitle("Login") + #endif + } + Text("Select a category") + .frame(maxWidth: .infinity, maxHeight: .infinity) + } + } +} diff --git a/Shared/Views/OAuth/UserInfo/UserComments.swift b/Shared/Views/OAuth/UserInfo/UserComments.swift new file mode 100644 index 0000000..2871304 --- /dev/null +++ b/Shared/Views/OAuth/UserInfo/UserComments.swift @@ -0,0 +1,32 @@ +// +// UserComments.swift +// Reddit +// +// Created by Carson Katri on 8/13/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI +import Request + +struct UserComments: View { + let username: String + + var body: some View { + let commentsList = RequestView(CommentListing.self, Request { + Url(API.default.userCommentsURL(for: username)) + Query(["raw_json":"1"]) + }) { (listing: CommentListing?) in + List(listing != nil ? listing!.data.children.map { $0.data } : [], id: \.id) { comment in + CommentView(comment: comment, nestLevel: 0) + } + .listStyle(DefaultListStyle()) + SpinnerView() + } + #if os(macOS) + return commentsList + #else + return commentsList.navigationBarTitle(Text("Comments"), displayMode: .inline) + #endif + } +} diff --git a/Shared/Views/OAuth/UserInfo/UserPosts.swift b/Shared/Views/OAuth/UserInfo/UserPosts.swift new file mode 100644 index 0000000..e057f05 --- /dev/null +++ b/Shared/Views/OAuth/UserInfo/UserPosts.swift @@ -0,0 +1,34 @@ +// +// UserList.swift +// Reddit +// +// Created by Carson Katri on 8/13/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI +import Request + +struct UserPosts: View { + let username: String + + var body: some View { + let postsList = RequestView(Listing.self, Request { + Url(API.default.userPostsURL(for: username)) + Query(["raw_json":"1"]) + }) { (listing: Listing?) in + List(listing != nil ? listing!.data.children.map { $0.data } : []) { post in + NavigationLink(destination: PostDetailView(post: post)) { + PostView(post: post) + } + } + .listStyle(DefaultListStyle()) + SpinnerView() + } + #if os(macOS) + return postsList + #else + return postsList.navigationBarTitle(Text("Posts"), displayMode: .inline) + #endif + } +} diff --git a/Shared/Views/OAuth/VoteView.swift b/Shared/Views/OAuth/VoteView.swift new file mode 100644 index 0000000..72abe0f --- /dev/null +++ b/Shared/Views/OAuth/VoteView.swift @@ -0,0 +1,49 @@ +// +// VoteView.swift +// Reddit +// +// Created by Carson Katri on 8/15/19. +// Copyright © 2019 Carson Katri. All rights reserved. +// + +import SwiftUI + +struct VoteView : View { + @Binding var votable: VotableThing + + var body: some View { + Group { + Image(systemName: "arrow.up") + .onTapGesture { + if API.default.loggedIn { + if self.votable.likes == true { + API.default.unvote(self.votable.name) { + self.votable.likes = nil + } + } else { + API.default.upvote(self.votable.name) { + self.votable.likes = true + } + } + } + } + .foregroundColor(votable.likes == true ? Color.orange : Color.primary) + Text("\(votable.score + (votable.likes == nil ? 0 : (votable.likes == true ? 1 : -1)))") + Image(systemName: "arrow.down") + .onTapGesture { + if API.default.loggedIn { + if self.votable.likes == false { + API.default.unvote(self.votable.name) { + self.votable.likes = nil + } + } else { + API.default.downvote(self.votable.name) { + self.votable.likes = false + } + } + } + } + .foregroundColor(votable.likes == false ? Color.blue : Color.primary) + } + } +} diff --git a/Shared/Views/PostDetailView.swift b/Shared/Views/PostDetailView.swift index 2fdf9b4..6abc65a 100644 --- a/Shared/Views/PostDetailView.swift +++ b/Shared/Views/PostDetailView.swift @@ -11,6 +11,10 @@ import Request struct PostDetailView: View { let post: Post + @State private var comment: String = "" + #if os(iOS) + @EnvironmentObject private var keyboardObserver: KeyboardObserver + #endif var title: some View { let vstack = VStack(alignment: .leading) { @@ -25,44 +29,58 @@ struct PostDetailView: View { return vstack #elseif os(macOS) /// Fill window width - return vstack.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: Alignment.topLeading) + return vstack.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading) #endif } var body: some View { - let list = List { - // Image - if post.url.contains(".jpg") || post.url.contains(".png") { - RequestImage(Url(post.url), contentMode: .fit) - .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: Alignment.topLeading) - } - // GIF - if post.url.contains(".gif") { - WebView(url: URL(string: post.url)!) - .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: Alignment.topLeading) - } - // Title - if post.selftext == "" { - NavigationLink(destination: WebView(url: URL(string: post.url)!)) { + let list = ZStack(alignment: Alignment.bottomLeading) { + List { + // Image + if post.url.contains(".jpg") || post.url.contains(".png") { + RequestImage(Url(post.url), contentMode: .fit) + .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading) + } + // GIF + if post.url.contains(".gif") { + WebView(url: URL(string: post.url)!) + .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading) + } + // Title + if post.selftext == "" { + NavigationLink(destination: WebView(url: URL(string: post.url)!)) { + title + } + } else { title } - } else { - title - } - // Body - if post.selftext != "" { - Text(post.selftext) - } - if post.flairs.count > 0 { - FlairView(flairs: post.flairs) + // Body + if post.selftext != "" { + Text(post.selftext) + } + if post.flairs.count > 0 { + FlairView(flairs: post.flairs) + } + MetadataView(post: post, spaced: true) + CommentsView(post: post) } - MetadataView(post: post, spaced: true) - CommentsView(post: post) + .padding(.bottom, 40) + /// Comment text field + #if os(macOS) + AddCommentView(text: $comment, parentName: self.post.name) + #else + AddCommentView(text: $comment, parentName: self.post.name) + .offset(y: keyboardObserver.keyboardHeight > 0 ? -(keyboardObserver.keyboardHeight - 50) : 0) + .animation(.spring()) + #endif } #if os(iOS) return list.navigationBarTitle(Text("r/\(post.subreddit)"), displayMode: .inline) #else - return list + // TODO: Implement `onCommand` + return list/*.onCommand(#selector(AppDelegate.upvote(_:))) { + print("Command received in View") + }*/ #endif } } diff --git a/privacy_policy.md b/privacy_policy.md new file mode 100644 index 0000000..deede3a --- /dev/null +++ b/privacy_policy.md @@ -0,0 +1,56 @@ +## Privacy Policy (for AppStore deploys) + +Carson Katri built the Homepage for Reddit app as an Open Source app. This SERVICE is provided by Carson Katri at no cost and is intended for use as is. + +This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service. + +If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy. + +The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Homepage for Reddit unless otherwise defined in this Privacy Policy. + +**Information Collection and Use** + +For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your device and is not collected by me in any way. + +**Log Data** + +I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics. + +**Cookies** + +Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory. + +This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service. + +**Service Providers** + +I may employ third-party companies and individuals due to the following reasons: + +* To facilitate our Service; +* To provide the Service on our behalf; +* To perform Service-related services; or +* To assist us in analyzing how our Service is used. + +I want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose. + +**Security** + +I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security. + +**Links to Other Sites** + +This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services. + +**Children’s Privacy** + +These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13\. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do necessary actions. + +**Changes to This Privacy Policy** + +I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page. These changes are effective immediately after they are posted on this page. + +**Contact Us** + +If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at carson.katri@gmail.com. + +This privacy policy page was created at [privacypolicytemplate.net](https://privacypolicytemplate.net) and modified/generated by [App Privacy Policy Generator](https://app-privacy-policy-generator.firebaseapp.com/)