Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
takasurazeem committed Sep 22, 2023
1 parent 580619e commit 4c19fa6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
5 changes: 0 additions & 5 deletions QuranMajeed/Quiz/Main/Model/QuranModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

import Foundation

enum TypeEnum: String, Codable {
case meccan = "meccan"
case medinan = "medinan"
}

// MARK: - Verse
struct Verse: Codable, Identifiable, Hashable, Comparable {
static func < (lhs: Verse, rhs: Verse) -> Bool {
Expand Down
49 changes: 11 additions & 38 deletions QuranMajeed/Quiz/Main/View/QuizView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ struct QuizView: View {
Section("Select Verses") {
NavigationLink {
VerseListView(
selectedVerses: $viewModel.selectedVerses,
selectedSuraVerses: viewModel.versesOfSelectedSura
)
} label: {
Text(viewModel.selectedVerse.text)
HStack {
Text(viewModel.selectedVerse.text)
}
}
/*
NavigationLink(
Expand All @@ -56,20 +59,17 @@ struct QuizView: View {
.deleteDisabled(true)
Section("Selected Verses") {
ForEach(viewModel.selectedVerses) { verse in
Text(verse.text)
.font(Font.custom("ScheherazadeNew-Bold", size: 24.0))
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity, alignment: .trailing)
HStack {
Text(("\(verse.ayaNumber)"))
Text(verse.text)
.font(Font.custom("ScheherazadeNew-Bold", size: 24.0))
.frame(maxWidth: .infinity, alignment: .trailing)
.multilineTextAlignment(.trailing)
}
}
.onDelete(perform: viewModel.delete(at:))
}
}

Button("Add") {
viewModel.addSelectedVerseToQuiz()
proxy.scrollTo(viewModel.selectedVerses.last, anchor: .bottom)
}
.buttonStyle(PrimaryButtonStyle())
}
.navigationTitle("Prepare Quiz")
.toolbar {
Expand Down Expand Up @@ -105,19 +105,6 @@ struct QuizView: View {
}
}

struct PrimaryButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.buttonStyle(.plain)
.frame(maxWidth: .infinity)
.frame(height: 45)
.foregroundColor(.white)
.background(Color(r: 32, g: 35, b: 37))
.clipShape(RoundedRectangle(cornerRadius: 8))
.padding(16)
}
}

/* FIXME: - Fix later
struct QuizView_Previews: PreviewProvider {
static let quizVerses = Bundle.main.decode(Surahs.self, from: "Quran_ur.json").first(where: {$0.id==67})?.verses.compactMap({
Expand Down Expand Up @@ -165,17 +152,3 @@ struct QuizView_Previews: PreviewProvider {
}
}
*/
extension Color {

init(
r: Double,
g: Double,
b: Double
) {
self.init(
red: r/255,
green: g/255,
blue: b/255)
}

}
24 changes: 22 additions & 2 deletions QuranMajeed/Quiz/Main/View/VerseListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import SwiftUI

struct VerseListView: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.editMode) private var editMode
@State var defaultEditMode = EditMode.active /// the edit mode
@State private var searchText = ""
var selectedSuraVerses: [Verse] = []
@State private var selection = Set<Verse>()

@Binding var selectedVerses: [Verse]
var selectedSuraVerses: [Verse] = []
var searchResults: [Verse] {
if searchText.isEmpty {
return selectedSuraVerses
Expand All @@ -29,6 +33,22 @@ struct VerseListView: View {
.multilineTextAlignment(.trailing)
}
}
.environment(\.editMode, $defaultEditMode)
.onDisappear {
defaultEditMode = .inactive
}
.onChange(of: selection) { newValue in
if newValue.count > 0 {
selectedVerses = Array(selection).sorted()
}
}
.onChange(of: editMode?.wrappedValue) { newValue in
if newValue == EditMode.inactive {
dismiss()
} else {
// Leaving edit mode (e.g. 'Done' tapped)
}
}
.searchable(text: $searchText)
.navigationTitle("Ayah Selection")
.toolbar { EditButton() }
Expand All @@ -43,7 +63,7 @@ fileprivate struct ContentPreview: View {
@State var allVerses: [Verse] = []
var body: some View {
NavigationStack {
VerseListView(selectedSuraVerses: allVerses)
VerseListView(selectedVerses: .constant([]), selectedSuraVerses: allVerses)
.task {
let repo = try! AppDependencyContainer
.shared
Expand Down

0 comments on commit 4c19fa6

Please sign in to comment.