diff --git a/Frameworks/Feed/Bundle/Sources/UI/Views/TopWordsView.swift b/Frameworks/Feed/Bundle/Sources/UI/Views/TopWordsView.swift new file mode 100644 index 0000000..95f9855 --- /dev/null +++ b/Frameworks/Feed/Bundle/Sources/UI/Views/TopWordsView.swift @@ -0,0 +1,82 @@ +// +// TopWordsView.swift +// ReviewsFeed +// +// Created by Javier Cicchelli on 21/03/2024. +// Copyright © 2024 Röck+Cöde. All rights reserved. +// + +import SwiftUI + +struct TopWordsView: View { + + // MARK: Constants + private let topWords: [TopWord] + + // MARK: Initialisers + init(_ topWords: [TopWord]) { + self.topWords = topWords + } + + // MARK: Body + var body: some View { + HStack { + Spacer() + + HStack(spacing: 12) { + ForEach(topWords) { topWord in + Item( + term: topWord.term, + count: String(topWord.count) + ) + } + } + + Spacer() + } + + } + +} + +// MARK: - Structs +private extension TopWordsView { + struct Item: View { + + // MARK: Constants + let term: String + let count: String + + // MARK: Body + var body: some View { + HStack( + alignment: .center, + spacing: 6 + ) { + Text(count) + .font(.footnote) + .foregroundColor(.primary.opacity(0.75)) + + Text(term) + .lineLimit(1) + .font(.body.bold()) + .foregroundColor(.primary) + } + .padding(.horizontal, 10) + .padding(.vertical, 6) + .background(Color.secondary.opacity(0.75)) + .cornerRadius(8) + } + + } +} + +// MARK: - Previews +#Preview { + TopWordsView([ + .init(id: "1", term: "Something", count: 3), + .init(id: "2", term: "Something", count: 2), + .init(id: "3", term: "Something", count: 1), + ]) + .padding(.horizontal) +} diff --git a/Reviews.xcodeproj/project.pbxproj b/Reviews.xcodeproj/project.pbxproj index d9358a5..f6bb822 100644 --- a/Reviews.xcodeproj/project.pbxproj +++ b/Reviews.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 02DC7FB52BA52520000EEEBE /* ReviewsKit in Frameworks */ = {isa = PBXBuildFile; productRef = 02DC7FB42BA52520000EEEBE /* ReviewsKit */; }; 02EACF2E2BABA34600FF8ECD /* FeedItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02EACF2D2BABA34600FF8ECD /* FeedItemCell.swift */; }; 02EACF302BABA50D00FF8ECD /* TopWordsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02EACF2F2BABA50D00FF8ECD /* TopWordsCell.swift */; }; + 02EACF322BABB23A00FF8ECD /* TopWordsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02EACF312BABB23A00FF8ECD /* TopWordsView.swift */; }; 02EACF342BABB28900FF8ECD /* TopWord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02EACF332BABB28900FF8ECD /* TopWord.swift */; }; 02EACF362BABB2F200FF8ECD /* TopWord+DTOs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02EACF352BABB2F200FF8ECD /* TopWord+DTOs.swift */; }; 345AD11C24C6EDD9004E2EE1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345AD11B24C6EDD9004E2EE1 /* AppDelegate.swift */; }; @@ -68,6 +69,7 @@ 02DC7FB12BA52084000EEEBE /* Libraries */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Libraries; sourceTree = ""; }; 02EACF2D2BABA34600FF8ECD /* FeedItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedItemCell.swift; sourceTree = ""; }; 02EACF2F2BABA50D00FF8ECD /* TopWordsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopWordsCell.swift; sourceTree = ""; }; + 02EACF312BABB23A00FF8ECD /* TopWordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopWordsView.swift; sourceTree = ""; }; 02EACF332BABB28900FF8ECD /* TopWord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopWord.swift; sourceTree = ""; }; 02EACF352BABB2F200FF8ECD /* TopWord+DTOs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TopWord+DTOs.swift"; sourceTree = ""; }; 345AD11824C6EDD9004E2EE1 /* Reviews.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Reviews.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -154,6 +156,7 @@ isa = PBXGroup; children = ( 0220ADA22BA90646001E6A9F /* FeedItemView.swift */, + 02EACF312BABB23A00FF8ECD /* TopWordsView.swift */, ); path = Views; sourceTree = ""; @@ -445,6 +448,7 @@ 02EACF362BABB2F200FF8ECD /* TopWord+DTOs.swift in Sources */, 02DC7FAF2BA51B4C000EEEBE /* Review.swift in Sources */, 02DC7FAE2BA51B4C000EEEBE /* FeedListViewController.swift in Sources */, + 02EACF322BABB23A00FF8ECD /* TopWordsView.swift in Sources */, 02909E792BAB6B0200710E14 /* FilterOption.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;