[Framework] Show top words for filtered items in the Feed List (#12)
This PR contains the work done to show the top 3 words belonging to the filtered reviews in the `FeedListViewController` view controller. Reviewed-on: rock-n-code/app-reviews#12 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #12.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// FeedItemView.swift
|
||||
// ReviewsFeed
|
||||
//
|
||||
// Created by Javier Cicchelli on 19/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import ReviewsUIKit
|
||||
import SwiftUI
|
||||
|
||||
struct FeedItemView: View {
|
||||
|
||||
// MARK: Constants
|
||||
private let item: Review
|
||||
|
||||
// MARK: Initialisers
|
||||
init(_ item: Review) {
|
||||
self.item = item
|
||||
}
|
||||
|
||||
// MARK: Body
|
||||
var body: some View {
|
||||
VStack(
|
||||
alignment: .leading,
|
||||
spacing: 16
|
||||
) {
|
||||
FakeLabel(
|
||||
systemIcon: .Icon.person,
|
||||
title: item.author
|
||||
)
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
VStack(spacing: 8) {
|
||||
Text(item.title)
|
||||
.font(.headline)
|
||||
.lineLimit(2)
|
||||
.fullWidth()
|
||||
|
||||
Text(item.comment)
|
||||
.font(.body)
|
||||
.lineLimit(4)
|
||||
.fullWidth()
|
||||
}
|
||||
.multilineTextAlignment(.leading)
|
||||
|
||||
HStack(
|
||||
alignment: .center,
|
||||
spacing: 32
|
||||
) {
|
||||
StarRating(
|
||||
item.rating.stars,
|
||||
of: .Rating.total
|
||||
)
|
||||
|
||||
FakeLabel(
|
||||
systemIcon: .Icon.info,
|
||||
title: item.rating.appVersion
|
||||
)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
#Preview("Feed Item") {
|
||||
FeedItemView(.init(
|
||||
author: "Some author name here...",
|
||||
comment: "Some review comment here...",
|
||||
id: 0,
|
||||
rating: .init(
|
||||
stars: 1,
|
||||
appVersion: "v1.2.3"
|
||||
),
|
||||
title: "Some review title here..."
|
||||
))
|
||||
.padding(.horizontal)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user