Skip to content

Commit

Permalink
feat: create new components to delegate tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-ctx committed Nov 21, 2023
1 parent 62be740 commit 13a09f4
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 54 deletions.
12 changes: 12 additions & 0 deletions SwiftyCompanion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
B75C3DEC2B092F1C0096416A /* UserImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B75C3DEB2B092F1C0096416A /* UserImage.swift */; };
B75C3DEE2B092FB80096416A /* SecondaryInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B75C3DED2B092FB80096416A /* SecondaryInformation.swift */; };
B75C3DF02B0960230096416A /* DetailsViewSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = B75C3DEF2B0960230096416A /* DetailsViewSelector.swift */; };
B760562B2B0CC10400903D80 /* LargeTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B760562A2B0CC10400903D80 /* LargeTitle.swift */; };
B760562D2B0CC5FF00903D80 /* MediumTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B760562C2B0CC5FF00903D80 /* MediumTitle.swift */; };
B760562F2B0CC62200903D80 /* SmallTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B760562E2B0CC62200903D80 /* SmallTitle.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -82,6 +85,9 @@
B75C3DEB2B092F1C0096416A /* UserImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserImage.swift; sourceTree = "<group>"; };
B75C3DED2B092FB80096416A /* SecondaryInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryInformation.swift; sourceTree = "<group>"; };
B75C3DEF2B0960230096416A /* DetailsViewSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailsViewSelector.swift; sourceTree = "<group>"; };
B760562A2B0CC10400903D80 /* LargeTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeTitle.swift; sourceTree = "<group>"; };
B760562C2B0CC5FF00903D80 /* MediumTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediumTitle.swift; sourceTree = "<group>"; };
B760562E2B0CC62200903D80 /* SmallTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallTitle.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -212,6 +218,9 @@
B758D17E2B0A64B60004209C /* SingleProject.swift */,
B758D1802B0ABB640004209C /* SingleAchievement.swift */,
B756B3EC2B0B4DBD00C4586A /* SingleSkill.swift */,
B760562A2B0CC10400903D80 /* LargeTitle.swift */,
B760562C2B0CC5FF00903D80 /* MediumTitle.swift */,
B760562E2B0CC62200903D80 /* SmallTitle.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -352,6 +361,7 @@
B73DA1202AFE65A70013B6E7 /* UserDetailsView.swift in Sources */,
B73DA0F52AFCEA0A0013B6E7 /* ContentView.swift in Sources */,
B73DA11E2AFE659A0013B6E7 /* SearchView.swift in Sources */,
B760562F2B0CC62200903D80 /* SmallTitle.swift in Sources */,
B75C3DEA2B092E870096416A /* MainInformation.swift in Sources */,
B75C3DF02B0960230096416A /* DetailsViewSelector.swift in Sources */,
B74CDD4B2B08B6BB00772FAE /* LabeledInfo.swift in Sources */,
Expand All @@ -362,7 +372,9 @@
B73DA0F32AFCEA0A0013B6E7 /* SwiftyCompanionApp.swift in Sources */,
B75C3DEC2B092F1C0096416A /* UserImage.swift in Sources */,
B70AFA932B022D2A00DED102 /* NetworkContext.swift in Sources */,
B760562D2B0CC5FF00903D80 /* MediumTitle.swift in Sources */,
B75C3DE82B092B930096416A /* Location.swift in Sources */,
B760562B2B0CC10400903D80 /* LargeTitle.swift in Sources */,
B758D17F2B0A64B60004209C /* SingleProject.swift in Sources */,
B73DA1252AFE927C0013B6E7 /* TextInput.swift in Sources */,
B758D17D2B0A1E8A0004209C /* DetailsViewSelectorButton.swift in Sources */,
Expand Down
3 changes: 1 addition & 2 deletions SwiftyCompanion/Components/DetailsViewSelectorButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ struct DetailsViewSelectorButton: View {
Button(action: {
currentView = buttonViewType
}) {
Text(text)
.font(.system(size: 18, weight: .semibold, design: .default))
SmallTitle(isUppercase: false, color: .white, text: text)
.padding(.vertical, 5)
.padding(.horizontal, 10)
}
Expand Down
12 changes: 4 additions & 8 deletions SwiftyCompanion/Components/LabeledInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ import Foundation
import SwiftUI

struct LabeledInfo: View {
let label: String?
let text: String?
let label: String
let text: String

var body: some View {
VStack(spacing: 3) {
Text(label ?? "Unknown")
SmallTitle(isUppercase: false, color: .accentColor, text: label)
.frame(maxWidth: .infinity)
.font(.system(size: 16, weight: .bold, design: .default))
.foregroundColor(.accentColor)
.padding(.horizontal, 15)
.padding(.top, 10)
Text(text ?? "Unknown")
SmallTitle(isUppercase: false, color: .white, text: text)
.frame(maxWidth: .infinity)
.font(.system(size: 16, weight: .semibold, design: .default))
.foregroundColor(.white)
.padding(.horizontal, 15)
.padding(.bottom, 10)
}
Expand Down
7 changes: 3 additions & 4 deletions SwiftyCompanion/Components/LargeButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ struct LargeButton: View {
action()
} label: {
HStack {
Text(title)
.textCase(.uppercase)
.font(.system(size: 22, weight: .semibold, design: .default))
LargeTitle(isUppercase: true, color: .white, text: "Search")
.frame(maxWidth: .infinity)

Image(systemName: iconName)
.font(.system(size: 22, weight: .semibold))
.font(.system(size: 26, weight: .semibold))
}
.padding()
.foregroundStyle(.white)
Expand Down
21 changes: 21 additions & 0 deletions SwiftyCompanion/Components/LargeTitle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Title.swift
// SwiftyCompanion
//
// Created by Julien Caucheteux on 21/11/2023.
//

import Foundation
import SwiftUI

struct LargeTitle: View {
let isUppercase: Bool
let color: Color
let text: String

var body: some View {
Text(isUppercase == true ? text.uppercased() : text)
.font(.system(size: 26, weight: .bold, design: .default))
.foregroundColor(color)
}
}
5 changes: 1 addition & 4 deletions SwiftyCompanion/Components/LevelBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ struct LevelBar: View {
Rectangle()
.frame(width: min(percentage * geometry.size.width, geometry.size.width), height: geometry.size.height)
.foregroundColor(.accentColor)
Text("Level \(String(format: "%.2f", level))")
.foregroundColor(.white)
SmallTitle(isUppercase: false, color: .white, text: "Level \(String(format: "%.2f", level))")
.frame(width: geometry.size.width, height: geometry.size.height)
.fontWeight(.bold)
}
.cornerRadius(10)
}
.frame(height: 26)
.padding(.horizontal)
.padding(.bottom, 7)
}
}
8 changes: 2 additions & 6 deletions SwiftyCompanion/Components/Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ struct Location: View {

var body: some View {
VStack(spacing: 0) {
Text("\(location != nil ? "Available" : "Unavailable")")
LargeTitle(isUppercase: false, color: .white, text: "\(location != nil ? "Available" : "Unavailable")")
.frame(maxWidth: .infinity)
.font(.system(size: 26, weight: .bold, design: .default))
.foregroundColor(.white)
.padding(.horizontal, 15)
.padding(.top, 20)
Text("\(location ?? "-")")
MediumTitle(isUppercase: false, color: .white, text: "\(location ?? "-")")
.frame(maxWidth: .infinity)
.font(.system(size: 22, weight: .bold, design: .default))
.foregroundColor(.white)
.padding(.horizontal, 15)
.padding(.bottom, 20)
}
Expand Down
10 changes: 3 additions & 7 deletions SwiftyCompanion/Components/MainInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ struct MainInformation: View {
let firstName: String
let lastName: String
let login: String

var body: some View {
Text("\(firstName) \(lastName)")
.font(.system(size: 24, weight: .bold, design: .default))
.foregroundColor(.white)
Text(login)
.font(.system(size: 18, weight: .semibold, design: .default))
.foregroundColor(.white)
LargeTitle(isUppercase: false, color: .white, text: "\(firstName) \(lastName)")
MediumTitle(isUppercase: false, color: .white, text: login)
}
}
21 changes: 21 additions & 0 deletions SwiftyCompanion/Components/MediumTitle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// MediumTitle.swift
// SwiftyCompanion
//
// Created by Julien Caucheteux on 21/11/2023.
//

import Foundation
import SwiftUI

struct MediumTitle: View {
let isUppercase: Bool
let color: Color
let text: String

var body: some View {
Text(isUppercase == true ? text.uppercased() : text)
.font(.system(size: 22, weight: .semibold, design: .default))
.foregroundColor(color)
}
}
1 change: 0 additions & 1 deletion SwiftyCompanion/Components/SecondaryInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import SwiftUI

struct SecondaryInformation: View {

let user: User

var body: some View {
Expand Down
4 changes: 1 addition & 3 deletions SwiftyCompanion/Components/SingleAchievement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ struct SingleAchievement: View {

var body: some View {
HStack {
Text(text)
.font(.system(size: 18, weight: .bold, design: .default))
.foregroundColor(.white)
SmallTitle(isUppercase: false, color: .white, text: text)
.lineLimit(1)
.truncationMode(.tail)
.padding(.trailing)
Expand Down
8 changes: 2 additions & 6 deletions SwiftyCompanion/Components/SingleProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ struct SingleProject: View {

var body: some View {
HStack() {
Text("\(project.project.name)")
.font(.system(size: 18, weight: .bold, design: .default))
.foregroundColor(project.validated == true ? .green : .red)
SmallTitle(isUppercase: false, color: project.validated == true ? .green : .red, text: "\(project.project.name)")
.lineLimit(1)
.truncationMode(.tail)
.padding(.trailing)
Spacer()
Image(systemName: project.validated == true ? "checkmark" : "xmark")
.foregroundColor(project.validated == true ? .green : .red)
if let finalMark = project.finalMark {
Text("\(finalMark)")
.font(.system(size: 18, weight: .bold, design: .default))
.foregroundColor(project.validated == true ? .green : .red)
SmallTitle(isUppercase: false, color: project.validated == true ? .green : .red, text: "\(finalMark)")
.lineLimit(1)
.truncationMode(.tail)
}
Expand Down
8 changes: 2 additions & 6 deletions SwiftyCompanion/Components/SingleSkill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ struct SingleSkill: View {

var body: some View {
HStack {
Text(skill.name)
.font(.system(size: 18, weight: .bold, design: .default))
.foregroundColor(.white)
SmallTitle(isUppercase: false, color: .white, text: skill.name)
.lineLimit(1)
.truncationMode(.tail)
.padding(.trailing)
Spacer()
Text("\(String(format: "%.2f", skill.level))")
.font(.system(size: 18, weight: .bold, design: .default))
.foregroundColor(.accentColor)
SmallTitle(isUppercase: false, color: .accentColor, text: "\(String(format: "%.2f", skill.level))")
}
}
}
21 changes: 21 additions & 0 deletions SwiftyCompanion/Components/SmallTitle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// SmallTitle.swift
// SwiftyCompanion
//
// Created by Julien Caucheteux on 21/11/2023.
//

import Foundation
import SwiftUI

struct SmallTitle: View {
let isUppercase: Bool
let color: Color
let text: String

var body: some View {
Text(isUppercase == true ? text.uppercased() : text)
.font(.system(size: 18, weight: .semibold, design: .default))
.foregroundColor(color)
}
}
1 change: 1 addition & 0 deletions SwiftyCompanion/Components/UserImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI

struct UserImage: View {
let userImage: String

var body: some View {
AsyncImage(url: URL(string: userImage)) { image in
image
Expand Down
2 changes: 1 addition & 1 deletion SwiftyCompanion/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct ContentView: View {
var body: some View {
SearchView()
SearchView()
}
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftyCompanion/Network/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct ProjectsUser: Codable {
let validated: Bool?
let project: Project
let cursusIds: [Int]

enum CodingKeys: String, CodingKey {
case finalMark = "final_mark"
case status
Expand Down
2 changes: 1 addition & 1 deletion SwiftyCompanion/Views/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct SearchView: View {
}
}
.alert(isPresented: $showAlert) {
Alert(title: Text("An error occurred"), message: Text("You need to enter a login to display the user information"), dismissButton: .default(Text("OK")))
Alert(title: Text("An error occurred").font(.system(size: 26, weight: .bold, design: .default)), message: Text("You need to enter a login to display the user information").font(.system(size: 18, weight: .semibold, design: .default)), dismissButton: .default(Text("OK").font(.system(size: 18, weight: .semibold, design: .default))))
}
}
.padding(.horizontal)
Expand Down
7 changes: 3 additions & 4 deletions SwiftyCompanion/Views/UserDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ struct UserDetailsView: View {
Group {
if let errorMessage = errorMessage {
VStack {
Text("Error".uppercased())
.font(.system(size: 28, weight: .bold, design: .default))
Text(errorMessage)
LargeTitle(isUppercase: true, color: .black, text: "ERROR")
SmallTitle(isUppercase: false, color: .black, text: errorMessage)
}
} else if isLoading {
ProgressView()
Expand Down Expand Up @@ -116,7 +115,7 @@ struct UserDetailsView: View {
} catch {
errorMessage = "Something went wrong."
}

}

private func hasMatchingProjects() -> Bool {
Expand Down

0 comments on commit 13a09f4

Please sign in to comment.