Add ability to create flashcards
This commit is contained in:
53
WordAX/Views/AddFlashCard.swift
Normal file
53
WordAX/Views/AddFlashCard.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// addFlashCard.swift
|
||||
// WordAX
|
||||
//
|
||||
// Created by Oliver Hnát on 07.04.2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AddFlashCard: View {
|
||||
@State var text: String = ""
|
||||
@State var description: String = ""
|
||||
@Binding var isShowing: Bool
|
||||
var addFlashCard: (String, String) -> Void
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
List {
|
||||
Section(header: Text("Flashcard details") ) {
|
||||
TextField("Name", text: $text)
|
||||
TextField("Description", text: $description, axis: .vertical)
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .topBarLeading) {
|
||||
Button(action: {
|
||||
self.isShowing = false
|
||||
}, label: {
|
||||
Text("Cancel")
|
||||
.foregroundStyle(.red)
|
||||
})
|
||||
}
|
||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||
Button(action: {
|
||||
self.addFlashCard(self.text, self.description)
|
||||
self.isShowing = false
|
||||
}, label: {
|
||||
Text("Create")
|
||||
.bold()
|
||||
})
|
||||
}
|
||||
}
|
||||
.navigationTitle("Add Flashcard")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
@State var isShowing = true
|
||||
func add(name: String, desc: String) {
|
||||
return
|
||||
}
|
||||
return AddFlashCard(isShowing: $isShowing, addFlashCard: add)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import SwiftUI
|
||||
struct FlashCardListView: View {
|
||||
@EnvironmentObject var model: WordAXModelView
|
||||
@State var showDescription = true
|
||||
@State var addFlashcard = false
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
List(model.flashcards) { word in
|
||||
@@ -20,9 +21,19 @@ struct FlashCardListView: View {
|
||||
}
|
||||
}
|
||||
.navigationTitle("Word List")
|
||||
.toolbar {
|
||||
Button(action: {
|
||||
self.addFlashcard = true
|
||||
}) {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
}
|
||||
} detail: {
|
||||
Text("Select word to get details about")
|
||||
}
|
||||
.sheet(isPresented: $addFlashcard, content: {
|
||||
AddFlashCard(isShowing: $addFlashcard, addFlashCard: model.addFlashCard)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ struct WordAX {
|
||||
var id: Int
|
||||
var name: String
|
||||
var description: String
|
||||
var shown: Bool
|
||||
var shown: Bool = false
|
||||
var nextSpacedRepetitionMilestone: SpacedRepetitionMilestoneEnum?
|
||||
var lastSeenOn: Date?
|
||||
var shownCount: Int = 0
|
||||
|
||||
@@ -57,6 +57,10 @@ class WordAXModelView: ObservableObject {
|
||||
model.setSpacedRepetitionMilestone(flashcardId: flashcardId, milestone: milestone)
|
||||
model.flashcardShown(flashcardId: flashcardId)
|
||||
}
|
||||
|
||||
public func addFlashCard(name: String, description: String) {
|
||||
self.model.add(flashcard: FlashCard(id: (self.flashcards.map{$0.id}.max() ?? -1) + 1, name: name, description: description))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user