Skip to content
This repository was archived by the owner on Aug 18, 2023. It is now read-only.
Merged
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
8 changes: 8 additions & 0 deletions brain-marks.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
C4392E80BFE640DAA2625F9D /* AWSTweet+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC43813A9098469FB57F5871 /* AWSTweet+Schema.swift */; };
CA80832580B84CB3A2D5F629 /* AmplifyModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F5BDE61EAA4A2DB9030734 /* AmplifyModels.swift */; };
CF16AFB9BE3F401E98C85114 /* AWSTweet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA54EDF3B34443CA9D530E5 /* AWSTweet.swift */; };
FF36B661262357F9007A6D7F /* AWSCategory+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF36B660262357F9007A6D7F /* AWSCategory+Extension.swift */; };
FF59902B2622C1CE004DF328 /* Amplify in Frameworks */ = {isa = PBXBuildFile; productRef = FF59902A2622C1CE004DF328 /* Amplify */; };
FF59902D2622C1CE004DF328 /* AWSAPIPlugin in Frameworks */ = {isa = PBXBuildFile; productRef = FF59902C2622C1CE004DF328 /* AWSAPIPlugin */; };
FF59902F2622C1CE004DF328 /* AWSDataStorePlugin in Frameworks */ = {isa = PBXBuildFile; productRef = FF59902E2622C1CE004DF328 /* AWSDataStorePlugin */; };
FF5990692622DD61004DF328 /* DataStoreManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5990682622DD61004DF328 /* DataStoreManager.swift */; };
FF6DCBF22623530400EC366F /* CategoryListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF6DCBF12623530400EC366F /* CategoryListViewModel.swift */; };
FFEBBB3A26223F75000F475F /* brain_marksApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEBBB3926223F75000F475F /* brain_marksApp.swift */; };
FFEBBB3C26223F75000F475F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEBBB3B26223F75000F475F /* ContentView.swift */; };
FFEBBB3E26223F7E000F475F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FFEBBB3D26223F7E000F475F /* Assets.xcassets */; };
Expand Down Expand Up @@ -68,7 +70,9 @@
CC43813A9098469FB57F5871 /* AWSTweet+Schema.swift */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 4; includeInIndex = 0; lastKnownFileType = sourcecode.swift; name = "AWSTweet+Schema.swift"; path = "amplify/generated/models/AWSTweet+Schema.swift"; sourceTree = "<group>"; };
DA7D79B731BC4ECFAAE8E817 /* awsconfiguration.json */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; path = awsconfiguration.json; sourceTree = "<group>"; };
ECA1CF04DB754255822691F2 /* amplifyconfiguration.json */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; path = amplifyconfiguration.json; sourceTree = "<group>"; };
FF36B660262357F9007A6D7F /* AWSCategory+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AWSCategory+Extension.swift"; sourceTree = "<group>"; };
FF5990682622DD61004DF328 /* DataStoreManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStoreManager.swift; sourceTree = "<group>"; };
FF6DCBF12623530400EC366F /* CategoryListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryListViewModel.swift; sourceTree = "<group>"; };
FFEBBB3626223F75000F475F /* brain-marks.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "brain-marks.app"; sourceTree = BUILT_PRODUCTS_DIR; };
FFEBBB3926223F75000F475F /* brain_marksApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = brain_marksApp.swift; sourceTree = "<group>"; };
FFEBBB3B26223F75000F475F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -184,6 +188,8 @@
FFEBBB7526226A39000F475F /* Secrets.swift */,
91739DEA2622D2A7000F982A /* AddURLView.swift */,
FF5990682622DD61004DF328 /* DataStoreManager.swift */,
FF6DCBF12623530400EC366F /* CategoryListViewModel.swift */,
FF36B660262357F9007A6D7F /* AWSCategory+Extension.swift */,
);
path = "brain-marks";
sourceTree = "<group>";
Expand Down Expand Up @@ -387,8 +393,10 @@
C0DAFC52B24C456EAE5AEF21 /* AWSCategory.swift in Sources */,
684E2F2D3FCC4D36AC68E57D /* AWSCategory+Schema.swift in Sources */,
CF16AFB9BE3F401E98C85114 /* AWSTweet.swift in Sources */,
FF36B661262357F9007A6D7F /* AWSCategory+Extension.swift in Sources */,
C4392E80BFE640DAA2625F9D /* AWSTweet+Schema.swift in Sources */,
A205CD422622A3EB00517DB5 /* TweetList.swift in Sources */,
FF6DCBF22623530400EC366F /* CategoryListViewModel.swift in Sources */,
91739DEB2622D2A7000F982A /* AddURLView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
10 changes: 10 additions & 0 deletions brain-marks/AWSCategory+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// AWSCategory+Extension.swift
// brain-marks
//
// Created by Mikaela Caron on 4/11/21.
//

import Foundation

extension AWSCategory: Identifiable {}
28 changes: 12 additions & 16 deletions brain-marks/CategoryList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
import SwiftUI

struct CategoryList: View {

var categories: [Category]

@StateObject var viewModel = CategoryListViewModel()

@State private var showingSheet = false

var body: some View {
NavigationView {
List(categories) { category in
NavigationLink(destination: TweetList(category: category)) {
List(viewModel.categories) { category in
NavigationLink(destination: TweetList(category: category)) {
CategoryRow(category: category)
}

}.listStyle(InsetGroupedListStyle())
.environment(\.horizontalSizeClass, .regular)
.navigationTitle("Categories")
Expand All @@ -39,6 +40,9 @@ struct CategoryList: View {
}
}
}
.onAppear {
viewModel.getCategories()
}
}
}

Expand Down Expand Up @@ -68,6 +72,7 @@ struct NewCategorySheetView: View {

Button {
presentationMode.wrappedValue.dismiss()
DataStoreManger.shared.createCategory(category: AWSCategory(name: newCategory, imageName: "swift"))
} label: {
Text("Create")
.frame(width: 150, height: 50)
Expand All @@ -86,16 +91,7 @@ struct NewCategorySheetView: View {

struct CategoryList_Previews: PreviewProvider {
static var previews: some View {
CategoryList(categories: [
Category(id: 0,
name: "SwiftUI",
numberOfTweets: 3,
imageName: "swift"),
Category(id: 1,
name: "BigBrainHacks",
numberOfTweets: 5,
imageName: "laptopcomputer")
])
CategoryList()

NewCategorySheetView()
}
Expand Down
27 changes: 27 additions & 0 deletions brain-marks/CategoryListViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// CategoryListViewModel.swift
// brain-marks
//
// Created by Mikaela Caron on 4/11/21.
//

import SwiftUI

final class CategoryListViewModel: ObservableObject {

@Published var categories = [AWSCategory]()

func getCategories() {
DataStoreManger.shared.fetchCategories { result in
switch result {
case .success(let categories):
DispatchQueue.main.async {
self.categories = categories
}
case .failure(let error):
print("Error fetching categories: \(error)")
}
}
}

}
34 changes: 17 additions & 17 deletions brain-marks/CategoryRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import SwiftUI

struct CategoryRow: View {
var category: Category
var category: AWSCategory

var body: some View {
HStack {
Image(systemName: category.imageName)
Image(systemName: category.imageName ?? "swift")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 40, height: 40)
Expand All @@ -22,18 +22,18 @@ struct CategoryRow: View {
}
}

struct CategoryRow_Previews: PreviewProvider {
static var previews: some View {
Group {
CategoryRow(category: Category(id: 0,
name: "SwiftUI",
numberOfTweets: 3,
imageName: "swift"))
CategoryRow(category: Category(id: 1,
name: "BigBrainHacks",
numberOfTweets: 5,
imageName: "laptopcomputer"))
}
.previewLayout(.fixed(width: 300, height: 70))
}
}
//struct CategoryRow_Previews: PreviewProvider {
// static var previews: some View {
// Group {
// CategoryRow(category: Category(id: 0,
// name: "SwiftUI",
// numberOfTweets: 3,
// imageName: "swift"))
// CategoryRow(category: Category(id: 1,
// name: "BigBrainHacks",
// numberOfTweets: 5,
// imageName: "laptopcomputer"))
// }
// .previewLayout(.fixed(width: 300, height: 70))
// }
//}
5 changes: 1 addition & 4 deletions brain-marks/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ struct ContentView: View {

var body: some View {
VStack {
CategoryList(categories: [
Category(id: 0, name: "SwiftUI", numberOfTweets: 3, imageName: "swift"),
Category(id: 1, name: "BigBrainHacks", numberOfTweets: 5, imageName: "laptopcomputer")
])
CategoryList()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions brain-marks/TweetList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct TweetList: View {
var category: Category
var category: AWSCategory

var body: some View {

Expand All @@ -17,7 +17,7 @@ struct TweetList: View {
} .toolbar {
ToolbarItem(placement: .principal) {
HStack {
Image(systemName: category.imageName)
Image(systemName: category.imageName ?? "swift")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 25, height: 25)
Expand Down