Delete flashcards, refactor, todos, date format
Added ability to delete flashcards Extracted adding flashcards into a function Added TODOs Updated dateFormatter to include time based on user's 24/12 format
This commit is contained in:
@@ -36,15 +36,7 @@ struct AddFlashCard: View {
|
|||||||
}
|
}
|
||||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
let flashcard = Flashcard(context: moc)
|
self.createFlashcard()
|
||||||
flashcard.id = UUID()
|
|
||||||
flashcard.name = self.text
|
|
||||||
flashcard.desc = self.description
|
|
||||||
flashcard.nextSpacedRepetitionMilestone = 0
|
|
||||||
flashcard.lastSeenOn = nil
|
|
||||||
flashcard.shownCount = 0
|
|
||||||
flashcard.dateAdded = Date()
|
|
||||||
try? moc.save()
|
|
||||||
self.isShowing = false
|
self.isShowing = false
|
||||||
}, label: {
|
}, label: {
|
||||||
Text("Create")
|
Text("Create")
|
||||||
@@ -55,6 +47,19 @@ struct AddFlashCard: View {
|
|||||||
.navigationTitle("Add Flashcard")
|
.navigationTitle("Add Flashcard")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func createFlashcard() {
|
||||||
|
let flashcard = Flashcard(context: moc)
|
||||||
|
flashcard.id = UUID()
|
||||||
|
flashcard.name = self.text
|
||||||
|
flashcard.desc = self.description
|
||||||
|
flashcard.nextSpacedRepetitionMilestone = 0
|
||||||
|
flashcard.lastSeenOn = nil
|
||||||
|
flashcard.shownCount = 0
|
||||||
|
flashcard.dateAdded = Date()
|
||||||
|
try? moc.save()
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct AnkiView: View {
|
|||||||
// .font(.subheadline)
|
// .font(.subheadline)
|
||||||
// .foregroundStyle(.gray)
|
// .foregroundStyle(.gray)
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
|
// TODO: Fix timeText, maybe using DateIntervallFormatter?
|
||||||
NextRepetitionButtonView(
|
NextRepetitionButtonView(
|
||||||
buttonText: "Wrong",
|
buttonText: "Wrong",
|
||||||
nextMilestone: flashcards.first!.getSpacedRepetitionMilestone(),
|
nextMilestone: flashcards.first!.getSpacedRepetitionMilestone(),
|
||||||
|
|||||||
@@ -12,18 +12,28 @@ struct FlashCardListView: View {
|
|||||||
@State var showDescription = true
|
@State var showDescription = true
|
||||||
@State var addFlashcard = false
|
@State var addFlashcard = false
|
||||||
@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "dateAdded", ascending: false)]) var flashcards: FetchedResults<Flashcard>
|
@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "dateAdded", ascending: false)]) var flashcards: FetchedResults<Flashcard>
|
||||||
|
@Environment(\.managedObjectContext) var moc
|
||||||
var body: some View {
|
var body: some View {
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
Group {
|
Group {
|
||||||
if !flashcards.isEmpty {
|
if !flashcards.isEmpty {
|
||||||
List(flashcards) { flashcard in
|
List {
|
||||||
|
ForEach(flashcards) { flashcard in
|
||||||
NavigationLink {
|
NavigationLink {
|
||||||
FlashCardView(flashcard: flashcard, showDescription: $showDescription)
|
FlashCardView(flashcard: flashcard, showDescription: $showDescription)
|
||||||
} label: {
|
} label: {
|
||||||
FlashCardListRowView(flashcard: flashcard)
|
FlashCardListRowView(flashcard: flashcard)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onDelete(perform: { offsets in
|
||||||
|
for index in offsets {
|
||||||
|
let flashcard = flashcards[index]
|
||||||
|
moc.delete(flashcard)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Text("You currently don't have any flashcards. To add flashcards, either click at the '+' button at the top or you can download them from the store (coming soon)")
|
Text("You currently don't have any flashcards. To add flashcards, either click at the '+' button at the top or you can download them from the store (coming soon)")
|
||||||
@@ -35,6 +45,7 @@ struct FlashCardListView: View {
|
|||||||
}
|
}
|
||||||
.navigationTitle("All Flashcards")
|
.navigationTitle("All Flashcards")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
EditButton()
|
||||||
Button(action: {
|
Button(action: {
|
||||||
self.addFlashcard = true
|
self.addFlashcard = true
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
@@ -21,11 +21,17 @@ struct FlashCardView: View {
|
|||||||
.font(.title)
|
.font(.title)
|
||||||
.bold()
|
.bold()
|
||||||
VStack {
|
VStack {
|
||||||
|
// TODO: Figure out if this and create/edit menu could be more similar?
|
||||||
if flashcard.lastSeenOn != nil {
|
if flashcard.lastSeenOn != nil {
|
||||||
Text("Last seen: " + model.getDateFormatter().string(from: flashcard.lastSeenOn!))
|
Text("Last seen: " + model.getDateFormatter().string(from: flashcard.lastSeenOn!))
|
||||||
.font(.subheadline)
|
.font(.subheadline)
|
||||||
}
|
}
|
||||||
if showDescription {
|
if showDescription {
|
||||||
|
// TODO: Add more information here
|
||||||
|
if flashcard.shownCount != 0 {
|
||||||
|
Text("Already seen: \(flashcard.shownCount) \(flashcard.shownCount == 1 ? "time" : "times")")
|
||||||
|
.padding(.bottom)
|
||||||
|
}
|
||||||
flashcardText
|
flashcardText
|
||||||
.textSelection(.enabled)
|
.textSelection(.enabled)
|
||||||
Divider()
|
Divider()
|
||||||
@@ -47,7 +53,7 @@ struct FlashCardView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
@State var showDescription = false
|
@State var showDescription = true
|
||||||
let flashcard = try? DataController.preview.viewContext.fetch(Flashcard.fetchRequest()).first
|
let flashcard = try? DataController.preview.viewContext.fetch(Flashcard.fetchRequest()).first
|
||||||
return FlashCardView(flashcard: flashcard!, showDescription: $showDescription)
|
return FlashCardView(flashcard: flashcard!, showDescription: $showDescription)
|
||||||
.environmentObject(WordAXModelView())
|
.environmentObject(WordAXModelView())
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ class WordAXModelView: ObservableObject {
|
|||||||
let settings: Settings
|
let settings: Settings
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
let hourString = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: NSLocale.current)
|
||||||
let dateFormatter = DateFormatter()
|
let dateFormatter = DateFormatter()
|
||||||
dateFormatter.dateFormat = "dd/MM/YYYY"
|
dateFormatter.dateFormat = "dd/MM/YYYY \(hourString?.contains("a") ?? true ? "hh" : "HH"):mm\(hourString?.contains("a") ?? true ? " a" : "")"
|
||||||
self.settings = Settings(dateFormatter: dateFormatter)
|
self.settings = Settings(dateFormatter: dateFormatter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user