From e6293b2fc4e6408fe81d1eed60073eb8a60664c6 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Thu, 12 Jun 2025 15:30:59 -0700 Subject: [PATCH] Add a refresh button, loading status, and show errors if there is any, along with some mobile improvements --- Berry Leaderboards.xcodeproj/project.pbxproj | 12 ++-- Berry Leaderboards/ContentView.swift | 63 +++++++++++++++----- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/Berry Leaderboards.xcodeproj/project.pbxproj b/Berry Leaderboards.xcodeproj/project.pbxproj index 08f7948..a5e0b07 100644 --- a/Berry Leaderboards.xcodeproj/project.pbxproj +++ b/Berry Leaderboards.xcodeproj/project.pbxproj @@ -389,7 +389,7 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; + IPHONEOS_DEPLOYMENT_TARGET = 16.6; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.5; @@ -428,7 +428,7 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; + IPHONEOS_DEPLOYMENT_TARGET = 16.6; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 13.5; @@ -453,7 +453,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = UA7XPYM6ZB; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; + IPHONEOS_DEPLOYMENT_TARGET = 16.6; MACOSX_DEPLOYMENT_TARGET = 13.5; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "xyz.lncvrt.Berry-LeaderboardsTests"; @@ -475,7 +475,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = UA7XPYM6ZB; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; + IPHONEOS_DEPLOYMENT_TARGET = 16.6; MACOSX_DEPLOYMENT_TARGET = 13.5; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "xyz.lncvrt.Berry-LeaderboardsTests"; @@ -496,7 +496,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = UA7XPYM6ZB; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; + IPHONEOS_DEPLOYMENT_TARGET = 16.6; MACOSX_DEPLOYMENT_TARGET = 13.5; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "xyz.lncvrt.Berry-LeaderboardsUITests"; @@ -517,7 +517,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = UA7XPYM6ZB; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; + IPHONEOS_DEPLOYMENT_TARGET = 16.6; MACOSX_DEPLOYMENT_TARGET = 13.5; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "xyz.lncvrt.Berry-LeaderboardsUITests"; diff --git a/Berry Leaderboards/ContentView.swift b/Berry Leaderboards/ContentView.swift index 75513a3..12334cb 100644 --- a/Berry Leaderboards/ContentView.swift +++ b/Berry Leaderboards/ContentView.swift @@ -9,39 +9,74 @@ import SwiftUI struct ContentView: View { @State private var players: [Player] = [] + @State private var loading = false + @State private var errorMessage: String? var body: some View { ZStack { #if os(macOS) VisualEffectBlur() .ignoresSafeArea() + #elseif os(iOS) + Color(red: 24/255, green: 24/255, blue: 24/255) + .ignoresSafeArea() #endif - List(players) { player in + + VStack(spacing: 8) { HStack { - Text(player.username) Spacer() - Text("\(player.score)") - .bold() + Button("Refresh") { + Task { await loadPlayers() } + } + .padding(.top, 8) + .padding(.trailing, 12) + } + + if loading { + Text("Loading...").padding() + } else if let errorMessage { + Text("Error: \(errorMessage)") + .foregroundColor(.red) + .padding() + } + + List(players) { player in + HStack { + Text(player.username) + Spacer() + Text("\(player.score)").bold() + } + .padding(.vertical, 4) + #if os(macOS) + .listRowBackground(Color.clear) + #elseif os(iOS) + .listRowBackground(Color(red: 48/255, green: 48/255, blue: 48/255)) + #endif + } + .background(Color.clear) + #if os(macOS) + .scrollContentBackground(.hidden) + #elseif os(iOS) + .scrollContentBackground(.hidden) + .listStyle(.plain) + #endif + .task { + await loadPlayers() } - .padding(.vertical, 4) - .listRowBackground(Color.clear) - } - .background(Color.clear) - #if os(macOS) - .scrollContentBackground(.hidden) - #endif - .task { - await loadPlayers() } } } func loadPlayers() async { + loading = true + errorMessage = nil do { + players = [] players = try await loadLeaderboard() } catch { - print("Failed to load leaderboard:", error) + errorMessage = error.localizedDescription } + loading = false } }