diff options
| author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2026-09-26 21:53:06 +0100 |
|---|---|---|
| committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2026-09-26 21:53:06 +0100 |
| commit | 40038b02ce651958ae703c8ecfe5f5578e1f7f09 (patch) | |
| tree | f6bc782c1b1d1a21073e5d40e4136d887f6fa4cd /ADSBDecoder/ContentView.swift | |
| parent | 505b23afc68ecbb63b8f0a7d44c0b0ad063d5cfd (diff) | |
| download | ADSBDecoder-40038b02ce651958ae703c8ecfe5f5578e1f7f09.tar.gz ADSBDecoder-40038b02ce651958ae703c8ecfe5f5578e1f7f09.zip | |
create adsbdecoder as UI, and renmae adsbdecoder to adsbdecodercli for terminal version
Diffstat (limited to 'ADSBDecoder/ContentView.swift')
| -rw-r--r-- | ADSBDecoder/ContentView.swift | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ADSBDecoder/ContentView.swift b/ADSBDecoder/ContentView.swift new file mode 100644 index 0000000..b1f9a9e --- /dev/null +++ b/ADSBDecoder/ContentView.swift @@ -0,0 +1,59 @@ +// +// ContentView.swift +// ADSBDecoder +// +// Created by Jacky Jack on 26/09/2026. +// + +import SwiftUI +import SwiftData + +struct ContentView: View { + @Environment(\.modelContext) private var modelContext + @Query private var items: [Item] + + var body: some View { + NavigationSplitView { + List { + ForEach(items) { item in + NavigationLink { + Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))") + } label: { + Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard)) + } + } + .onDelete(perform: deleteItems) + } + .navigationSplitViewColumnWidth(min: 180, ideal: 200) + .toolbar { + ToolbarItem { + Button(action: addItem) { + Label("Add Item", systemImage: "plus") + } + } + } + } detail: { + Text("Select an item") + } + } + + private func addItem() { + withAnimation { + let newItem = Item(timestamp: Date()) + modelContext.insert(newItem) + } + } + + private func deleteItems(offsets: IndexSet) { + withAnimation { + for index in offsets { + modelContext.delete(items[index]) + } + } + } +} + +#Preview { + ContentView() + .modelContainer(for: Item.self, inMemory: true) +} |
