diff --git a/WordAX/Views/AddFlashCard.swift b/WordAX/Views/AddFlashCard.swift index 0adf647..db5d3e0 100644 --- a/WordAX/Views/AddFlashCard.swift +++ b/WordAX/Views/AddFlashCard.swift @@ -36,15 +36,7 @@ struct AddFlashCard: View { } ToolbarItemGroup(placement: .topBarTrailing) { Button(action: { - 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() + self.createFlashcard() self.isShowing = false }, label: { Text("Create") @@ -55,6 +47,19 @@ struct AddFlashCard: View { .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 { diff --git a/WordAX/Views/AnkiView.swift b/WordAX/Views/AnkiView.swift index cad5c3b..fd3bdda 100644 --- a/WordAX/Views/AnkiView.swift +++ b/WordAX/Views/AnkiView.swift @@ -36,6 +36,7 @@ struct AnkiView: View { // .font(.subheadline) // .foregroundStyle(.gray) HStack(alignment: .center) { + // TODO: Fix timeText, maybe using DateIntervallFormatter? NextRepetitionButtonView( buttonText: "Wrong", nextMilestone: flashcards.first!.getSpacedRepetitionMilestone(), diff --git a/WordAX/Views/FlashCardListView.swift b/WordAX/Views/FlashCardListView.swift index 8135eb4..6b26122 100644 --- a/WordAX/Views/FlashCardListView.swift +++ b/WordAX/Views/FlashCardListView.swift @@ -12,17 +12,27 @@ struct FlashCardListView: View { @State var showDescription = true @State var addFlashcard = false @FetchRequest(sortDescriptors: [NSSortDescriptor(key: "dateAdded", ascending: false)]) var flashcards: FetchedResults + @Environment(\.managedObjectContext) var moc var body: some View { GeometryReader { geometry in NavigationSplitView { Group { if !flashcards.isEmpty { - List(flashcards) { flashcard in - NavigationLink { - FlashCardView(flashcard: flashcard, showDescription: $showDescription) - } label: { - FlashCardListRowView(flashcard: flashcard) + List { + ForEach(flashcards) { flashcard in + NavigationLink { + FlashCardView(flashcard: flashcard, showDescription: $showDescription) + } label: { + FlashCardListRowView(flashcard: flashcard) + } } + .onDelete(perform: { offsets in + for index in offsets { + let flashcard = flashcards[index] + moc.delete(flashcard) + } + + }) } } else { @@ -35,6 +45,7 @@ struct FlashCardListView: View { } .navigationTitle("All Flashcards") .toolbar { + EditButton() Button(action: { self.addFlashcard = true }) { diff --git a/WordAX/Views/FlashCardView.swift b/WordAX/Views/FlashCardView.swift index 60a8148..0a772d2 100644 --- a/WordAX/Views/FlashCardView.swift +++ b/WordAX/Views/FlashCardView.swift @@ -21,11 +21,17 @@ struct FlashCardView: View { .font(.title) .bold() VStack { + // TODO: Figure out if this and create/edit menu could be more similar? if flashcard.lastSeenOn != nil { Text("Last seen: " + model.getDateFormatter().string(from: flashcard.lastSeenOn!)) .font(.subheadline) } if showDescription { + // TODO: Add more information here + if flashcard.shownCount != 0 { + Text("Already seen: \(flashcard.shownCount) \(flashcard.shownCount == 1 ? "time" : "times")") + .padding(.bottom) + } flashcardText .textSelection(.enabled) Divider() @@ -47,7 +53,7 @@ struct FlashCardView: View { } #Preview { - @State var showDescription = false + @State var showDescription = true let flashcard = try? DataController.preview.viewContext.fetch(Flashcard.fetchRequest()).first return FlashCardView(flashcard: flashcard!, showDescription: $showDescription) .environmentObject(WordAXModelView()) diff --git a/WordAX/WordAXModelView.swift b/WordAX/WordAXModelView.swift index 585d105..f61a8c7 100644 --- a/WordAX/WordAXModelView.swift +++ b/WordAX/WordAXModelView.swift @@ -14,8 +14,9 @@ class WordAXModelView: ObservableObject { let settings: Settings init() { + let hourString = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: NSLocale.current) 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) }