Renamed word to FlashCard in all files
This commit is contained in:
@@ -11,10 +11,10 @@
|
||||
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */; };
|
||||
6C8185022B88C9FB0033CF46 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185012B88C9FB0033CF46 /* SettingsView.swift */; };
|
||||
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185032B88CA210033CF46 /* AnkiView.swift */; };
|
||||
6C8185062B8A537F0033CF46 /* WordView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185052B8A537F0033CF46 /* WordView.swift */; };
|
||||
6C8185062B8A537F0033CF46 /* FlashCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185052B8A537F0033CF46 /* FlashCardView.swift */; };
|
||||
6C8185082B8B523E0033CF46 /* NextRepetitionButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */; };
|
||||
6C81850A2B8BA5740033CF46 /* WordListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185092B8BA5740033CF46 /* WordListView.swift */; };
|
||||
6C81850C2B8BA6BC0033CF46 /* WordListRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C81850B2B8BA6BC0033CF46 /* WordListRowView.swift */; };
|
||||
6C81850A2B8BA5740033CF46 /* FlashCardListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185092B8BA5740033CF46 /* FlashCardListView.swift */; };
|
||||
6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */; };
|
||||
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439512B83541D004C3543 /* WordAXApp.swift */; };
|
||||
6CF439542B83541D004C3543 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439532B83541D004C3543 /* MainView.swift */; };
|
||||
6CF439562B83541E004C3543 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CF439552B83541E004C3543 /* Assets.xcassets */; };
|
||||
@@ -26,10 +26,10 @@
|
||||
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXModelView.swift; sourceTree = "<group>"; };
|
||||
6C8185012B88C9FB0033CF46 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||
6C8185032B88CA210033CF46 /* AnkiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnkiView.swift; sourceTree = "<group>"; };
|
||||
6C8185052B8A537F0033CF46 /* WordView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordView.swift; sourceTree = "<group>"; };
|
||||
6C8185052B8A537F0033CF46 /* FlashCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardView.swift; sourceTree = "<group>"; };
|
||||
6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextRepetitionButtonView.swift; sourceTree = "<group>"; };
|
||||
6C8185092B8BA5740033CF46 /* WordListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordListView.swift; sourceTree = "<group>"; };
|
||||
6C81850B2B8BA6BC0033CF46 /* WordListRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordListRowView.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>"; };
|
||||
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>"; };
|
||||
6CF439532B83541D004C3543 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
|
||||
@@ -69,11 +69,11 @@
|
||||
children = (
|
||||
6CF439512B83541D004C3543 /* WordAXApp.swift */,
|
||||
6CF439532B83541D004C3543 /* MainView.swift */,
|
||||
6C8185092B8BA5740033CF46 /* WordListView.swift */,
|
||||
6C81850B2B8BA6BC0033CF46 /* WordListRowView.swift */,
|
||||
6C8185092B8BA5740033CF46 /* FlashCardListView.swift */,
|
||||
6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */,
|
||||
6C8185012B88C9FB0033CF46 /* SettingsView.swift */,
|
||||
6C8185032B88CA210033CF46 /* AnkiView.swift */,
|
||||
6C8185052B8A537F0033CF46 /* WordView.swift */,
|
||||
6C8185052B8A537F0033CF46 /* FlashCardView.swift */,
|
||||
6C8185072B8B523D0033CF46 /* NextRepetitionButtonView.swift */,
|
||||
6C8184FD2B88C9580033CF46 /* WordAX.swift */,
|
||||
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */,
|
||||
@@ -164,13 +164,13 @@
|
||||
6C8185022B88C9FB0033CF46 /* SettingsView.swift in Sources */,
|
||||
6CF439542B83541D004C3543 /* MainView.swift in Sources */,
|
||||
6C8185082B8B523E0033CF46 /* NextRepetitionButtonView.swift in Sources */,
|
||||
6C8185062B8A537F0033CF46 /* WordView.swift in Sources */,
|
||||
6C81850A2B8BA5740033CF46 /* WordListView.swift in Sources */,
|
||||
6C8185062B8A537F0033CF46 /* FlashCardView.swift in Sources */,
|
||||
6C81850A2B8BA5740033CF46 /* FlashCardListView.swift in Sources */,
|
||||
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */,
|
||||
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */,
|
||||
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */,
|
||||
6C8184FE2B88C9580033CF46 /* WordAX.swift in Sources */,
|
||||
6C81850C2B8BA6BC0033CF46 /* WordListRowView.swift in Sources */,
|
||||
6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -9,15 +9,15 @@ import SwiftUI
|
||||
|
||||
struct AnkiView: View {
|
||||
@EnvironmentObject var model: WordAXModelView
|
||||
@State var showDescription = true
|
||||
var word: WordAX.FlashCard? {
|
||||
model.getWordToDisplay()
|
||||
@State var showDescription = false
|
||||
var flashcard: WordAX.FlashCard? {
|
||||
model.getFlashCardsToDisplay()
|
||||
}
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
if word != nil {
|
||||
if flashcard != nil {
|
||||
VStack {
|
||||
WordView(word: word!, showDescription: $showDescription)
|
||||
FlashCardView(flashcard: flashcard!, showDescription: $showDescription)
|
||||
if showDescription {
|
||||
// Text("How did you do?")
|
||||
// .font(.subheadline)
|
||||
@@ -25,8 +25,8 @@ struct AnkiView: View {
|
||||
HStack(alignment: .center) {
|
||||
NextRepetitionButtonView(
|
||||
buttonText: "Wrong",
|
||||
nextMilestone: word!.nextSpacedRepetitionMilestone,
|
||||
wordId: word!.id,
|
||||
nextMilestone: flashcard!.nextSpacedRepetitionMilestone,
|
||||
flashcardId: flashcard!.id,
|
||||
width: geometry.size.width,
|
||||
color: .red,
|
||||
geometry: geometry,
|
||||
@@ -35,8 +35,8 @@ struct AnkiView: View {
|
||||
)
|
||||
NextRepetitionButtonView(
|
||||
buttonText: "Correct",
|
||||
nextMilestone: WordAX.SpacedRepetitionMilestoneEnum.getNext(milestone: word!.nextSpacedRepetitionMilestone),
|
||||
wordId: word!.id,
|
||||
nextMilestone: WordAX.SpacedRepetitionMilestoneEnum.getNext(milestone: flashcard!.nextSpacedRepetitionMilestone),
|
||||
flashcardId: flashcard!.id,
|
||||
width:geometry.size.width,
|
||||
color: .orange,
|
||||
geometry: geometry,
|
||||
@@ -45,8 +45,8 @@ struct AnkiView: View {
|
||||
)
|
||||
NextRepetitionButtonView(
|
||||
buttonText: "Easy",
|
||||
nextMilestone: WordAX.SpacedRepetitionMilestoneEnum.getNext(milestone: WordAX.SpacedRepetitionMilestoneEnum.getNext(milestone: word!.nextSpacedRepetitionMilestone)),
|
||||
wordId: word!.id,
|
||||
nextMilestone: WordAX.SpacedRepetitionMilestoneEnum.getNext(milestone: WordAX.SpacedRepetitionMilestoneEnum.getNext(milestone: flashcard!.nextSpacedRepetitionMilestone)),
|
||||
flashcardId: flashcard!.id,
|
||||
width: geometry.size.width,
|
||||
color: .green,
|
||||
geometry: geometry,
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct WordListRowView: View {
|
||||
struct FlashCardListRowView: View {
|
||||
@EnvironmentObject var model: WordAXModelView
|
||||
var word: WordAX.FlashCard
|
||||
var flashcard: WordAX.FlashCard
|
||||
@State var favorite = true
|
||||
var body: some View {
|
||||
HStack {
|
||||
@@ -30,12 +30,12 @@ struct WordListRowView: View {
|
||||
}
|
||||
.padding(.trailing)
|
||||
VStack {
|
||||
Text(word.name)
|
||||
Text(flashcard.name)
|
||||
.bold()
|
||||
.font(.system(size: 19))
|
||||
.multilineTextAlignment(.leading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Text(word.description)
|
||||
Text(flashcard.description)
|
||||
.multilineTextAlignment(.leading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(1)
|
||||
@@ -47,11 +47,11 @@ struct WordListRowView: View {
|
||||
|
||||
#Preview {
|
||||
Group {
|
||||
WordListRowView(word: WordAX.FlashCard(id: 0, name: "Mesmerizing", description: "Some very long description like Lorem Ipsum which I'm to lazy to copy", shown: false, nextSpacedRepetitionMilestone: WordAX.SpacedRepetitionMilestoneEnum.OneDay, lastSeenOn: Date(), shownCount: 1))
|
||||
FlashCardListRowView(flashcard: WordAX.FlashCard(id: 0, name: "Mesmerizing", description: "Some very long description like Lorem Ipsum which I'm to lazy to copy", shown: false, nextSpacedRepetitionMilestone: WordAX.SpacedRepetitionMilestoneEnum.OneDay, lastSeenOn: Date(), shownCount: 1))
|
||||
.environmentObject(WordAXModelView())
|
||||
WordListRowView(word: WordAX.FlashCard(id: 0, name: "Mesmerizing", description: "Some very long description like Lorem Ipsum which I'm to lazy to copy", shown: false, nextSpacedRepetitionMilestone: WordAX.SpacedRepetitionMilestoneEnum.OneDay, lastSeenOn: Date(), shownCount: 1))
|
||||
FlashCardListRowView(flashcard: WordAX.FlashCard(id: 0, name: "Mesmerizing", description: "Some very long description like Lorem Ipsum which I'm to lazy to copy", shown: false, nextSpacedRepetitionMilestone: WordAX.SpacedRepetitionMilestoneEnum.OneDay, lastSeenOn: Date(), shownCount: 1))
|
||||
.environmentObject(WordAXModelView())
|
||||
WordListRowView(word: WordAX.FlashCard(id: 0, name: "Mesmerizing", description: "Some very long description like Lorem Ipsum which I'm to lazy to copy", shown: false, nextSpacedRepetitionMilestone: WordAX.SpacedRepetitionMilestoneEnum.OneDay, lastSeenOn: Date(), shownCount: 1))
|
||||
FlashCardListRowView(flashcard: WordAX.FlashCard(id: 0, name: "Mesmerizing", description: "Some very long description like Lorem Ipsum which I'm to lazy to copy", shown: false, nextSpacedRepetitionMilestone: WordAX.SpacedRepetitionMilestoneEnum.OneDay, lastSeenOn: Date(), shownCount: 1))
|
||||
.environmentObject(WordAXModelView())
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,16 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct WordListView: View {
|
||||
struct FlashCardListView: View {
|
||||
@EnvironmentObject var model: WordAXModelView
|
||||
@State var showDescription = true
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
List(model.words) { word in
|
||||
List(model.flashcards) { word in
|
||||
NavigationLink {
|
||||
WordView(word: word, showDescription: $showDescription)
|
||||
FlashCardView(flashcard: word, showDescription: $showDescription)
|
||||
} label: {
|
||||
WordListRowView(word: word)
|
||||
FlashCardListRowView(flashcard: word)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Word List")
|
||||
@@ -27,6 +27,6 @@ struct WordListView: View {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
WordListView()
|
||||
FlashCardListView()
|
||||
.environmentObject(WordAXModelView())
|
||||
}
|
||||
@@ -8,32 +8,32 @@
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
struct WordView: View {
|
||||
var word: WordAX.FlashCard
|
||||
struct FlashCardView: View {
|
||||
var flashcard: WordAX.FlashCard
|
||||
@Binding var showDescription: Bool
|
||||
@EnvironmentObject var model: WordAXModelView
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
|
||||
var body: some View {
|
||||
let wordText = Text(word.name)
|
||||
let flashcardText = Text(flashcard.name)
|
||||
.font(.title)
|
||||
.bold()
|
||||
VStack {
|
||||
if word.shown && word.lastSeenOn != nil {
|
||||
Text("Last seen: " + model.getDateFormatter().string(from: word.lastSeenOn!))
|
||||
if flashcard.shown && flashcard.lastSeenOn != nil {
|
||||
Text("Last seen: " + model.getDateFormatter().string(from: flashcard.lastSeenOn!))
|
||||
.font(.subheadline)
|
||||
}
|
||||
if showDescription {
|
||||
wordText
|
||||
flashcardText
|
||||
.textSelection(.enabled)
|
||||
Divider()
|
||||
.background(colorScheme == .light ? Color.black : Color.white)
|
||||
.padding(.horizontal)
|
||||
Text(word.description)
|
||||
Text(flashcard.description)
|
||||
.multilineTextAlignment(.center)
|
||||
} else {
|
||||
wordText
|
||||
flashcardText
|
||||
}
|
||||
}
|
||||
.padding([.horizontal, .top])
|
||||
@@ -47,6 +47,6 @@ struct WordView: View {
|
||||
|
||||
#Preview {
|
||||
@State var showDescription = false
|
||||
return WordView(word: WordAXModelView().getWordToDisplay()!, showDescription: $showDescription)
|
||||
return FlashCardView(flashcard: WordAXModelView().getFlashCardsToDisplay()!, showDescription: $showDescription)
|
||||
.environmentObject(WordAXModelView())
|
||||
}
|
||||
@@ -22,11 +22,11 @@ struct MainView: View {
|
||||
Image(systemName: "star")
|
||||
Text("Anki")
|
||||
}
|
||||
WordListView()
|
||||
.tag("Word List")
|
||||
FlashCardListView()
|
||||
.tag("Flashcards")
|
||||
.tabItem {
|
||||
Image(systemName: "list.bullet")
|
||||
Text("Word List")
|
||||
Text("Flashcards")
|
||||
}
|
||||
SettingsView()
|
||||
.tag("Settings")
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
struct NextRepetitionButtonView: View {
|
||||
let buttonText: String
|
||||
let nextMilestone: WordAX.SpacedRepetitionMilestoneEnum?
|
||||
let wordId: Int
|
||||
let flashcardId: Int
|
||||
let width: CGFloat
|
||||
let color: Color
|
||||
let geometry: GeometryProxy
|
||||
@@ -21,7 +21,7 @@ struct NextRepetitionButtonView: View {
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
var body: some View {
|
||||
Button(action: {
|
||||
model.ankiButtonClicked(wordId: wordId, milestone: nextMilestone)
|
||||
model.ankiButtonClicked(flashcardId: flashcardId, milestone: nextMilestone)
|
||||
self.showDescription = false
|
||||
}) {
|
||||
VStack {
|
||||
|
||||
@@ -26,23 +26,26 @@ struct WordAX {
|
||||
}
|
||||
|
||||
enum SpacedRepetitionMilestoneEnum: Int, CaseIterable {
|
||||
case OneDay = 1
|
||||
case OneWeek = 7
|
||||
case TwoWeeks = 14
|
||||
case OneMonth = 30
|
||||
case TwoMonths = 60
|
||||
case FiveMonths = 150
|
||||
case OneYear = 365
|
||||
case OneMinute = 60 // 60 * 1
|
||||
case TenMinutes = 600 // 60 * 10
|
||||
case OneHour = 3600 // 60 * 60
|
||||
case OneDay = 86_400 // 24 * 60 * 60
|
||||
case OneWeek = 604_800 // 24 * 60 * 60 * 7
|
||||
case TwoWeeks = 1_209_600 // 24 * 60 * 60 * 14
|
||||
case OneMonth = 2_592_000 // 24 * 60 * 60 * 30
|
||||
case TwoMonths = 5_184_000 // 24 * 60 * 60 * 60
|
||||
case FiveMonths = 12_960_000 // 24 * 60 * 60 * 150
|
||||
case OneYear = 31_536_000 // 24 * 60 * 60 * 365
|
||||
|
||||
static var allCasesSorted: [SpacedRepetitionMilestoneEnum] {
|
||||
allCases.sorted {$0.rawValue < $1.rawValue }
|
||||
}
|
||||
|
||||
static func getNext(milestone: SpacedRepetitionMilestoneEnum?) -> SpacedRepetitionMilestoneEnum? {
|
||||
if milestone == nil {
|
||||
return SpacedRepetitionMilestoneEnum.OneDay
|
||||
}
|
||||
let sorted = WordAX.SpacedRepetitionMilestoneEnum.allCasesSorted
|
||||
if milestone == nil {
|
||||
return sorted.first
|
||||
}
|
||||
let milestoneIndex = sorted.firstIndex(where: {$0.rawValue == milestone!.rawValue})!
|
||||
if milestoneIndex < WordAX.SpacedRepetitionMilestoneEnum.allCasesSorted.count {
|
||||
return sorted[milestoneIndex + 1]
|
||||
@@ -57,47 +60,51 @@ struct WordAX {
|
||||
var dateFormatter: DateFormatter
|
||||
}
|
||||
|
||||
public mutating func setNextSpacedRepetitionMilestone(word: FlashCard) {
|
||||
if word.nextSpacedRepetitionMilestone != nil {
|
||||
let current = SpacedRepetitionMilestoneEnum.allCasesSorted.firstIndex(of: word.nextSpacedRepetitionMilestone!) ?? SpacedRepetitionMilestoneEnum.allCases.count
|
||||
let index = words.firstIndex(where:{$0.id == word.id}) ?? nil
|
||||
public mutating func setNextSpacedRepetitionMilestone(flashcard: FlashCard) {
|
||||
if flashcard.nextSpacedRepetitionMilestone != nil {
|
||||
let current = SpacedRepetitionMilestoneEnum.allCasesSorted.firstIndex(of: flashcard.nextSpacedRepetitionMilestone!) ?? SpacedRepetitionMilestoneEnum.allCases.count
|
||||
let index = flashcards.firstIndex(where:{$0.id == flashcard.id}) ?? nil
|
||||
if current + 1 < SpacedRepetitionMilestoneEnum.allCases.count && index != nil {
|
||||
words[index!].nextSpacedRepetitionMilestone = SpacedRepetitionMilestoneEnum.allCasesSorted[current + 1]
|
||||
flashcards[index!].nextSpacedRepetitionMilestone = SpacedRepetitionMilestoneEnum.allCasesSorted[current + 1]
|
||||
} else if index != nil {
|
||||
words[index!].nextSpacedRepetitionMilestone = nil
|
||||
flashcards[index!].nextSpacedRepetitionMilestone = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public mutating func setSpacedRepetitionMilestone(wordId: Int, milestone: SpacedRepetitionMilestoneEnum?) {
|
||||
let index = words.firstIndex(where:{$0.id == wordId}) ?? nil
|
||||
public mutating func setSpacedRepetitionMilestone(flashcardId: Int, milestone: SpacedRepetitionMilestoneEnum?) {
|
||||
let index = flashcards.firstIndex(where:{$0.id == flashcardId}) ?? nil
|
||||
if index != nil {
|
||||
words[index!].nextSpacedRepetitionMilestone = milestone
|
||||
if !words[index!].shown {
|
||||
words[index!].shown = true
|
||||
flashcards[index!].nextSpacedRepetitionMilestone = milestone
|
||||
if !flashcards[index!].shown {
|
||||
flashcards[index!].shown = true
|
||||
}
|
||||
words[index!].lastSeenOn = Date()
|
||||
flashcards[index!].lastSeenOn = Date()
|
||||
}
|
||||
}
|
||||
|
||||
public mutating func wordShown(wordId: Int) {
|
||||
let index = words.firstIndex(where:{$0.id == wordId}) ?? nil
|
||||
public mutating func flashcardShown(flashcardId: Int) {
|
||||
let index = flashcards.firstIndex(where:{$0.id == flashcardId}) ?? nil
|
||||
if index != nil {
|
||||
words[index!].shownCount += 1
|
||||
flashcards[index!].shownCount += 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var words: [FlashCard] = []
|
||||
var flashcards: [FlashCard] = []
|
||||
var settings: Settings
|
||||
|
||||
public mutating func add(flashcard: FlashCard) {
|
||||
self.flashcards.append(flashcard)
|
||||
}
|
||||
|
||||
init() {
|
||||
self.words = []
|
||||
self.flashcards = []
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "dd/MM/YYYY"
|
||||
self.settings = Settings(dateFormatter: dateFormatter)
|
||||
self.words.append(FlashCard(id: 0, name: "Magnificent", description: "When something is awesome. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.", shown: false))
|
||||
self.words.append(FlashCard(id: 1, name: "Mesmerising", description: "When something is beautiful", shown: false))
|
||||
self.flashcards.append(FlashCard(id: 0, name: "Magnificent", description: "When something is awesome. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.", shown: false))
|
||||
self.flashcards.append(FlashCard(id: 1, name: "Mesmerising", description: "When something is beautiful", shown: false))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,37 +9,37 @@ import Foundation
|
||||
|
||||
class WordAXModelView: ObservableObject {
|
||||
@Published private var model: WordAX
|
||||
typealias Word = WordAX.FlashCard
|
||||
typealias FlashCard = WordAX.FlashCard
|
||||
init() {
|
||||
model = WordAX()
|
||||
}
|
||||
|
||||
public var words: [Word] {
|
||||
model.words
|
||||
public var flashcards: [FlashCard] {
|
||||
model.flashcards
|
||||
}
|
||||
|
||||
public func getDateFormatter() -> DateFormatter {
|
||||
model.settings.dateFormatter
|
||||
}
|
||||
|
||||
public func getWordToDisplay() -> Word? {
|
||||
let words = model.words
|
||||
public func getFlashCardsToDisplay() -> FlashCard? {
|
||||
let flashcards = model.flashcards
|
||||
|
||||
if words.count > 0 {
|
||||
let notShownWords = words.filter({!$0.shown})
|
||||
if notShownWords.count == 0 {
|
||||
if flashcards.count > 0 {
|
||||
let notShownFlashCards = flashcards.filter({!$0.shown})
|
||||
if notShownFlashCards.count == 0 {
|
||||
return nil
|
||||
}
|
||||
// if today is the date they're supposed to be shown
|
||||
|
||||
let displayToday = words.filter({ $0.lastSeenOn != nil && $0.lastSeenOn!.addSpacedRepetitionMilestone(milestone: $0.nextSpacedRepetitionMilestone).isBeforeTodayOrToday()})
|
||||
let displayToday = flashcards.filter({ $0.lastSeenOn != nil && $0.lastSeenOn!.addSpacedRepetitionMilestone(milestone: $0.nextSpacedRepetitionMilestone).isBeforeTodayOrToday()})
|
||||
if displayToday.count > 0 {
|
||||
return displayToday.first!
|
||||
}
|
||||
|
||||
// let shownWords = words.filter({ $0.shown })
|
||||
// if shownWords.count == 0 {
|
||||
return notShownWords.sorted(by: {$0.id < $1.id}).first
|
||||
return notShownFlashCards.sorted(by: {$0.id < $1.id}).first
|
||||
// }
|
||||
// if today is the day to show a new word
|
||||
// let settings = model.settings
|
||||
@@ -53,9 +53,9 @@ class WordAXModelView: ObservableObject {
|
||||
return nil
|
||||
}
|
||||
|
||||
public func ankiButtonClicked(wordId: Int, milestone: WordAX.SpacedRepetitionMilestoneEnum?) {
|
||||
model.setSpacedRepetitionMilestone(wordId: wordId, milestone: milestone)
|
||||
model.wordShown(wordId: wordId)
|
||||
public func ankiButtonClicked(flashcardId: Int, milestone: WordAX.SpacedRepetitionMilestoneEnum?) {
|
||||
model.setSpacedRepetitionMilestone(flashcardId: flashcardId, milestone: milestone)
|
||||
model.flashcardShown(flashcardId: flashcardId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user