Skip to content

Commit

Permalink
Merge branch 'jellyfin:main' into iOSSettingsUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
JPKribs authored Dec 26, 2024
2 parents e910791 + 2f13093 commit 23ac711
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 52 deletions.
6 changes: 6 additions & 0 deletions Shared/Extensions/Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ extension Set {
insert(value)
}
}

mutating func insert(contentsOf elements: [Element]) {
for element in elements {
insert(element)
}
}
}
107 changes: 55 additions & 52 deletions Swiftfin/Views/SelectUserView/SelectUserView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import SwiftUI
// TODO: user ordering
// - name
// - last signed in date
// TODO: between the server selection menu and delete toolbar,
// figure out a way to make the grid/list and splash screen
// not jump when size is changed

struct SelectUserView: View {

Expand Down Expand Up @@ -85,6 +88,17 @@ struct SelectUserView: View {
@State
private var error: Error? = nil

private var users: [UserState] {
gridItems.compactMap { item in
switch item {
case let .user(user, _):
return user
default:
return nil
}
}
}

// MARK: - Select Server

private var selectedServer: ServerState? {
Expand Down Expand Up @@ -380,33 +394,6 @@ struct SelectUserView: View {
}
}

// MARK: - Delete Users Button

@ViewBuilder
private var deleteUsersButton: some View {
Button {
isPresentingConfirmDeleteUsers = true
} label: {
ZStack {
Color.red

Text(L10n.delete)
.font(.body.weight(.semibold))
.foregroundStyle(selectedUsers.isNotEmpty ? .primary : .secondary)

if selectedUsers.isEmpty {
Color.black
.opacity(0.5)
}
}
.clipShape(RoundedRectangle(cornerRadius: 10))
.frame(height: 50)
.frame(maxWidth: 400)
}
.disabled(selectedUsers.isEmpty)
.buttonStyle(.plain)
}

// MARK: - User View

@ViewBuilder
Expand Down Expand Up @@ -453,11 +440,6 @@ struct SelectUserView: View {
)
.edgePadding([.bottom, .horizontal])
}

if isEditingUsers {
deleteUsersButton
.edgePadding([.bottom, .horizontal])
}
}
.background {
if selectUserUseSplashscreen, splashScreenImageSources.isNotEmpty {
Expand Down Expand Up @@ -516,28 +498,49 @@ struct SelectUserView: View {
.aspectRatio(contentMode: .fit)
.frame(width: 30)
}
}
.topBarTrailing {
if isEditingUsers {
Button {
isEditingUsers = false
} label: {
L10n.cancel.text
.font(.headline)
.padding(.vertical, 5)
.padding(.horizontal, 10)
.background {
if colorScheme == .light {
Color.secondarySystemFill
} else {
Color.tertiarySystemBackground
}

ToolbarItem(placement: .topBarLeading) {
if isEditingUsers {
if selectedUsers.count == users.count {
Button(L10n.removeAll) {
selectedUsers.removeAll()
}
.buttonStyle(.toolbarPill)
} else {
Button(L10n.selectAll) {
selectedUsers.insert(contentsOf: users)
}
.clipShape(RoundedRectangle(cornerRadius: 10))
.buttonStyle(.toolbarPill)
}
}
}

ToolbarItemGroup(placement: .topBarTrailing) {
if isEditingUsers {
Button(isEditingUsers ? L10n.cancel : L10n.edit) {
isEditingUsers.toggle()

UIDevice.impact(.light)

if !isEditingUsers {
selectedUsers.removeAll()
}
}
.buttonStyle(.toolbarPill)
} else {
advancedMenu
}
}

ToolbarItem(placement: .bottomBar) {
if isEditingUsers {
Button(L10n.delete) {
isPresentingConfirmDeleteUsers = true
}
.buttonStyle(.toolbarPill(.red))
.disabled(selectedUsers.isEmpty)
.frame(maxWidth: .infinity, alignment: .trailing)
}
.buttonStyle(.plain)
} else {
advancedMenu
}
}
.onAppear {
Expand Down

0 comments on commit 23ac711

Please sign in to comment.