forked from housseindjirdeh/angular2-hn
-
Notifications
You must be signed in to change notification settings - Fork 15
PR 6/10 — Port the feed list and story item components #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devanshi-gpta
wants to merge
2
commits into
devin-09.08.2026-devanshi/add-shared-and-core-components
Choose a base branch
from
devin-09.08.2026-devanshi/port-feed-views
base: devin-09.08.2026-devanshi/add-shared-and-core-components
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| @import "../../styles/media"; | ||
| @import "../../styles/theme_variables"; | ||
|
|
||
| p { | ||
| margin: 2px 0; | ||
|
|
||
| @media #{$mobile-only} { | ||
| margin-bottom: 5px; | ||
| margin-top: 0; | ||
| } | ||
| } | ||
|
|
||
| a { | ||
| cursor: pointer; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .title { | ||
| font-size: 16px; | ||
| font-family: Verdana, Geneva, sans-serif; | ||
| } | ||
|
|
||
| .subtext-laptop { | ||
| font-size: 12px; | ||
| font-weight: bold; | ||
| letter-spacing: 0.5px; | ||
|
|
||
| a { | ||
| &:hover { | ||
| text-decoration: underline; | ||
| }; | ||
| } | ||
| @media #{$mobile-only} { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
| .subtext-palm { | ||
| font-size: 13px; | ||
| font-weight: bold; | ||
| letter-spacing: 0.5px; | ||
|
|
||
| a { | ||
| &:hover { | ||
| text-decoration: underline; | ||
| }; | ||
| } | ||
|
|
||
| .details { | ||
| margin-top: 5px; | ||
|
|
||
| .right { | ||
| float: right; | ||
| } | ||
| } | ||
| @media #{$laptop-only} { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
| .domain { | ||
| color: #696969; | ||
| letter-spacing: 0.5px; | ||
| } | ||
|
|
||
| .item-details { | ||
| padding: 10px; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { MemoryRouter } from 'react-router-dom'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { SettingsProvider } from '../../context/SettingsContext'; | ||
| import type { Story } from '../../models/story'; | ||
| import Item, { hasUrl } from './Item'; | ||
|
|
||
| const story: Story = { | ||
| id: 1, | ||
| title: 'A linked story', | ||
| points: 42, | ||
| user: 'pg', | ||
| time: 0, | ||
| time_ago: 0, | ||
| type: 'story', | ||
| url: 'https://example.com/post', | ||
| domain: 'example.com', | ||
| comments_count: 3, | ||
| }; | ||
|
|
||
| function renderItem(item: Story) { | ||
| return render( | ||
| <MemoryRouter> | ||
| <SettingsProvider> | ||
| <Item item={item} /> | ||
| </SettingsProvider> | ||
| </MemoryRouter> | ||
| ); | ||
| } | ||
|
|
||
| describe('Item', () => { | ||
| it('detects external urls', () => { | ||
| expect(hasUrl(story)).toBe(true); | ||
| expect(hasUrl({ ...story, url: 'item?id=1' })).toBe(false); | ||
| expect(hasUrl({ ...story, url: undefined })).toBe(false); | ||
| }); | ||
|
|
||
| it('links external stories to their url and shows the domain', () => { | ||
| renderItem(story); | ||
|
|
||
| const link = screen.getByRole('link', { name: 'A linked story' }); | ||
| expect(link).toHaveAttribute('href', 'https://example.com/post'); | ||
| expect(link).not.toHaveAttribute('target'); | ||
| expect(screen.getByText('(example.com)')).toBeInTheDocument(); | ||
| expect(screen.getAllByText(/3 comments/).length).toBe(2); | ||
| }); | ||
|
|
||
| it('links self posts to the item page', () => { | ||
| renderItem({ ...story, url: undefined, domain: undefined }); | ||
|
|
||
| expect(screen.getByRole('link', { name: 'A linked story' })).toHaveAttribute( | ||
| 'href', | ||
| '/item/1' | ||
| ); | ||
| }); | ||
|
|
||
| it('hides points and comments for jobs', () => { | ||
| renderItem({ ...story, type: 'job' }); | ||
|
|
||
| expect(screen.queryByText('pg')).not.toBeInTheDocument(); | ||
| expect(screen.queryByText(/comments/)).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { Link, NavLink } from 'react-router-dom'; | ||
|
|
||
| import { useSettings } from '../../context/SettingsContext'; | ||
| import type { Story } from '../../models/story'; | ||
| import { formatCommentCount } from '../../utils/format-comment-count'; | ||
|
|
||
| import './Item.scss'; | ||
|
|
||
| export interface ItemProps { | ||
| item: Story; | ||
| } | ||
|
|
||
| export function hasUrl(item: Story): boolean { | ||
| return item.url?.startsWith('http') ?? false; | ||
| } | ||
|
|
||
| function activeClass({ isActive }: { isActive: boolean }) { | ||
| return isActive ? 'active' : ''; | ||
| } | ||
|
|
||
| export default function Item({ item }: ItemProps) { | ||
| const { settings } = useSettings(); | ||
| const titleStyle = { fontSize: `${settings.titleFontSize}px` }; | ||
| const newTabProps = settings.openLinkInNewTab | ||
| ? { target: '_blank', rel: 'noopener' } | ||
| : {}; | ||
|
|
||
| return ( | ||
| <div style={{ marginBottom: `${settings.listSpacing}px` }}> | ||
| {hasUrl(item) ? ( | ||
| <p> | ||
| <a className="title" style={titleStyle} href={item.url} {...newTabProps}> | ||
| {item.title} | ||
| </a> | ||
| {item.domain && <span className="domain">({item.domain})</span>} | ||
| </p> | ||
| ) : ( | ||
| <p> | ||
| <Link className="title" style={titleStyle} to={`/item/${item.id}`}> | ||
| {item.title} | ||
| </Link> | ||
| </p> | ||
| )} | ||
| <div className="subtext-palm"> | ||
| {item.type !== 'job' && ( | ||
| <div className="details"> | ||
| <span> | ||
| <NavLink to={`/user/${item.user}`} className={activeClass}> | ||
| {item.user} | ||
| </NavLink> | ||
| </span> | ||
| <span className="right">{item.points} ★</span> | ||
| </div> | ||
| )} | ||
| <div className="details"> | ||
| {item.time_ago} | ||
| {item.type !== 'job' && ( | ||
| <NavLink | ||
| to={`/item/${item.id}`} | ||
| className={({ isActive }) => | ||
| isActive ? 'comment-number active' : 'comment-number' | ||
| } | ||
| > | ||
| {' '} | ||
| • {formatCommentCount(item.comments_count)} | ||
| </NavLink> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <div className="subtext-laptop"> | ||
| {item.type !== 'job' && ( | ||
| <span> | ||
| {item.points} points by{' '} | ||
| <NavLink to={`/user/${item.user}`} className={activeClass}> | ||
| {item.user} | ||
| </NavLink> | ||
| </span> | ||
| )} | ||
| <span className={item.type !== 'job' ? 'item-details' : undefined}> | ||
| {item.time_ago} | ||
| {item.type !== 'job' && ( | ||
| <span> | ||
| {' '} | ||
| |{' '} | ||
| <NavLink to={`/item/${item.id}`} className={activeClass}> | ||
| {formatCommentCount(item.comments_count)} | ||
| </NavLink> | ||
| </span> | ||
| )} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| @import "../styles/media"; | ||
| @import "../styles/theme_variables"; | ||
|
|
||
| a { | ||
| text-decoration: none; | ||
| font-weight: bold; | ||
|
|
||
| &:hover { | ||
| text-decoration: underline; | ||
| }; | ||
| } | ||
|
|
||
| ol { | ||
| padding: 0 40px; | ||
| margin: 0; | ||
|
|
||
| @media #{$mobile-only} { | ||
| box-sizing: border-box; | ||
| list-style: none; | ||
| padding: 0 10px; | ||
| } | ||
|
|
||
| li { | ||
| position: relative; | ||
| -webkit-transition: background-color .2s ease; | ||
| transition: background-color .2s ease; | ||
| } | ||
| } | ||
|
|
||
| .list-margin { | ||
| @media #{$mobile-only} { | ||
| margin-top: 55px; | ||
| } | ||
| } | ||
|
|
||
| .main-content { | ||
| position: relative; | ||
| width: 100%; | ||
| min-height: 100vh; | ||
| -webkit-transition: opacity .2s ease; | ||
| transition: opacity .2s ease; | ||
| box-sizing: border-box; | ||
| padding: 8px 0; | ||
| z-index: 0; | ||
| } | ||
|
|
||
| .post { | ||
| padding: 10px 0 10px 5px; | ||
| transition: background-color 0.2s ease; | ||
| border-bottom: 1px solid #CECECB; | ||
|
|
||
| .itemNum { | ||
| color: #696969; | ||
| position: absolute; | ||
| width: 30px; | ||
| text-align: right; | ||
| left: 0; | ||
| top: 4px; | ||
| } | ||
| } | ||
|
|
||
| .item-block { | ||
| display: block; | ||
| } | ||
|
|
||
|
|
||
| .nav { | ||
| padding: 10px 40px; | ||
| margin-top: 10px; | ||
| font-size: 17px; | ||
|
|
||
| a { | ||
| @media #{$mobile-only} { | ||
| text-decoration: none; | ||
| } | ||
| } | ||
|
|
||
| @media #{$mobile-only} { | ||
| margin: 20px 0; | ||
| text-align: center; | ||
| padding: 10px 80px; | ||
| height: 20px; | ||
| } | ||
|
|
||
| .prev { | ||
| padding-right: 20px; | ||
|
|
||
| @media #{$mobile-only} { | ||
| float: left; | ||
| padding-right: 0; | ||
| } | ||
| } | ||
|
|
||
| .more { | ||
| @media #{$mobile-only} { | ||
| float: right; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .job-header { | ||
| font-size: 15px; | ||
| padding: 0 40px 10px; | ||
|
|
||
| @media #{$mobile-only} { | ||
| padding: 60px 15px 25px 15px; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Ported styles are now global
Angular previously scoped these selectors per component. Audit
a,p,ol,.nav,.title, and.detailsbefore the app shell mounts feeds.Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. Global SCSS is the established convention in
react-app/(_themes.scsstargets global class names like.wrapper/.nav, so CSS Modules would break theming), and these rules are a verbatim port offeed.component.scss. The one real collision found so far (.namevs the header rule) is fixed in 3967066; a broader audit of the barea/p/olselectors is best done once the router mounts all views together.