blob: 5b679cd3ffab099c09b8f30ddd2d9044fc9b7a0f (
plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
//
// DetailedSnippetView.swift
// iTexSnip
//
// Created by Navan Chauhan on 10/21/24.
//
import LaTeXSwiftUI
import SwiftUI
struct DetailedSnippetView: View {
@Environment(\.modelContext) var modelContext
@Environment(\.dismiss) private var dismiss
@State var showOriginal = false
var snippet: ImageSnippet
var body: some View {
VStack {
HStack {
Toggle("Show Original", isOn: $showOriginal)
.toggleStyle(.switch)
.padding()
Spacer()
HStack {
Button {
if snippet.rating == true {
updateRating(nil)
} else {
updateRating(true)
}
} label: {
if snippet.rating == true {
Image(systemName: "hand.thumbsup")
.foregroundStyle(.green)
.imageScale(.large)
} else {
Image(systemName: "hand.thumbsup")
.imageScale(.large)
}
}.buttonStyle(PlainButtonStyle())
Button {
if snippet.rating == false {
updateRating(nil)
} else {
updateRating(false)
}
} label: {
if snippet.rating == false {
Image(systemName: "hand.thumbsdown")
.foregroundStyle(.red)
.imageScale(.large)
} else {
Image(systemName: "hand.thumbsdown")
.imageScale(.large)
}
}.buttonStyle(PlainButtonStyle())
Button(role: .destructive) {
withAnimation {
modelContext.delete(snippet)
do {
try modelContext.save()
dismiss()
} catch {
print("Failed to delete snippet: \(error)")
}
}
} label: {
Image(systemName: "trash")
.imageScale(.large)
}
.padding()
.buttonStyle(PlainButtonStyle())
}.padding()
}
ScrollView {
if showOriginal {
HStack {
Spacer()
Image(nsImage: NSImage(data: snippet.image)!)
.resizable()
.clipped()
.cornerRadius(10)
.scaledToFit()
.frame(height: 100)
Spacer()
}.padding()
}
HStack {
Spacer()
LaTeXEquationView(equation: snippet.transcribedText!)
.clipped()
.scaledToFit()
.frame(height: 100)
Spacer()
}
VStack {
LaTeXCopyView(latex: snippet.transcribedText!, textStart: "", textEnd: "")
LaTeXCopyView(latex: snippet.transcribedText!, textStart: "$", textEnd: "$")
LaTeXCopyView(latex: snippet.transcribedText!, textStart: "$$", textEnd: "$$")
LaTeXCopyView(
latex: snippet.transcribedText!, textStart: "\\begin{equation}",
textEnd: "\\end{equation}")
}
}.frame(height: 450)
Spacer()
}
}
func updateRating(_ rating: Bool?) {
withAnimation {
self.snippet.rate(rating)
do {
try modelContext.save()
} catch {
print("Error saving rating: \(error)")
}
}
}
}
struct LaTeXCopyView: View {
var latex: String
var textStart: String
var textEnd: String
var body: some View {
HStack {
ScrollView(.horizontal) {
Text("\(textStart) \(latex) \(textEnd)")
.frame(height: 20)
.textSelection(.enabled)
.padding()
}
.frame(width: 400)
.border(Color.accentColor)
Button {
print("Should Copy")
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString("\(textStart) \(latex) \(textEnd)", forType: .string)
} label: {
Image(systemName: "document.on.clipboard")
}
.buttonStyle(PlainButtonStyle())
.imageScale(.large)
}
}
}
struct LaTeXEquationView: View {
var equation: String
var body: some View {
LaTeX(equation)
.parsingMode(.all)
.font(.system(size: 28, weight: .bold))
}
}
|