Skip to content

Commit

Permalink
♻️ refactor charts code
Browse files Browse the repository at this point in the history
  • Loading branch information
touyou committed Jul 3, 2022
1 parent 668dc5f commit 35b56e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 67 deletions.
4 changes: 0 additions & 4 deletions VisionReceipt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
434FB0D3285F67D100838D43 /* ReceiptData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 434FB0D2285F67D000838D43 /* ReceiptData.swift */; };
434FB0D7285FFCCF00838D43 /* ScannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 434FB0D6285FFCCF00838D43 /* ScannerView.swift */; };
43A3BCC9286EE172007BBF06 /* CheckView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A3BCC8286EE172007BBF06 /* CheckView.swift */; };
43A3BCCB287018DF007BBF06 /* ChartsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43A3BCCA287018DF007BBF06 /* ChartsView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -26,7 +25,6 @@
434FB0D2285F67D000838D43 /* ReceiptData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptData.swift; sourceTree = "<group>"; };
434FB0D6285FFCCF00838D43 /* ScannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerView.swift; sourceTree = "<group>"; };
43A3BCC8286EE172007BBF06 /* CheckView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckView.swift; sourceTree = "<group>"; };
43A3BCCA287018DF007BBF06 /* ChartsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartsView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -65,7 +63,6 @@
434FB0C6285F653100838D43 /* ContentView.swift */,
434FB0D6285FFCCF00838D43 /* ScannerView.swift */,
43A3BCC8286EE172007BBF06 /* CheckView.swift */,
43A3BCCA287018DF007BBF06 /* ChartsView.swift */,
434FB0D2285F67D000838D43 /* ReceiptData.swift */,
);
path = VisionReceipt;
Expand Down Expand Up @@ -154,7 +151,6 @@
434FB0C5285F653100838D43 /* VisionReceiptApp.swift in Sources */,
434FB0D7285FFCCF00838D43 /* ScannerView.swift in Sources */,
43A3BCC9286EE172007BBF06 /* CheckView.swift in Sources */,
43A3BCCB287018DF007BBF06 /* ChartsView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
52 changes: 0 additions & 52 deletions VisionReceipt/ChartsView.swift

This file was deleted.

23 changes: 12 additions & 11 deletions VisionReceipt/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import Charts
struct ContentView: View {
@AppStorage("receiptDatas") var receiptDatas = ReceiptDatas()
@State private var showScannerSheet = false

private var entries: [ChartEntry] {
let sortedDatas = receiptDatas.sorted(by: { $0.date < $1.date })
let formatter = DateFormatter()
formatter.dateFormat = "MMdd"
return sortedDatas.map { ChartEntry(date: formatter.string(from: $0.date), value: $0.totalCost()) }

return sortedDatas.map {
ChartEntry(date: formatter.string(from: $0.date), value: $0.totalCost())
}
}

var body: some View {
NavigationStack {
VStack(alignment: .center) {
Expand Down Expand Up @@ -70,22 +71,22 @@ struct ContentView: View {
}
.navigationTitle("Receipt Manager")
.navigationBarItems(trailing:
Button(action: {
showScannerSheet = true
}, label: {
Image(systemName: "plus.circle")
})
Button(action: {
showScannerSheet = true
}, label: {
Image(systemName: "plus.circle")
})
)
.sheet(isPresented: $showScannerSheet, content: {
ScannerView()
})
}
}

init(showScannerSheet: Bool = false) {
self.showScannerSheet = showScannerSheet
}

struct ChartEntry: Identifiable {
let date: String
let value: Int
Expand Down

0 comments on commit 35b56e5

Please sign in to comment.