-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathFavoritesView.swift
84 lines (52 loc) · 1.62 KB
/
FavoritesView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// FavoritesView.swift
// Strongbox
//
// Created by Strongbox on 27/07/2024.
// Copyright © 2024 Mark McGuill. All rights reserved.
//
import Foundation
import SwiftUI
struct FavoritesView: View {
private var rows: [GridItem] {
var full = [
GridItem(.flexible(minimum: 50)),
GridItem(.flexible(minimum: 0)),
GridItem(.flexible(minimum: 0)),
]
let count = model.database.favourites.count
if count < 5 {
full.removeLast()
}
if count < 3 {
full.removeLast()
}
return full
}
@ObservedObject
var model: DatabaseHomeViewModel
var body: some View {
ScrollView(.horizontal) {
LazyHGrid(rows: rows, alignment: .top) {
ForEach(model.database.favourites) { favourite in
FavouriteCapsuleView(model: model, entry: favourite, easyReadSeparator: model.twoFactorShowSeparator)
.contextMenu {
EntryViewContextMenu(model: model, item: favourite)
}.id(UUID())
}
}
}
}
}
#Preview {
let favs = [SwiftDummyEntryModel(title: "HSBC UK 1", imageSystemName: "doc", favourite: true),
SwiftDummyEntryModel(title: "Strava 2", imageSystemName: "doc", favourite: true),
]
let database = SwiftDummyDatabaseModel()
database.entries = favs
let model = DatabaseHomeViewModel(database: database)
return
List {
FavoritesView(model: model)
}
}