Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Added search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
aeoliux committed Apr 14, 2024
1 parent 1f29ea6 commit b175f51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions LibrePass.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand Down Expand Up @@ -494,7 +494,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
23 changes: 7 additions & 16 deletions LibrePass/API/LibrePassCipher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class LibrePassCipher: Codable {
}
}

func contains(query: String) -> Bool {
return self.id == query ||
(self.type == .Login) ? self.loginData!.name.contains(query) || self.loginData!.username?.contains(query) ?? false || self.loginData!.uris?.filter({ $0.contains(query) }).count ?? 0 > 0 || self.loginData!.notes?.contains(query) ?? false:
(self.type == .SecureNote) ? self.secureNoteData!.title.contains(query) || self.secureNoteData!.note.contains(query) :
self.cardData!.name.contains(query) || self.cardData!.cardholderName.contains(query) || self.cardData!.notes?.contains(query) ?? false
}

enum CipherType: Int, Codable {
case Login = 0
case SecureNote
Expand Down Expand Up @@ -121,19 +128,3 @@ class LibrePassCipher: Codable {
var lastUsed: Int
}
}

extension [LibrePassEncryptedCipher] {
mutating func addOrReplace(cipher: LibrePassEncryptedCipher) {
if let index = self.firstIndex(where: { cipher.id == $0.id }) {
self[index] = cipher
} else {
self.append(cipher)
}
}

mutating func delete(id: String) {
if let index = self.firstIndex(where: { id == $0.id }) {
self.remove(at: index)
}
}
}
5 changes: 4 additions & 1 deletion LibrePass/App/LibrePassManagerWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ struct LibrePassManagerWindow: View {
@Query var syncQueue: [SyncQueueItem]
@Query var lastStorageItem: [LastSyncStorage]

@State var searchQuery: String = ""

var body: some View {
NavigationView {
List {
if self.context.lClient != nil {
ForEach(vault, id: \.self.id) { encCipher in
let cipher = try? LibrePassCipher(encCipher: encCipher.encryptedCipher, key: self.context.lClient!.sharedKey!)

if let cipher = cipher {
if let cipher = cipher, self.searchQuery == "" || (self.searchQuery != "" && cipher.contains(query: self.searchQuery)) {
NavigationLink(destination: CipherView(cipher: cipher, sync: self.syncVault)) {
HStack {
CipherButton(cipher: cipher)
Expand All @@ -52,6 +54,7 @@ struct LibrePassManagerWindow: View {
}

.navigationTitle("Vault")
.searchable(text: self.$searchQuery)
.toolbar {
HStack {
SpinningWheel(isPresented: self.$deletionIndicator, task: self.deleteCiphers)
Expand Down

0 comments on commit b175f51

Please sign in to comment.