This PR contains the work done to show the top 3 words belonging to the filtered reviews in the `FeedListViewController` view controller. Reviewed-on: #12 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
83 lines
1.8 KiB
Swift
83 lines
1.8 KiB
Swift
//
|
|
// 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)
|
|
}
|