Locations manifest, reorganized instances settings

This commit is contained in:
Arkadiusz Fal
2022-07-01 23:28:32 +02:00
parent 6f62f14adf
commit 4fcf57d755
28 changed files with 686 additions and 214 deletions

View File

@@ -8,45 +8,50 @@ struct AccountsMenuView: View {
@Default(.instances) private var instances
@Default(.accountPickerDisplaysUsername) private var accountPickerDisplaysUsername
var body: some View {
Menu {
ForEach(allAccounts, id: \.id) { account in
Button {
model.setCurrent(account)
} label: {
HStack {
Text(accountButtonTitle(account: account))
@ViewBuilder var body: some View {
if !instances.isEmpty {
Menu {
ForEach(allAccounts, id: \.id) { account in
Button {
model.setCurrent(account)
} label: {
HStack {
Text(accountButtonTitle(account: account))
Spacer()
Spacer()
if model.current == account {
Image(systemName: "checkmark")
if model.current == account {
Image(systemName: "checkmark")
}
}
}
}
}
} label: {
HStack {
Image(systemName: "person.crop.circle")
if accountPickerDisplaysUsername {
label
.labelStyle(.titleOnly)
} label: {
HStack {
if !accountPickerDisplaysUsername || !(model.current?.isPublic ?? true) {
Image(systemName: "globe")
}
if accountPickerDisplaysUsername {
label
.labelStyle(.titleOnly)
}
}
}
.disabled(allAccounts.isEmpty)
.transaction { t in t.animation = .none }
}
.disabled(instances.isEmpty)
.transaction { t in t.animation = .none }
}
private var label: some View {
Label(model.current?.description ?? "Select Account", systemImage: "person.crop.circle")
Label(model.current?.description ?? "Select Account", systemImage: "globe")
}
private var allAccounts: [Account] {
accounts + instances.map(\.anonymousAccount)
accounts + instances.map(\.anonymousAccount) + [model.publicAccount].compactMap { $0 }
}
private func accountButtonTitle(account: Account) -> String {
instances.count > 1 ? "\(account.description)\(account.instance.description)" : account.description
account.isPublic ? account.description : "\(account.description)\(account.instance.shortDescription)"
}
}

View File

@@ -19,6 +19,7 @@ struct ContentView: View {
@EnvironmentObject<PlaylistsModel> private var playlists
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var search
@EnvironmentObject<SettingsModel> private var settings
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
@@ -42,6 +43,7 @@ struct ContentView: View {
AppSidebarNavigation()
#elseif os(tvOS)
TVNavigationView()
.environmentObject(settings)
#endif
}
.onChange(of: accounts.signedIn) { _ in
@@ -105,10 +107,12 @@ struct ContentView: View {
}
)
.background(
EmptyView().sheet(isPresented: $navigation.presentingSettings, onDismiss: openWelcomeScreenIfAccountEmpty) {
EmptyView().sheet(isPresented: $navigation.presentingSettings) {
SettingsView()
.environmentObject(accounts)
.environmentObject(instances)
.environmentObject(settings)
.environmentObject(navigation)
.environmentObject(player)
}
)
@@ -126,14 +130,6 @@ struct ContentView: View {
#endif
}
func openWelcomeScreenIfAccountEmpty() {
guard Defaults[.instances].isEmpty else {
return
}
navigation.presentingWelcomeScreen = true
}
var videoPlayer: some View {
VideoPlayerView()
.environmentObject(accounts)