Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
LePips committed Jan 3, 2025
1 parent 3326b64 commit 141393d
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class ItemEditorViewModel<Element: Equatable>: ViewModel, Stateful, Eventful {

// MARK: - Reorder Elements (To Be Overridden)

// TODO: should instead move to an index-based self insertion
// instead of replacement
func reorderComponents(_ tags: [Element]) async throws {
fatalError("This method should be overridden in subclasses")
}
Expand Down
2 changes: 1 addition & 1 deletion Swiftfin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2901,8 +2901,8 @@
4EFAC1312D1E373B00E40880 /* AddServerUserAccessTagsView */ = {
isa = PBXGroup;
children = (
4EFAC1322D1E8C6B00E40880 /* AddServerUserAccessTagsView.swift */,
4EFAC1342D1FB19700E40880 /* Components */,
4EFAC1322D1E8C6B00E40880 /* AddServerUserAccessTagsView.swift */,
);
path = AddServerUserAccessTagsView;
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct AddServerUserAccessTagsView: View {
@ObservedObject
private var viewModel: ServerUserAdminViewModel

@ObservedObject
@StateObject
private var tagViewModel: TagEditorViewModel

// MARK: - Access Tag Variables
Expand All @@ -31,11 +31,6 @@ struct AddServerUserAccessTagsView: View {
@State
private var access: Bool = false

// MARK: - Trie Data Loaded

@State
private var loaded: Bool = false

// MARK: - Error State

@State
Expand Down Expand Up @@ -65,7 +60,7 @@ struct AddServerUserAccessTagsView: View {
init(viewModel: ServerUserAdminViewModel) {
self.viewModel = viewModel
self.tempPolicy = viewModel.user.policy!
self.tagViewModel = TagEditorViewModel(item: .init())
self._tagViewModel = StateObject(wrappedValue: TagEditorViewModel(item: .init()))
}

// MARK: - Body
Expand Down Expand Up @@ -126,7 +121,6 @@ struct AddServerUserAccessTagsView: View {
case .updated:
break
case .loaded:
loaded = true
tagViewModel.send(.search(tempTag))
case let .error(eventError):
UIDevice.feedback(.error)
Expand All @@ -149,7 +143,7 @@ struct AddServerUserAccessTagsView: View {

SearchResultsSection(
tag: $tempTag,
population: tagViewModel.matches,
tags: tagViewModel.matches,
isSearching: tagViewModel.backgroundStates.contains(.searching)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,33 @@ extension AddServerUserAccessTagsView {

// MARK: - Element Search Variables

let population: [String]
let tags: [String]
let isSearching: Bool

// MARK: - Body

var body: some View {
if tag.isNotEmpty {
Section {
if population.isNotEmpty {
if tags.isNotEmpty {
resultsView
.animation(.easeInOut, value: population.count)
} else if !isSearching {
noResultsView
.transition(.opacity)
.animation(.easeInOut, value: population.count)
}
} header: {
HStack {
Text(L10n.existingItems)

if isSearching {
DelayedProgressView()
ProgressView()
} else {
Text("-")
Text(population.count.description)

Text(tags.count, format: .number)
}
}
.animation(.easeInOut, value: isSearching)
}
.animation(.linear(duration: 0.2), value: tags)
}
}

Expand All @@ -56,23 +55,17 @@ extension AddServerUserAccessTagsView {
private var noResultsView: some View {
Text(L10n.none)
.foregroundStyle(.secondary)
.frame(maxWidth: .infinity, alignment: .center)
}

// MARK: - Results View

private var resultsView: some View {
ForEach(population, id: \.self) { result in
Button {
ForEach(tags, id: \.self) { result in
Button(result) {
tag = result
} label: {
Text(result)
.frame(maxWidth: .infinity, alignment: .leading)
}
.foregroundStyle(.primary)
.disabled(tag == result)
.transition(.opacity.combined(with: .move(edge: .top)))
.animation(.easeInOut, value: population.count)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ extension AddServerUserAccessTagsView {

// MARK: - Element Variables

@FocusState
private var isTagFocused: Bool

@Binding
var access: Bool
@Binding
Expand All @@ -26,40 +29,34 @@ extension AddServerUserAccessTagsView {
// MARK: - Body

var body: some View {
tagView
}

// MARK: - Tag View

@ViewBuilder
private var tagView: some View {
Section {
Picker(L10n.access, selection: $access) {
Text(L10n.allowed).tag(true)
Text(L10n.blocked).tag(false)
}
// TODO: Enable on 10.10
.disabled(true)
} header: {
Text(L10n.access)
} footer: {
LearnMoreButton(L10n.accessTags) {
TextPair(
title: L10n.allowed,
subtitle: L10n.accessTagAllowDescription
)
TextPair(
title: L10n.blocked,
subtitle: L10n.accessTagBlockDescription
)
}
}
// TODO: Enable on 10.10
// Section {
// Picker(L10n.access, selection: $access) {
// Text(L10n.allowed).tag(true)
// Text(L10n.blocked).tag(false)
// }
// .disabled(true)
// } header: {
// Text(L10n.access)
// } footer: {
// LearnMoreButton(L10n.accessTags) {
// TextPair(
// title: L10n.allowed,
// subtitle: L10n.accessTagAllowDescription
// )
// TextPair(
// title: L10n.blocked,
// subtitle: L10n.accessTagBlockDescription
// )
// }
// }

Section {
TextField(L10n.name, text: $tag)
.autocorrectionDisabled()
.focused($isTagFocused)
} footer: {
if tag.isEmpty || tag == "" {
if tag.isEmpty {
Label(
L10n.required,
systemImage: "exclamationmark.circle.fill"
Expand Down Expand Up @@ -87,6 +84,9 @@ extension AddServerUserAccessTagsView {
}
}
}
.onFirstAppear {
isTagFocused = true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@ extension EditServerUserAccessTagsView {

struct EditAccessTagRow: View {

// MARK: - Enviroment Variables

@Environment(\.isEditing)
private var isEditing
@Environment(\.isSelected)
private var isSelected

// MARK: - Metadata Variables

let item: String
let access: Bool
let tag: String

// MARK: - Row Actions

Expand All @@ -34,36 +26,22 @@ extension EditServerUserAccessTagsView {
// MARK: - Body

var body: some View {
ListRow {} content: {
rowContent
}
.onSelect(perform: onSelect)
.isSeparatorVisible(false)
.swipeActions {
Button(L10n.delete, systemImage: "trash", action: onDelete)
.tint(.red)
}
}

// MARK: - Row Content
Button(action: onSelect) {
HStack {
Text(tag)
.frame(maxWidth: .infinity, alignment: .leading)

@ViewBuilder
private var rowContent: some View {
HStack {
VStack(alignment: .leading) {
TextPairView(
leading: item,
trailing: access ? L10n.allowed : L10n.blocked
)
.foregroundStyle(
isEditing ? (isSelected ? .primary : .secondary) : .primary, .secondary
)
.font(.headline)
ListRowCheckbox()
}

ListRowCheckbox()
.environment(\.isEditing, isEditing)
.environment(\.isSelected, isSelected)
}
.foregroundStyle(.primary)
.swipeActions {
Button(
L10n.delete,
systemImage: "trash",
action: onDelete
)
.tint(.red)
}
}
}
Expand Down
Loading

0 comments on commit 141393d

Please sign in to comment.