Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions ShopHub/ShopHub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
4271EC902A88729C00E2C85B /* SalesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4271EC8F2A88729C00E2C85B /* SalesView.swift */; };
4271EC922A88753900E2C85B /* ProductView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4271EC912A88753900E2C85B /* ProductView.swift */; };
428D1B9D2ABDF28300F65A65 /* LaunchScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 428D1B9C2ABDF28300F65A65 /* LaunchScreenView.swift */; };
428D1B9F2ABE53F900F65A65 /* LaunchScreenPhase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 428D1B9E2ABE53F900F65A65 /* LaunchScreenPhase.swift */; };
42994BF12A9D4B39007248F0 /* MockCartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42994BF02A9D4B39007248F0 /* MockCartView.swift */; };
428D1B9F2ABE53F900F65A65 /* LaunchScreenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 428D1B9E2ABE53F900F65A65 /* LaunchScreenManager.swift */; };
42A3BCEF2AC2A4C3006E9DCA /* DayNightToggleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42A3BCEE2AC2A4C3006E9DCA /* DayNightToggleView.swift */; };
42A3BCF32AC2ADF4006E9DCA /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42A3BCF22AC2ADF4006E9DCA /* IconView.swift */; };
42A3BCF92AC350AA006E9DCA /* OrderIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42A3BCF82AC350AA006E9DCA /* OrderIconView.swift */; };
Expand Down Expand Up @@ -51,6 +50,7 @@
AEB27CAA2A8857E5009E7A80 /* ToolBarStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB27CA92A8857E5009E7A80 /* ToolBarStyle.swift */; };
AEBD622F2A99A1E10014C335 /* CartItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBD622E2A99A1E10014C335 /* CartItemView.swift */; };
AEC27B292AACDCA000B22C40 /* TextFieldQuantityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC27B282AACDCA000B22C40 /* TextFieldQuantityView.swift */; };
AECB45CC2B1C24E30012D629 /* EmptyCartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECB45CB2B1C24E30012D629 /* EmptyCartView.swift */; };
AED85CD52A8B347B00E8B347 /* BannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED85CD42A8B347B00E8B347 /* BannerView.swift */; };
AEE12AAE2AAE5199002FE29D /* AddToCartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE12AAD2AAE5199002FE29D /* AddToCartView.swift */; };
AEF37BC12A891F710003F44E /* ShopHubViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEF37BC02A891F710003F44E /* ShopHubViewModel.swift */; };
Expand Down Expand Up @@ -83,8 +83,7 @@
4271EC912A88753900E2C85B /* ProductView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductView.swift; sourceTree = "<group>"; };
428D1B9A2ABDDE4000F65A65 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
428D1B9C2ABDF28300F65A65 /* LaunchScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchScreenView.swift; sourceTree = "<group>"; };
428D1B9E2ABE53F900F65A65 /* LaunchScreenPhase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchScreenPhase.swift; sourceTree = "<group>"; };
42994BF02A9D4B39007248F0 /* MockCartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCartView.swift; sourceTree = "<group>"; };
428D1B9E2ABE53F900F65A65 /* LaunchScreenManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchScreenManager.swift; sourceTree = "<group>"; };
42A3BCEE2AC2A4C3006E9DCA /* DayNightToggleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayNightToggleView.swift; sourceTree = "<group>"; };
42A3BCF22AC2ADF4006E9DCA /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = "<group>"; };
42A3BCF82AC350AA006E9DCA /* OrderIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderIconView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -114,6 +113,7 @@
AEB27CA92A8857E5009E7A80 /* ToolBarStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolBarStyle.swift; sourceTree = "<group>"; };
AEBD622E2A99A1E10014C335 /* CartItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CartItemView.swift; sourceTree = "<group>"; };
AEC27B282AACDCA000B22C40 /* TextFieldQuantityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldQuantityView.swift; sourceTree = "<group>"; };
AECB45CB2B1C24E30012D629 /* EmptyCartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCartView.swift; sourceTree = "<group>"; };
AED85CD42A8B347B00E8B347 /* BannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerView.swift; sourceTree = "<group>"; };
AEE12AAD2AAE5199002FE29D /* AddToCartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToCartView.swift; sourceTree = "<group>"; };
AEF37BC02A891F710003F44E /* ShopHubViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShopHubViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -166,19 +166,11 @@
isa = PBXGroup;
children = (
428D1B9C2ABDF28300F65A65 /* LaunchScreenView.swift */,
428D1B9E2ABE53F900F65A65 /* LaunchScreenPhase.swift */,
428D1B9E2ABE53F900F65A65 /* LaunchScreenManager.swift */,
);
path = LaunchScreen;
sourceTree = "<group>";
};
42994BEF2A9D4AFE007248F0 /* Mock */ = {
isa = PBXGroup;
children = (
42994BF02A9D4B39007248F0 /* MockCartView.swift */,
);
path = Mock;
sourceTree = "<group>";
};
42A3BCF42AC34292006E9DCA /* UserComponent */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -242,7 +234,6 @@
children = (
428D1B9B2ABDF25800F65A65 /* LaunchScreen */,
428D1B9A2ABDDE4000F65A65 /* Info.plist */,
42994BEF2A9D4AFE007248F0 /* Mock */,
AEB27CAB2A886A02009E7A80 /* Extensions */,
4271EC822A88717E00E2C85B /* JSON Data */,
4269E81E2A944D8E00AB9475 /* ViewModels */,
Expand Down Expand Up @@ -346,6 +337,7 @@
AEAC80192A9C1DBA0074F0CC /* CartTranscationView.swift */,
42F49D652A91CF12002C3C35 /* CartListView.swift */,
AEBD622E2A99A1E10014C335 /* CartItemView.swift */,
AECB45CB2B1C24E30012D629 /* EmptyCartView.swift */,
);
path = Cart;
sourceTree = "<group>";
Expand Down Expand Up @@ -524,7 +516,6 @@
AEAC801A2A9C1DBA0074F0CC /* CartTranscationView.swift in Sources */,
4237B37D2A8AC17900C214AE /* ProductDetailView.swift in Sources */,
AE2B3B7B2A871EAE00889805 /* ContentView.swift in Sources */,
42994BF12A9D4B39007248F0 /* MockCartView.swift in Sources */,
4271EC902A88729C00E2C85B /* SalesView.swift in Sources */,
AEF37BC12A891F710003F44E /* ShopHubViewModel.swift in Sources */,
AEE12AAE2AAE5199002FE29D /* AddToCartView.swift in Sources */,
Expand All @@ -536,11 +527,12 @@
4271EC922A88753900E2C85B /* ProductView.swift in Sources */,
4260484A2AC0B26D00C54B0C /* OrderView.swift in Sources */,
AE2B3B792A871EAE00889805 /* ShopHubApp.swift in Sources */,
428D1B9F2ABE53F900F65A65 /* LaunchScreenPhase.swift in Sources */,
428D1B9F2ABE53F900F65A65 /* LaunchScreenManager.swift in Sources */,
4260484C2AC0B2B500C54B0C /* HistoryView.swift in Sources */,
AEB27CAA2A8857E5009E7A80 /* ToolBarStyle.swift in Sources */,
42A3BCFB2AC350C8006E9DCA /* WalletIconView.swift in Sources */,
42A3BCFF2AC350E6006E9DCA /* BookmarkIconView.swift in Sources */,
AECB45CC2B1C24E30012D629 /* EmptyCartView.swift in Sources */,
42A3BCFD2AC350D8006E9DCA /* HistoryIconView.swift in Sources */,
AE5FAA402AB79787004D1EFA /* NavigationCustomBackButton.swift in Sources */,
4271EC882A8871BE00E2C85B /* Bundle+Decode.swift in Sources */,
Expand Down
19 changes: 8 additions & 11 deletions ShopHub/ShopHub/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,26 @@ import SwiftUI

struct ContentView: View {

// State Object
// Environment

@StateObject var viewModel: ShopHubViewModel = ShopHubViewModel()
@StateObject var cartViewModel: CartViewModel = CartViewModel()
@Environment(LaunchScreenManager.self) private var launchScreenManager

// Environment Object
// Internal State

@EnvironmentObject var launchScreenManager: LaunchScreenManager
@State var viewModel: ShopHubViewModel = ShopHubViewModel()
@StateObject var cartViewModel: CartViewModel = CartViewModel()
@State var selectedTab: MenuTab = .products

// App Storage

@AppStorage("dark-mode") private var isDarkModeOn: Bool = false

// Internal State

@State var selectedTab: MenuTab = .products

var body: some View {
TabView(selection: $selectedTab) {
MenuTabView()
}
.onAppear(perform: dismissLaunchScreen)
.environmentObject(viewModel)
.environment(viewModel)
.environmentObject(cartViewModel)
.environment(\.selectedMenuTab, $selectedTab)
.preferredColorScheme(isDarkModeOn ? .dark : .light)
Expand All @@ -43,5 +40,5 @@ struct ContentView: View {

#Preview("Content View") {
ContentView()
.environmentObject(LaunchScreenManager())
.environment(LaunchScreenManager())
}
2 changes: 1 addition & 1 deletion ShopHub/ShopHub/JSON Data/ProductList.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
{
"id": 7,
"name": "Nintendo Switch™ with Neon Blue and Neon Red Joy‑Con™",
"name": "Nintendo Switch",
"price": 299.99,
"type": "Electronics",
"description": "Play at home or on the go with one system The Nintendo Switch™ system is designed to go wherever you do, instantly transforming from a home console you play on TV to a portable system you can play anywhere. So you get more time to play the games you love, however you like.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// LaunchScreenPhase.swift
// LaunchScreenManager.swift
// ShopHub
//
// Created by CHENGTAO on 9/22/23.
Expand All @@ -13,8 +13,12 @@ enum LaunchScreenPhase {
case completed
}

final class LaunchScreenManager: ObservableObject {
@Published private(set) var state: LaunchScreenPhase = .first
/// This `Observable` class is the view model that manages the life cycle of launch screen.
@Observable
final class LaunchScreenManager {

private(set) var state: LaunchScreenPhase = .first

func dismiss() {
self.state = .second

Expand Down
9 changes: 5 additions & 4 deletions ShopHub/ShopHub/LaunchScreen/LaunchScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import SwiftUI

/// This struct creates the initial lanuch screen view when user enters the app.
struct LaunchScreenView: View {

// Environment Object

@EnvironmentObject var launchScreenManager: LaunchScreenManager
// Environment
@Environment(LaunchScreenManager.self) private var launchScreenManager

// Internal State

Expand All @@ -21,7 +22,7 @@ struct LaunchScreenView: View {
private let timer = Timer.publish(every: 0.65, on: .main, in: .common).autoconnect()

var body: some View {
ZStack{
ZStack {
background
logo
}
Expand Down
174 changes: 0 additions & 174 deletions ShopHub/ShopHub/Mock/MockCartView.swift

This file was deleted.

Loading