-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathToggleFavouriteButton.swift
52 lines (44 loc) · 1.39 KB
/
ToggleFavouriteButton.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
//
// ToggleFavouriteButton.swift
// Strongbox
//
// Created by Strongbox on 29/07/2024.
// Copyright © 2024 Mark McGuill. All rights reserved.
//
import SwiftUI
struct ToggleAppleWatchButton: View {
var model: DatabaseHomeViewModel
var entry: any SwiftEntryModelInterface
var body: some View {
Button(action: {
model.toggleAppleWatch(entry: entry)
}) {
let isWatchEntry = entry.isWatchEntry
let title: LocalizedStringKey = isWatchEntry ? "action_remove_entry_from_apple_watch" : "action_add_entry_to_apple_watch"
HStack {
Text(title)
Image(systemName: isWatchEntry ? "applewatch.slash" : "applewatch")
}
}
}
}
struct ToggleFavouriteButton: View {
var model: DatabaseHomeViewModel
var entry: any SwiftEntryModelInterface
var body: some View {
Button(action: {
model.toggleFavourite(entry: entry)
}) {
let pinned = entry.isFavourite
let title: LocalizedStringKey = pinned ? "browse_vc_action_unpin" : "browse_vc_action_pin"
HStack {
Text(title)
Image(systemName: pinned ? "star.slash" : "star")
.foregroundColor(.yellow)
}
}
}
}
#Preview {
ToggleFavouriteButton(model: DatabaseHomeViewModel(), entry: SwiftDummyEntryModel())
}