Add ability to create flashcards
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
6C8185082B8B523E0033CF46 /* NextRepetitionButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */; };
|
6C8185082B8B523E0033CF46 /* NextRepetitionButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */; };
|
||||||
6C81850A2B8BA5740033CF46 /* FlashCardListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185092B8BA5740033CF46 /* FlashCardListView.swift */; };
|
6C81850A2B8BA5740033CF46 /* FlashCardListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185092B8BA5740033CF46 /* FlashCardListView.swift */; };
|
||||||
6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */; };
|
6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */; };
|
||||||
|
6CEF7F522BC2DBF800E205F6 /* AddFlashCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F512BC2DBF800E205F6 /* AddFlashCard.swift */; };
|
||||||
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439512B83541D004C3543 /* WordAXApp.swift */; };
|
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439512B83541D004C3543 /* WordAXApp.swift */; };
|
||||||
6CF439542B83541D004C3543 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439532B83541D004C3543 /* MainView.swift */; };
|
6CF439542B83541D004C3543 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439532B83541D004C3543 /* MainView.swift */; };
|
||||||
6CF439562B83541E004C3543 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CF439552B83541E004C3543 /* Assets.xcassets */; };
|
6CF439562B83541E004C3543 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CF439552B83541E004C3543 /* Assets.xcassets */; };
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextRepetitionButtonView.swift; sourceTree = "<group>"; };
|
6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextRepetitionButtonView.swift; sourceTree = "<group>"; };
|
||||||
6C8185092B8BA5740033CF46 /* FlashCardListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListView.swift; sourceTree = "<group>"; };
|
6C8185092B8BA5740033CF46 /* FlashCardListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListView.swift; sourceTree = "<group>"; };
|
||||||
6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListRowView.swift; sourceTree = "<group>"; };
|
6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListRowView.swift; sourceTree = "<group>"; };
|
||||||
|
6CEF7F512BC2DBF800E205F6 /* AddFlashCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFlashCard.swift; sourceTree = "<group>"; };
|
||||||
6CF4394E2B83541D004C3543 /* WordAX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WordAX.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
6CF4394E2B83541D004C3543 /* WordAX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WordAX.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
6CF439512B83541D004C3543 /* WordAXApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXApp.swift; sourceTree = "<group>"; };
|
6CF439512B83541D004C3543 /* WordAXApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXApp.swift; sourceTree = "<group>"; };
|
||||||
6CF439532B83541D004C3543 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
|
6CF439532B83541D004C3543 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
|
||||||
@@ -48,6 +50,20 @@
|
|||||||
/* End PBXFrameworksBuildPhase section */
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXGroup section */
|
/* Begin PBXGroup section */
|
||||||
|
6C4632342BC2D99E003ED0E9 /* Views */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
6CEF7F512BC2DBF800E205F6 /* AddFlashCard.swift */,
|
||||||
|
6CF439532B83541D004C3543 /* MainView.swift */,
|
||||||
|
6C8185092B8BA5740033CF46 /* FlashCardListView.swift */,
|
||||||
|
6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */,
|
||||||
|
6C8185012B88C9FB0033CF46 /* SettingsView.swift */,
|
||||||
|
6C8185032B88CA210033CF46 /* AnkiView.swift */,
|
||||||
|
6C8185052B8A537F0033CF46 /* FlashCardView.swift */,
|
||||||
|
);
|
||||||
|
path = Views;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
6CF439452B83541D004C3543 = {
|
6CF439452B83541D004C3543 = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -68,12 +84,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
6CF439512B83541D004C3543 /* WordAXApp.swift */,
|
6CF439512B83541D004C3543 /* WordAXApp.swift */,
|
||||||
6CF439532B83541D004C3543 /* MainView.swift */,
|
6C4632342BC2D99E003ED0E9 /* Views */,
|
||||||
6C8185092B8BA5740033CF46 /* FlashCardListView.swift */,
|
|
||||||
6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */,
|
|
||||||
6C8185012B88C9FB0033CF46 /* SettingsView.swift */,
|
|
||||||
6C8185032B88CA210033CF46 /* AnkiView.swift */,
|
|
||||||
6C8185052B8A537F0033CF46 /* FlashCardView.swift */,
|
|
||||||
6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */,
|
6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */,
|
||||||
6C8184FD2B88C9580033CF46 /* WordAX.swift */,
|
6C8184FD2B88C9580033CF46 /* WordAX.swift */,
|
||||||
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */,
|
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */,
|
||||||
@@ -169,6 +180,7 @@
|
|||||||
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */,
|
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */,
|
||||||
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */,
|
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */,
|
||||||
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */,
|
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */,
|
||||||
|
6CEF7F522BC2DBF800E205F6 /* AddFlashCard.swift in Sources */,
|
||||||
6C8184FE2B88C9580033CF46 /* WordAX.swift in Sources */,
|
6C8184FE2B88C9580033CF46 /* WordAX.swift in Sources */,
|
||||||
6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */,
|
6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */,
|
||||||
);
|
);
|
||||||
|
|||||||
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 {
|
struct FlashCardListView: View {
|
||||||
@EnvironmentObject var model: WordAXModelView
|
@EnvironmentObject var model: WordAXModelView
|
||||||
@State var showDescription = true
|
@State var showDescription = true
|
||||||
|
@State var addFlashcard = false
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
List(model.flashcards) { word in
|
List(model.flashcards) { word in
|
||||||
@@ -20,9 +21,19 @@ struct FlashCardListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Word List")
|
.navigationTitle("Word List")
|
||||||
|
.toolbar {
|
||||||
|
Button(action: {
|
||||||
|
self.addFlashcard = true
|
||||||
|
}) {
|
||||||
|
Image(systemName: "plus")
|
||||||
|
}
|
||||||
|
}
|
||||||
} detail: {
|
} detail: {
|
||||||
Text("Select word to get details about")
|
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 id: Int
|
||||||
var name: String
|
var name: String
|
||||||
var description: String
|
var description: String
|
||||||
var shown: Bool
|
var shown: Bool = false
|
||||||
var nextSpacedRepetitionMilestone: SpacedRepetitionMilestoneEnum?
|
var nextSpacedRepetitionMilestone: SpacedRepetitionMilestoneEnum?
|
||||||
var lastSeenOn: Date?
|
var lastSeenOn: Date?
|
||||||
var shownCount: Int = 0
|
var shownCount: Int = 0
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ class WordAXModelView: ObservableObject {
|
|||||||
model.setSpacedRepetitionMilestone(flashcardId: flashcardId, milestone: milestone)
|
model.setSpacedRepetitionMilestone(flashcardId: flashcardId, milestone: milestone)
|
||||||
model.flashcardShown(flashcardId: flashcardId)
|
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