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
2 changes: 2 additions & 0 deletions amplify/backend/api/amplifyDatasource/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ type AWSTweet @model {
id: ID!
tweetID: String!
text: String
authorName: String
authorUsername: String
category: AWSCategory @connection(name: "CategorizedTweet")
}

Expand Down
4 changes: 4 additions & 0 deletions amplify/generated/models/AWSTweet+Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ extension AWSTweet {
case id
case tweetID
case text
case authorName
case authorUsername
case category
}

Expand All @@ -23,6 +25,8 @@ extension AWSTweet {
.id(),
.field(aWSTweet.tweetID, is: .required, ofType: .string),
.field(aWSTweet.text, is: .optional, ofType: .string),
.field(aWSTweet.authorName, is: .optional, ofType: .string),
.field(aWSTweet.authorUsername, is: .optional, ofType: .string),
.belongsTo(aWSTweet.category, is: .optional, ofType: AWSCategory.self, targetName: "awsTweetCategoryId")
)
}
Expand Down
6 changes: 6 additions & 0 deletions amplify/generated/models/AWSTweet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ public struct AWSTweet: Model {
public let id: String
public var tweetID: String
public var text: String?
public var authorName: String?
public var authorUsername: String?
public var category: AWSCategory?

public init(id: String = UUID().uuidString,
tweetID: String,
text: String? = nil,
authorName: String? = nil,
authorUsername: String? = nil,
category: AWSCategory? = nil) {
self.id = id
self.tweetID = tweetID
self.text = text
self.authorName = authorName
self.authorUsername = authorUsername
self.category = category
}
}
2 changes: 1 addition & 1 deletion amplify/generated/models/AmplifyModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation
// Contains the set of classes that conforms to the `Model` protocol.

final public class AmplifyModels: AmplifyModelRegistration {
public let version: String = "2e2f9f76f94d0d76a69b2e3cdf98ddea"
public let version: String = "7d41c478cd06ada434ebdb360c6e4382"

public func registerModels(registry: ModelRegistry.Type) {
ModelRegistry.register(modelType: AWSTweet.self)
Expand Down
4 changes: 4 additions & 0 deletions brain-marks.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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 */; };
FFCB1097263E31D400544309 /* ReturnedTweet.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFCB1096263E31D300544309 /* ReturnedTweet.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 @@ -81,6 +82,7 @@
FF39431F262FCF6100A3623B /* Response.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Response.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>"; };
FFCB1096263E31D300544309 /* ReturnedTweet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReturnedTweet.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 @@ -156,6 +158,7 @@
FF39431F262FCF6100A3623B /* Response.swift */,
91C8958826228D1500689196 /* Tweet.swift */,
FF394315262FCF3900A3623B /* User.swift */,
FFCB1096263E31D300544309 /* ReturnedTweet.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -451,6 +454,7 @@
91C8958926228D1500689196 /* Tweet.swift in Sources */,
FFEBBB3C26223F75000F475F /* ContentView.swift in Sources */,
A224A9E62622BCED00AC12AF /* TweetCard.swift in Sources */,
FFCB1097263E31D400544309 /* ReturnedTweet.swift in Sources */,
FF36B6712623678D007A6D7F /* AWSTweet+Extension.swift in Sources */,
FFEBBB7626226A39000F475F /* Secrets.swift in Sources */,
A2F449912622829D00725FEA /* CategoryList.swift in Sources */,
Expand Down
9 changes: 7 additions & 2 deletions brain-marks/Add/AddURLView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct AddURLView: View {
}

extension AddURLView {
func get(url:String, completion: @escaping (Result<Tweet, Error>) -> Void) {
func get(url:String, completion: @escaping (Result<ReturnedTweet, Error>) -> Void) {

let id = url.components(separatedBy: "/").last!.components(separatedBy: "?")[0]
var request = URLRequest(url: URL(string: "https://api.twitter.com/2/tweets/\(id)?expansions=author_id")!,
Expand All @@ -89,7 +89,12 @@ extension AddURLView {
if error == nil {
let result = try JSONDecoder().decode(Response.self, from: data)

completion(.success(result.data))
let authorName = result.includes.users.first?.name ?? ""
let authorUsername = result.includes.users.first?.username ?? ""

let tweetToSave = ReturnedTweet(id: result.data.id, text: result.data.text, authorName: authorName , authorUsername: authorUsername)

completion(.success(tweetToSave))
}

DispatchQueue.main.async {
Expand Down
4 changes: 3 additions & 1 deletion brain-marks/Managers/DataStoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ class DataStoreManger {

// MARK: - Tweets

func createTweet(tweet: Tweet, category: AWSCategory) {
func createTweet(tweet: ReturnedTweet, category: AWSCategory) {
let awsTweet = AWSTweet(id: UUID().uuidString,
tweetID: tweet.id,
text: tweet.text,
authorName: tweet.authorName,
authorUsername: tweet.authorUsername,
category: category)

Amplify.DataStore.save(awsTweet) { result in
Expand Down
15 changes: 15 additions & 0 deletions brain-marks/Models/ReturnedTweet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ReturnedTweet.swift
// brain-marks
//
// Created by Mikaela Caron on 5/1/21.
//

import Foundation

struct ReturnedTweet: Codable {
let id:String
let text:String
let authorName: String
let authorUsername: String
}
1 change: 0 additions & 1 deletion brain-marks/Models/Tweet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ import Foundation
struct Tweet: Codable {
let id:String
let text:String

}
15 changes: 11 additions & 4 deletions brain-marks/Tweets/Views/TweetCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ struct TweetCard: View {

var body: some View {
VStack(alignment: .leading) {
TweetHeaderView()
TweetHeaderView(tweet: tweet)
TweetBodyView(tweetBody: tweet.text!)
// TweetFooterView()
}
}
}

struct TweetHeaderView: View {

let tweet: AWSTweet

var body: some View {
HStack {
UserIconView(size: 55)
UserInfoView()
UserInfoView(authorName: tweet.authorName ?? "",
authorUsername: tweet.authorUsername ?? "")
Spacer()
}
.padding(EdgeInsets(top: 18, leading: 18, bottom: 18, trailing: 18))
Expand Down Expand Up @@ -72,17 +76,20 @@ struct UserIconView: View {

struct UserInfoView: View {

let authorName: String
let authorUsername: String

var body: some View {
HStack(alignment: .firstTextBaseline) {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 4) {
Text("Elon Musk")
Text(authorName)
.font(.system(size: 16, weight: .semibold, design: .default))
// Image("verified")
// .resizable()
// .frame(width: 14, height: 14, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
}
Text("@elonmusk")
Text("@\(authorUsername)")
.font(.callout)
.foregroundColor(.secondary)
}
Expand Down