created details viewmodel
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
c2768a4864
commit
9102f8d3c6
50
EmployeeDirectory/ViewModels/EmployeeDetailsViewModel.swift
Normal file
50
EmployeeDirectory/ViewModels/EmployeeDetailsViewModel.swift
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// EmployeeDetailsViewModel.swift
|
||||
// EmployeeDirectory
|
||||
//
|
||||
// Created by Matt Bruce on 2/6/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
/// ViewModel that will be used along with the EmployeeTableViewCell.
|
||||
@MainActor
|
||||
public class EmployeeDetailViewModel: ObservableObject {
|
||||
// MARK: - Properties
|
||||
|
||||
private let employee: Employee
|
||||
|
||||
public private(set) var uuid: String
|
||||
public private(set) var fullName: String
|
||||
public private(set) var phoneNumber: String?
|
||||
public private(set) var emailAddress: String
|
||||
public private(set) var biography: String?
|
||||
public private(set) var team: String
|
||||
public private(set) var employeeType: String
|
||||
@Published public private(set) var largePhoto: UIImage?
|
||||
|
||||
// MARK: - Initializer
|
||||
|
||||
public init(employee: Employee) {
|
||||
self.employee = employee
|
||||
|
||||
// Initialize properties
|
||||
uuid = employee.uuid.uuidString
|
||||
fullName = employee.fullName
|
||||
phoneNumber = employee.phoneNumber?.formatUSNumber()
|
||||
emailAddress = employee.emailAddress
|
||||
biography = employee.biography
|
||||
team = employee.team
|
||||
employeeType = employee.employeeType.description
|
||||
|
||||
// Fetch the image for the url if it exists
|
||||
if let endpoint = employee.photoURLLarge {
|
||||
Task{
|
||||
if let photoURL = URL(string: endpoint) {
|
||||
largePhoto = await ImageCacheService.shared.loadImage(from: photoURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user