Skip to content

Commit

Permalink
Merge pull request #521 from pennlabs/anli/03-24-fix-listing-name-fie…
Browse files Browse the repository at this point in the history
…ld-weirdness

Fix Listing Name field weirdness
  • Loading branch information
anli5005 authored Mar 24, 2024
2 parents 74df06c + 7447a26 commit 02e0712
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions PennMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3329,8 +3329,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pennlabs/PennForms";
requirement = {
kind = revision;
revision = aff2ed4611e71bc5c7b16dfae9636789e06993b7;
branch = subletting;
kind = branch;
};
};
F213CCE023C3EE3E000AD90F /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
16 changes: 14 additions & 2 deletions PennMobile/Subletting/Listings/NewListingForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct NewListingForm: View {
init(sublet: Sublet) {
self.isNew = false
self.originalSublet = sublet
self._subletData = State(initialValue: sublet.data)
self._subletData = State(initialValue: SubletData())
self._negotiable = State(initialValue: sublet.negotiable)
self._price = State(initialValue: sublet.price)
self._startDate = State(initialValue: sublet.startDate.date)
Expand All @@ -76,7 +76,7 @@ struct NewListingForm: View {
self._images = State(initialValue: [])
self._existingImages = State(initialValue: sublet.images.map { $0.imageUrl })

self.showValidationErrors = true
self.showValidationErrors = false
}

var body: some View {
Expand Down Expand Up @@ -358,6 +358,18 @@ struct NewListingForm: View {
}
}
.environment(\.showValidationErrors, showValidationErrors)
.onAppear {
// HACK: Listing Name field shows really weird behavior unless we do this??
if !isNew {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1)) {
if let originalSublet {
subletData = originalSublet.data
}

showValidationErrors = true
}
}
}
}
}

Expand Down
7 changes: 2 additions & 5 deletions PennMobile/Subletting/SublettingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct MarketplaceFilterData: Codable {
var selectedAmenities = OrderedSet<String>()
}

class SublettingViewModel: ObservableObject {
@MainActor class SublettingViewModel: ObservableObject {
@Published private var sublets: [Int: Sublet] = [:]
var sortedFilteredSublets: [Sublet] {
let filtered = filteredIDs.compactMap { sublets[$0] }
Expand Down Expand Up @@ -228,11 +228,8 @@ class SublettingViewModel: ObservableObject {
return savedIDs.contains(sublet.subletID)
}

private let subletUpdateQueue = DispatchQueue(label: "subletUpdateQueue")
func updateSublet(sublet: Sublet) {
subletUpdateQueue.sync {
sublets[sublet.subletID] = sublet
}
sublets[sublet.subletID] = sublet
}

func getSublet(subletID: Int) -> Sublet? {
Expand Down

0 comments on commit 02e0712

Please sign in to comment.