Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions react-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-66348622-3', 'auto');
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { Suspense } from 'react';
import { Outlet } from 'react-router-dom';
import { usePageViews } from './analytics/usePageViews';
import { Footer } from './components/Footer/Footer';
import { Header } from './components/Header/Header';
import { Loader } from './components/Loader/Loader';
import { useSettings } from './settings';
import './styles/app.scss';

export default function App() {
const { settings } = useSettings();
usePageViews();
return (
<div className={settings.theme}>
<div className="body-cover"></div>
<div className="wrapper">
<Header />
<Suspense fallback={<Loader />}>
<Outlet />
</Suspense>
<Footer />
</div>
</div>
);
Expand Down
17 changes: 17 additions & 0 deletions react-app/src/analytics/usePageViews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

declare global {
interface Window {
ga?: (...args: unknown[]) => void;
}
}

// Mirrors AppComponent's NavigationEnd hook: one GA pageview per route change.
export function usePageViews() {
const { pathname, search } = useLocation();
useEffect(() => {
window.ga?.('set', 'page', pathname + search);
window.ga?.('send', 'pageview');
}, [pathname, search]);
}
22 changes: 22 additions & 0 deletions react-app/src/components/Footer/Footer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@use "../../styles/media" as *;

#footer {
position: relative;
padding: 10px;
height: 60px;
letter-spacing: 0.7px;
text-align: center;

a {
font-weight: bold;
text-decoration: none;

&:hover {
text-decoration: underline;
}
}

@media #{$mobile-only} {
display: none;
}
}
14 changes: 14 additions & 0 deletions react-app/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import './Footer.scss';

export function Footer() {
return (
<div id="footer">
<p>
Show this project some ❤ on{' '}
<a href="https://github.com/hdjirdeh/angular2-hn" target="_blank" rel="noopener">
GitHub
</a>
</p>
</div>
);
}
158 changes: 158 additions & 0 deletions react-app/src/components/Header/Header.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
@use "../../styles/media" as *;

#header {
color: #fff;
padding: 6px 0;
line-height: 18px;
vertical-align: middle;
position: relative;
z-index: 1;
width: 100%;

@media #{$mobile-only} {
height: 50px;
position: fixed;
top: 0;
}

a {
display: inline;
}

// Scoped: React has no Angular view encapsulation, and feed rows also use .name/.left etc.

.home-link {
width: 50px;
height: 66px;
}

.logo-inner {
width: 32px;
position: absolute;
left: 17px;
top: 18px;
z-index: -1;
height: 32px;
border-radius: 50%;

@media #{$mobile-only} {
left: 16px;
top: 12px;
}
}

.logo {
width: 50px;
padding: 3px 8px 0;

@media #{$mobile-only} {
width: 45px;
padding: 0 0 0 10px;
}
}

h1 {
font-weight: normal;
display: inline-block;
vertical-align:middle;
margin: 0;
font-size: 16px;

a {
color: #fff;
text-decoration: none;
}
}

.name {
margin-right: 30px;
margin-bottom: 2px;

@media #{$mobile-only} {
display: none;
}
}

.header-text {
position: absolute;
width: inherit;
height: 20px;
left: 10px;
top: 27px;
z-index: -1;

@media #{$mobile-only} {
top: 22px;
}
}

.left {
position: absolute;
left: 60px;
font-size: 16px;

@media #{$mobile-only} {
width: 100%;
left: 0;
}
}

.header-nav {
display: inline-block;
margin-left: 20px;

@media #{$mobile-only} {
margin-left: 60px;
}

a {
color: hsla(0,0%,100%,.9);
text-decoration: none;
margin: 0 5px;
letter-spacing: 1.8px;

&:hover {
color: #fff;
}
}

.active {
color: #fff;
}
}

.info {
position: absolute;
top: 0;
right: 20px;
height: 100%;

@media #{$mobile-only} {
right: 10px;
}

img {
opacity: 0.8;
width: 25px;
margin-top: 21.5px;
display: block;

&:hover {
opacity: 1;
cursor: pointer;
}

@media #{$mobile-only} {
margin-top: 15px;
}
}
}

.settings-button {
padding: 0;
border: 0;
background: none;
cursor: pointer;
font: inherit;
}
}
49 changes: 49 additions & 0 deletions react-app/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { NavLink } from 'react-router-dom';
import { useSettings } from '../../settings';
import { SettingsPanel } from '../Settings/SettingsPanel';
import './Header.scss';

const NAV_LINKS = [
{ to: '/newest/1', label: 'new' },
{ to: '/show/1', label: 'show' },
{ to: '/ask/1', label: 'ask' },
{ to: '/jobs/1', label: 'jobs' },
];

function scrollTop() {
window.scrollTo(0, 0);
}

export function Header() {
const { settings, toggleSettings } = useSettings();
return (
<header>
<div id="header">
<NavLink className="home-link" to="/news/1" onClick={scrollTop}>
<div className="logo-inner"></div>
<img className="logo" src="/assets/images/logo.svg" alt="Logo" />
</NavLink>
<div className="header-text">
<div className="left">
<span className="header-nav">
{NAV_LINKS.map(({ to, label }, i) => (
<span key={to}>
{i > 0 && ' | '}
<NavLink to={to} onClick={scrollTop}>
{label}
</NavLink>
</span>
))}
</span>
</div>
</div>
<div className="info">
<button type="button" className="settings-button" aria-label="Settings" onClick={toggleSettings}>
<img className="settings" src="/assets/images/cog.svg" alt="" />
</button>
</div>
</div>
{settings.showSettings && <SettingsPanel />}
</header>
);
}
78 changes: 78 additions & 0 deletions react-app/src/components/Settings/Settings.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@use "../../styles/media" as *;

.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
opacity: 1;
z-index: 1;
}

.popup {
margin: 70px auto;
padding: 30px;
border-radius: 5px;
width: 30%;
position: relative;
h1 {
margin-top: 0;
margin-bottom: 0px;
color: #fff;
text-align: center;
letter-spacing: 1px;
}
h2 {
padding-top: 10px;
}
hr {
width: 40%;
margin-bottom: 20px;
}
.close {
padding: 0;
border: 0;
background: none;
cursor: pointer;
line-height: 1;
position: absolute;
top: 12px;
right: 20px;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: rgba(255,255,255,0.8);
&:hover {
color: #fff;
cursor: pointer;
}
}
.content {
max-height: 30%;
color: #fff;
letter-spacing: 1px;
overflow: auto;
}
input[type=number] {
display: block;
width: 80%;
height: 20px;
margin-bottom: 15px;
border-radius: 5px;
padding: 2px;
}
}

.control-section {
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px solid white;
}

@media screen and (max-width: 700px) {
.box, .popup {
width: 70%;
}
}
Loading
Loading