Skip to content

Commit

Permalink
Simplify names screen in the Example app
Browse files Browse the repository at this point in the history
  • Loading branch information
kosratdev committed Mar 25, 2024
1 parent 09f07b6 commit 9ce71b7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 121 deletions.
16 changes: 0 additions & 16 deletions Example/MuslimDataExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
6A22480F2BAED7960094967B /* NamesRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A22480E2BAED7960094967B /* NamesRowView.swift */; };
6A2248112BAEDAEE0094967B /* NamesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2248102BAEDAED0094967B /* NamesViewModel.swift */; };
6A2248152BAEDB4E0094967B /* MuslimData in Frameworks */ = {isa = PBXBuildFile; productRef = 6A2248142BAEDB4E0094967B /* MuslimData */; };
6A2248182BAEE1990094967B /* ErrorWithRetryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2248172BAEE1990094967B /* ErrorWithRetryView.swift */; };
6A22481A2BAEEBFB0094967B /* AppTabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A2248192BAEEBFB0094967B /* AppTabs.swift */; };
6A787B1C2BAECF6F00DA0107 /* MuslimDataExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A787B1B2BAECF6F00DA0107 /* MuslimDataExampleApp.swift */; };
6A787B1E2BAECF6F00DA0107 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A787B1D2BAECF6F00DA0107 /* ContentView.swift */; };
6A787B202BAECF7200DA0107 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A787B1F2BAECF7200DA0107 /* Assets.xcassets */; };
Expand All @@ -24,8 +22,6 @@
6A22480E2BAED7960094967B /* NamesRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamesRowView.swift; sourceTree = "<group>"; };
6A2248102BAEDAED0094967B /* NamesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamesViewModel.swift; sourceTree = "<group>"; };
6A2248132BAEDB050094967B /* muslim-data-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "muslim-data-ios"; path = ..; sourceTree = "<group>"; };
6A2248172BAEE1990094967B /* ErrorWithRetryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorWithRetryView.swift; sourceTree = "<group>"; };
6A2248192BAEEBFB0094967B /* AppTabs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTabs.swift; sourceTree = "<group>"; };
6A787B182BAECF6F00DA0107 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
6A787B1B2BAECF6F00DA0107 /* MuslimDataExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuslimDataExampleApp.swift; sourceTree = "<group>"; };
6A787B1D2BAECF6F00DA0107 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -63,15 +59,6 @@
name = Frameworks;
sourceTree = "<group>";
};
6A2248162BAEE1880094967B /* Shared */ = {
isa = PBXGroup;
children = (
6A2248172BAEE1990094967B /* ErrorWithRetryView.swift */,
6A2248192BAEEBFB0094967B /* AppTabs.swift */,
);
path = Shared;
sourceTree = "<group>";
};
6A787B0F2BAECF6F00DA0107 = {
isa = PBXGroup;
children = (
Expand All @@ -92,7 +79,6 @@
6A787B1A2BAECF6F00DA0107 /* MuslimDataExample */ = {
isa = PBXGroup;
children = (
6A2248162BAEE1880094967B /* Shared */,
6A22480B2BAED7730094967B /* Names */,
6A787B1B2BAECF6F00DA0107 /* MuslimDataExampleApp.swift */,
6A787B1D2BAECF6F00DA0107 /* ContentView.swift */,
Expand Down Expand Up @@ -183,8 +169,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6A22481A2BAEEBFB0094967B /* AppTabs.swift in Sources */,
6A2248182BAEE1990094967B /* ErrorWithRetryView.swift in Sources */,
6A22480F2BAED7960094967B /* NamesRowView.swift in Sources */,
6A22480D2BAED7840094967B /* NamesScreen.swift in Sources */,
6A787B1E2BAECF6F00DA0107 /* ContentView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
{
"originHash" : "d74d0ac244973253b6ab6ca55279e1495dd27d9c84571fa4571b37d82a389f45",
"originHash" : "3b2a1b99aedb4ce24cdd643637ecbc2ac01b64f9fcc6462aa023925eb3dfc85c",
"pins" : [
{
"identity" : "csqlite",
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/CSQLite.git",
"state" : {
"revision" : "3a405d0ebd8bf07d4c41a8b05a203e4d03415b5b",
"version" : "0.3.0"
}
},
{
"identity" : "grdb.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/GRDB.swift.git",
"state" : {
"revision" : "49a7b2091c84e8e695e78ada1840eda022e5dc11",
"version" : "4.0.1"
"revision" : "77b85bed259b7f107710a0b78c439b1c5839dc45",
"version" : "6.26.0"
}
}
],
Expand Down
18 changes: 12 additions & 6 deletions Example/MuslimDataExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@
import SwiftUI

struct ContentView: View {
@State private var tab: AppTabs = .prayerTime
@State private var selection: AppTabs = .prayerTime
enum AppTabs {
case prayerTime
case names
case azkar
}

var body: some View {
TabView(selection: $tab) {
TabView(selection: $selection) {
Text("Prayer Time")
.tabItem {
Image("ic_nav_prayers")
Text("Prayer Time")
}.tag(1)
Text("Prayer Times")
}.tag(AppTabs.prayerTime)
NamesScreen()
.tabItem {
Image("ic_nav_names")
Text("Names")
}.tag(2)
}.tag(AppTabs.names)
Text("Azkar")
.tabItem {
Image("ic_nav_azkars")
Text("Azkar")
}.tag(3)
}.tag(AppTabs.azkar)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Example/MuslimDataExample/Names/NamesRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import MuslimData
/// - name: The `Name` data to be displayed in the row.
struct NamesRowView: View {
let name: Name

var body: some View {
VStack(alignment: .leading){
Text(name.name)
Expand All @@ -28,5 +29,5 @@ struct NamesRowView: View {
}

#Preview {
NamesRowView(name: .init(name: "", translated: ""))
NamesRowView(name: .init(name: "اللە", translated: "Allah"))
}
17 changes: 4 additions & 13 deletions Example/MuslimDataExample/Names/NamesScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,15 @@

import SwiftUI

/// Displays a list of the Names of Allah. Handles loading, error states, and data presentation.
/// Displays a list of the Names of Allah.
struct NamesScreen: View {
@ObservedObject private var viewModel = NamesViewModel()
private var viewModel = NamesViewModel()

var body: some View {
NavigationStack{
List {
if viewModel.isLoading {
ProgressView("Loading...")
} else if let error = viewModel.error {
ErrorWithRetryView(title: "Error loading names!",
errorMessage: error.localizedDescription) {
viewModel.getNamesOfAllah()
}
} else {
ForEach(viewModel.names, id: \.name) { name in
NamesRowView(name: name)
}
ForEach(viewModel.names, id: \.name) { name in
NamesRowView(name: name)
}
}
.listStyle(.plain)
Expand Down
15 changes: 6 additions & 9 deletions Example/MuslimDataExample/Names/NamesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,24 @@
import Foundation
import MuslimData

/// Manages the state for a list of Names of Allah. Responsible for fetching data, handling loading states, and potential errors.
class NamesViewModel: ObservableObject {
@Published private(set) var names: [Name] = []
@Published private(set) var isLoading = false
@Published private(set) var error: Error? = nil
/// Manages the state for a list of Names of Allah. Responsible for fetching data.
@Observable
class NamesViewModel {
private(set) var names: [Name] = []

/// Initializes the view model and starts fetching the Names of Allah.
init() {
getNamesOfAllah()
}

/// Fetches the Names of Allah from the `MuslimRepository`. Manages loading and error states.
/// Fetches the Names of Allah from the `MuslimRepository`.
func getNamesOfAllah() {
Task {
isLoading = true
do {
names = try await MuslimRepository().getNamesOfAllah(language: .en) ?? []
} catch {
self.error = error
print("Error getting names: \(error.localizedDescription)")
}
isLoading = false
}
}
}
Expand Down
22 changes: 0 additions & 22 deletions Example/MuslimDataExample/Shared/AppTabs.swift

This file was deleted.

42 changes: 0 additions & 42 deletions Example/MuslimDataExample/Shared/ErrorWithRetryView.swift

This file was deleted.

0 comments on commit 9ce71b7

Please sign in to comment.