<repo_name>Shun-Takashige/Team02_prototype<file_sep>/SwiftUI_team02/Views/Categories/CategoryRow.swift
//
//  CategoryRow.swift
//  SwiftUI_team02
//
//  Created by 高重駿 on 2021/01/13.
//

import SwiftUI

struct CategoryRow: View {
    var categoryName: String
    var items: [House]

    var body: some View {
        VStack(alignment: .leading) {
            Text(categoryName)
                .font(.headline)
                .padding(.leading, 15)
                .padding(.top, 5)

            ScrollView(.horizontal, showsIndicators: false) {
                HStack(alignment: .top, spacing: 0) {
                    ForEach(items) { house in
                        NavigationLink(destination: HouseDetail(house: house)) {
                            CategoryItem(house: house)
                        }
                        
                    }
                }
            }
        .frame(height: 185)
        }
    }
}

struct CategoryRow_Previews: PreviewProvider {
    static var houses = ModelDate().houses
    
    
    static var previews: some View {
        CategoryRow(
            categoryName: houses[0].category.rawValue,
            items: Array(houses.prefix(3))
        )
    }
}
<file_sep>/SwiftUI_team02/Views/Houses/HouseList.swift
//
//  HouseList.swift
//  SwiftUI_team02
//
//  Created by 高重駿 on 2021/01/10.
//

import SwiftUI

struct HouseList: View {
    @EnvironmentObject var modelData: ModelDate
    @State private var showFavoritesOnly = false
    
    var filteredHouses:[House]{
        modelData.houses.filter{ house in
            (!showFavoritesOnly || house.isFavorite)
        }
    }
    
    var body: some View {
        NavigationView{
            List{
                Toggle(isOn: $showFavoritesOnly){
                    Text("Favorites only")
                }
                
                ForEach(filteredHouses){ house in
                    NavigationLink(destination: HouseDetail(house: house)){
                        HouseRow(house: house)
                        
                    }
                }
            }
            .navigationTitle("Houses")
        }
        
        
    }
}

struct HouseList_Previews: PreviewProvider {
    static var previews: some View {
        HouseList()
            .environmentObject(ModelDate())
    }
}
<file_sep>/SwiftUI_team02/Views/Houses/HouseRow.swift
//
//  HouseRow.swift
//  SwiftUI_team02
//
//  Created by 高重駿 on 2021/01/10.
//

import SwiftUI

struct HouseRow: View {
    var house : House
    
    var body: some View {
        HStack{
            house.image
                .resizable()
                .frame(width: 50, height: 50)
            Text(house.name)
            
            Spacer()
            
            if house.isFavorite {
                Image(systemName: "star.fill")
                    .imageScale(.medium)
                    .foregroundColor(.yellow)
            }
        }
    }
}

struct HouseRow_Previews: PreviewProvider {
    static var houses = ModelDate().houses
    
    static var previews: some View {
        Group{
            HouseRow(house: houses[0])
            HouseRow(house: houses[1])
        }
        .previewLayout(.fixed(width: 300, height: 70))

    }
}
<file_sep>/SwiftUI_team02/Views/Houses/HouseDetail.swift
//
//  HouseDetail.swift
//  SwiftUI_team02
//
//  Created by 高重駿 on 2021/01/10.
//

import SwiftUI
import MapKit

struct HouseDetail: View {
    @EnvironmentObject var modelData: ModelDate
    var house: House
    
    var houseIndex: Int{
        modelData.houses.firstIndex(where: {$0.id == house.id})!
    }
    
    var body: some View {
        ScrollView{
              MapView(coordinate: house.locationCoordinate)
                .ignoresSafeArea(edges: .top)
                .frame(height: 300)
            
            CircleImage(image: house.image)
                .offset(y : -130)
                .padding(.bottom, -130)
            
            VStack(alignment:.leading) {
                HStack{
                    Text(house.name)
                        .font(.title)
                        .foregroundColor(.primary)
                    FavoriteButton(isSet: $modelData.houses[houseIndex].isFavorite)
                }
                
                HStack {
                    //Text(house.type)
                    //Spacer()
                    Text(house.prefecture)
                      
                }
                .font(.subheadline)
                .foregroundColor(.secondary)

                Divider()
                
                Text("About \(house.name)")
                    .font(.title2)
                Text(house.description)
                
            }
            .padding()
        }
        .navigationTitle(house.name)
        .navigationBarTitleDisplayMode(.inline)
    }
}

struct HouseDetail_Previews: PreviewProvider {
    static let modelData = ModelDate()
    
    static var previews: some View {
        HouseDetail(house: modelData.houses[0])
            .environmentObject(modelData)
    }
}
<file_sep>/SwiftUI_team02/Model/House.swift
//
//  House.swift
//  SwiftUI_team02
//
//  Created by 高重駿 on 2021/01/10.
//

import Foundation
import SwiftUI
import CoreLocation

struct House: Hashable, Codable, Identifiable{
    var id: Int
    var name: String
    //var type: String
    var prefecture: String
    var description: String
    var isFavorite: Bool
    var isFeatured: Bool
    
    var category: Category
        enum Category: String, CaseIterable, Codable {
            case shibuya = "Shibuya"
            case shinjuku = "Shinjuku"
            case setagaya = "Setagaya"
        }
    
    
    
    private var imageName: String
        var image: Image {
            Image(imageName)
            
        }
    
    private var coordinates: Coordinates
    var locationCoordinate: CLLocationCoordinate2D {
            CLLocationCoordinate2D(
                latitude: coordinates.latitude,
                longitude: coordinates.longitude)
        }

        struct Coordinates: Hashable, Codable {
            var latitude: Double
            var longitude: Double
        }
}

