mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 06:49:12 +00:00
can now edit events, need to make it apply on the fly
added about window
This commit is contained in:
40
MacNearFuture/AboutView.swift
Normal file
40
MacNearFuture/AboutView.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// AboutView.swift
|
||||
// MacNearFuture
|
||||
//
|
||||
// Created by neon443 on 28/05/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AboutView: View {
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
Image(nsImage: #imageLiteral(resourceName: "NearFutureIcon.png"))
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 100)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 25))
|
||||
Text("Near Future")
|
||||
.bold()
|
||||
.monospaced()
|
||||
.font(.title)
|
||||
Text("Version " + getVersion() + " (\(getBuildID()))")
|
||||
.padding(.bottom)
|
||||
Text("© 2024-2025 neon443, Inc")
|
||||
.padding(.bottom)
|
||||
Link("Developer Website", destination: URL(string: "https://neon443.xyz")!)
|
||||
}
|
||||
.padding()
|
||||
.padding()
|
||||
.containerBackground(.ultraThinMaterial, for: .window)
|
||||
.toolbar(removing: .title)
|
||||
.toolbarBackground(.hidden, for: .windowToolbar)
|
||||
.windowMinimizeBehavior(.disabled)
|
||||
.windowFullScreenBehavior(.disabled)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
AboutView()
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import SwiftUI
|
||||
|
||||
@main
|
||||
struct NearFutureApp: App {
|
||||
@Environment(\.openWindow) var openWindow
|
||||
@StateObject var viewModel: EventViewModel = EventViewModel()
|
||||
@StateObject var settingsModel: SettingsViewModel = SettingsViewModel()
|
||||
|
||||
@@ -22,13 +23,41 @@ struct NearFutureApp: App {
|
||||
}
|
||||
.defaultSize(width: 550, height: 650)
|
||||
.commands {
|
||||
CommandGroup(replacing: CommandGroupPlacement.appInfo) {
|
||||
Button("about nf") {
|
||||
openWindow(id: "about")
|
||||
}
|
||||
}
|
||||
NearFutureCommands()
|
||||
}
|
||||
|
||||
Window("About Near Future", id: "about") {
|
||||
|
||||
WindowGroup("edit Event", for: Event.ID.self) { $eventID in
|
||||
EditEventView(
|
||||
viewModel: viewModel,
|
||||
event: Binding(
|
||||
get: {
|
||||
viewModel.events.first(where: {$0.id == eventID})!
|
||||
},
|
||||
set: { newValue in
|
||||
if let eventIndex = viewModel.events.firstIndex(where: {
|
||||
$0.id == eventID
|
||||
}) {
|
||||
viewModel.events[eventIndex] = newValue
|
||||
}
|
||||
viewModel.saveEvents()
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Window("About Near Future", id: "about") {
|
||||
AboutView()
|
||||
}
|
||||
.windowBackgroundDragBehavior(.enabled)
|
||||
.windowResizability(.contentSize)
|
||||
.restorationBehavior(.disabled)
|
||||
.defaultPosition(UnitPoint.center)
|
||||
|
||||
Settings {
|
||||
Text("wip")
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import SwiftUI
|
||||
|
||||
struct NearFutureCommands: Commands {
|
||||
var body: some Commands {
|
||||
|
||||
CommandGroup(after: CommandGroupPlacement.appInfo) {
|
||||
Text("hi")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ struct EventListView: View {
|
||||
@State var largeTick: Bool = false
|
||||
@State var hovering: Bool = false
|
||||
|
||||
@Environment(\.openWindow) var openWindow
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color.black.opacity(hovering ? 0.5 : 0.0)
|
||||
@@ -130,6 +132,9 @@ struct EventListView: View {
|
||||
hovering.toggle()
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
openWindow(value: event.id)
|
||||
}
|
||||
.contextMenu() {
|
||||
Button(role: .destructive) {
|
||||
let eventToModify = viewModel.events.firstIndex() { currEvent in
|
||||
|
||||
@@ -12,19 +12,6 @@ struct EditEventView: View {
|
||||
@ObservedObject var viewModel: EventViewModel
|
||||
@Binding var event: Event
|
||||
|
||||
fileprivate func saveEdits() {
|
||||
//if there is an event in vM.events with the id of the event we r editing,
|
||||
//firstindex - loops through the arr and finds first element where that events id matches editing event's id
|
||||
if let index = viewModel.events.firstIndex(where: { xEvent in
|
||||
xEvent.id == event.id
|
||||
}) {
|
||||
viewModel.events[index] = event
|
||||
}
|
||||
viewModel.saveEvents()
|
||||
|
||||
dismiss()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
AddEventView(
|
||||
viewModel: viewModel,
|
||||
@@ -42,7 +29,7 @@ struct EditEventView: View {
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
Button() {
|
||||
saveEdits()
|
||||
dismiss()
|
||||
} label: {
|
||||
Text("Done")
|
||||
.bold()
|
||||
|
||||
Reference in New Issue
Block a user