Skip to content
FrontDepth, Home

Feed filters

Code ReviewSenior
Target
find the 3 must-fix problems (4 in all)
Your best
Not played yet

Pull request

Feed: tags, replies, back to top · feature/feed-v2

The feed grows to a few hundred posts a day, so this pull request:

  • sorts it newest first and adds tag filters;
  • adds a reply box to every card (the draft stays in the card);
  • shrinks the cards below the fold while scrolling, and shows a Back to top button further down.

Your teammate wrote it with an AI assistant and checked it on a feed of twenty posts. Review it before it is merged: comment on every line that has to change, and give each comment a category.

Hints

    Your comments

      Scoring: a comment finds a problem when it is on the problem's lines (or one line around them) and names its category. The score is the share of problems found, minus half a problem for each comment that finds nothing new. Find every must-fix problem, with no more such comments than there are problems, to complete the challenge. Only your first review is scored.

      1import { useEffect, useState } from "react";
      2import { PostCard } from "./PostCard.jsx";
      3
      3export function Feed({ posts }) {
      4export function Feed({ posts, tags }) {
      5 const [tag, setTag] = useState("all");
      6 const [showTop, setShowTop] = useState(false);
      7
      8 // Newest first, then only the chosen tag.
      9 const sorted = posts.sort((a, b) => b.createdAt - a.createdAt);
      10 const visible = tag === "all" ? sorted : sorted.filter((post) => post.tags.includes(tag));
      11
      12 useEffect(() => {
      13 function onScroll() {
      14 // Cards below the fold show only their title until the user gets there.
      15 for (const card of document.querySelectorAll(".post-card")) {
      16 card.style.height = card.getBoundingClientRect().top > window.innerHeight ? "3rem" : "auto";
      17 }
      18 // Show "Back to top" once the user has scrolled down.
      19 if (window.scrollY > 800 !== showTop) setShowTop(!showTop);
      20 }
      21 window.addEventListener("scroll", onScroll, { passive: true });
      22 return () => window.removeEventListener("scroll", onScroll);
      23 }, []);
      24
      25 return (
      5 <ul className="feed">
      6 {posts.map((post) => (
      7 <PostCard key={post.id} post={post} />
      8 ))}
      9 </ul>
      26 <>
      27 <div className="tags" role="group" aria-label="Filter by tag">
      28 {["all", ...tags].map((name) => (
      29 <button key={name} aria-pressed={tag === name} onClick={() => setTag(name)}>
      30 {name}
      31 </button>
      32 ))}
      33 </div>
      34 <ul className="feed">
      35 {visible.map((post, index) => (
      36 <PostCard key={index} post={post} />
      37 ))}
      38 </ul>
      39 {showTop && (
      40 <button className="back-to-top" onClick={() => window.scrollTo({ top: 0 })}>
      41 Back to top
      42 </button>
      43 )}
      44 </>
      45 );
      46}