-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
253 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Example/MuslimDataExample/Azkars/AzkarChapters/AzkarChaptersScreen.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// AzkarsScreen.swift | ||
// Example | ||
// | ||
// Created by Kosrat Ahmed on 25/03/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Display the azkar chapter list. | ||
struct AzkarChaptersScreen: View { | ||
private var azkarViewModel = ChapterViewModel() | ||
|
||
var body: some View { | ||
NavigationSplitView { | ||
List { | ||
ForEach(azkarViewModel.azkarChapters, id: \.id) { chapter in | ||
NavigationLink { | ||
AzkarItemsScreen(chapterId: chapter.id) | ||
} label: { | ||
ChapterRow(azkarChapter: chapter) | ||
.frame(height: 36) | ||
} | ||
} | ||
} | ||
.navigationTitle("Azkars") | ||
} detail: { | ||
Text("Select an Azkar") | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
AzkarChaptersScreen() | ||
} |
28 changes: 28 additions & 0 deletions
28
Example/MuslimDataExample/Azkars/AzkarChapters/ChapterRow.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// AzkarRow.swift | ||
// Example | ||
// | ||
// Created by Kosrat Ahmed on 25/03/2024. | ||
// | ||
|
||
import SwiftUI | ||
import MuslimData | ||
|
||
/// Displays a single row that is representing an azkar chapter. | ||
/// | ||
/// - Parameters: | ||
/// - azkarChapter: the `AzkarChapter` instance that needs to be displayed in the row. | ||
struct ChapterRow: View { | ||
var azkarChapter: AzkarChapter | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
Text(azkarChapter.name) | ||
.font(.body) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ChapterRow(azkarChapter: AzkarChapter(id: 1, categoryId: 1, name: "Morning Azkars")) | ||
} |
30 changes: 30 additions & 0 deletions
30
Example/MuslimDataExample/Azkars/AzkarChapters/ChapterViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// AzkarViewModel.swift | ||
// Example | ||
// | ||
// Created by Kosrat Ahmed on 25/03/2024. | ||
// | ||
|
||
import Foundation | ||
import MuslimData | ||
|
||
@Observable | ||
/// Manages the state for the azkar chapters list and responsible for fetching data. | ||
class ChapterViewModel { | ||
private(set) var azkarChapters: [AzkarChapter] = [] | ||
|
||
init() { | ||
getAzkarChapters() | ||
} | ||
|
||
/// Fetches the azkar chapters from the `MuslimRepository`. | ||
private func getAzkarChapters() { | ||
Task { | ||
do { | ||
azkarChapters = try await MuslimRepository().getAzkarChapters(language: .en) ?? [] | ||
} catch { | ||
print("Error loading azkars: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Example/MuslimDataExample/Azkars/AzkarItems/AzkarItemsScreen.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// AzkarDetailScreen.swift | ||
// Example | ||
// | ||
// Created by Kosrat Ahmed on 25/03/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Display the detail of the selected azkar chapter. | ||
struct AzkarItemsScreen: View { | ||
var chapterId: Int | ||
var itemsViewModel: ItemViewModel | ||
|
||
init(chapterId: Int) { | ||
self.chapterId = chapterId | ||
itemsViewModel = ItemViewModel(chapterId: chapterId) | ||
} | ||
|
||
var body: some View { | ||
List { | ||
ForEach(itemsViewModel.azkarItems, id: \.id) { item in | ||
ItemRow(azkarItem: item) | ||
} | ||
} | ||
.listRowSpacing(8) | ||
.navigationTitle("Azkar Details") | ||
} | ||
} | ||
|
||
#Preview { | ||
AzkarItemsScreen(chapterId: 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// ItemRow.swift | ||
// Example | ||
// | ||
// Created by Kosrat Ahmed on 25/03/2024. | ||
// | ||
|
||
import SwiftUI | ||
import MuslimData | ||
|
||
/// Displays a single row that is representing an Azkar Item. Includes the Arabic azkar, its tranlation, | ||
/// and the azkar reference. | ||
/// | ||
/// - Parameters: | ||
/// - azkarItem: the `AzkarItem` instance that needs to be displayed in the row. | ||
struct ItemRow: View { | ||
var azkarItem: AzkarItem | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
Text(azkarItem.item) | ||
.font(.headline) | ||
.padding(.bottom, 4) | ||
Text(azkarItem.translation) | ||
.font(.body) | ||
.padding(.bottom, 8) | ||
Text(azkarItem.reference) | ||
.font(.caption) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ItemRow(azkarItem: AzkarItem( | ||
id: 1, | ||
chapterId: 1, | ||
item: "Azkar detail in Arabic language", | ||
translation: "translated azkar into user's language", | ||
reference: "Azkar references") | ||
) | ||
} |
32 changes: 32 additions & 0 deletions
32
Example/MuslimDataExample/Azkars/AzkarItems/ItemViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// ItemViewModel.swift | ||
// Example | ||
// | ||
// Created by Kosrat Ahmed on 25/03/2024. | ||
// | ||
|
||
import Foundation | ||
import MuslimData | ||
|
||
@Observable | ||
/// Manages the state for the azkar item list and responsible for fetching data. | ||
class ItemViewModel { | ||
private(set) var azkarItems: [AzkarItem] = [] | ||
let chapterId: Int | ||
|
||
init(chapterId: Int) { | ||
self.chapterId = chapterId | ||
getAzkarItems() | ||
} | ||
|
||
/// Fetches the azkar items from the `MuslimRepository`. | ||
private func getAzkarItems() { | ||
Task { | ||
do { | ||
azkarItems = try await MuslimRepository().getAzkarItems(chapterId: chapterId, language: .en) ?? [] | ||
} catch { | ||
print("Error getting azkar items: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters