Skip to content
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

Feat: Update Fronted to Next13 #356

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
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
13 changes: 0 additions & 13 deletions frontend/.eslintrc

This file was deleted.

3 changes: 3 additions & 0 deletions frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import Image from "next/image";

const Footer = () => (
<div className="labs-footer bg-black">
<p className="white">A Labs project from your friends at</p>
<a href="https://postlight.com/">
<img src="/static/images/postlight-logo.svg" height="32"/>
<Image src="/images/postlight-logo.svg" width={32} height={32} alt="Postlight Logo" />
</a>
</div>
);
Expand Down
22 changes: 0 additions & 22 deletions frontend/components/Header.js

This file was deleted.

11 changes: 11 additions & 0 deletions frontend/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Head from 'next/head';

const Header = () => (
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charSet="utf-8" />
<title>WordPress + React Starter Kit Frontend by Postlight</title>
</Head>
);

export default Header;
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React from 'react';
import Header from './Header';
import Menu from './Menu';
import Footer from './Footer';

const Layout = props => {
Expand Down
124 changes: 0 additions & 124 deletions frontend/components/Menu.js

This file was deleted.

115 changes: 115 additions & 0 deletions frontend/components/Menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { FC, useEffect, useState } from 'react';
import Link from 'next/link';
import Router from 'next/router';
import Image from 'next/image';

import Logo from './common/Logo';
import Config from '../config';

interface Props {
menu: any
}

const getSlug = (url) => {
const parts = url.split('/');
return parts.length > 2 ? parts[parts.length - 2] : '';
};

const Menu: FC<Props> = ({ menu }) => {
const [auth, setAuth] = useState(null);

useEffect(() => {
const token = localStorage.getItem(Config.AUTH_TOKEN);
const username = localStorage.getItem(Config.USERNAME);
setAuth({ token, username });
}, []);

const handleSelectChange = (e) => {
location.href = e.target.value;
};

return (
<div className="menu bb">
<div className="flex justify-between w-90-l center-l">
<div className="brand bb flex justify-center items-center w-100 justify-between-l bn-l">
<Link href="/" className="starter-kit-logo">
<Logo width={48} height={32} />
<div className="pl2">
WordPress + React
<br />
Starter Kit
</div>
</Link>
</div>
<div className="links dn flex-l justify-between items-center">
{menu.items.map((item) => {
if (item.object === 'custom') {
return (
<a href={item.url} key={item.ID}>
{item.title}
</a>
);
}
const slug = getSlug(item.url);
const actualPage =
item.object === 'category' ? 'category' : 'post';
return (
<Link
href={`/${actualPage}/${slug}`}
key={item.ID}
>
{item.title}
</Link>
);
})}

<Link href="/search">
<Image src="/images/search.svg" width={25} height={25} alt="Search icon" />
</Link>

{auth?.token ? (
<a
className="pointer round-btn ba bw1 pv2 ph3"
onClick={() => {
localStorage.removeItem(Config.AUTH_TOKEN);
Router.push('/login');
}}
>
Log out {auth.username}
</a>
) : (
<Link href="/login" className="round-btn ba bw1 pv2 ph3">
Log in
</Link>
)}
</div>
</div>
<div className="dropdown bb flex justify-center items-center dn-l">
<select onChange={handleSelectChange}>
<option>Menu</option>
{menu.items.map((item) => {
if (item.object === 'custom') {
return (
<option value={item.url} key={item.ID}>
{item.title}
</option>
);
}
const slug = getSlug(item.url);
const actualPage =
item.object === 'category' ? 'category' : 'post';
return (
<option
value={`/${actualPage}?slug=${slug}&apiRoute=${item.object}`}
key={item.ID}
>
{item.title}
</option>
);
})}
</select>
</div>
</div>
);
}
export default Menu;
29 changes: 0 additions & 29 deletions frontend/components/PageWrapper.js

This file was deleted.

16 changes: 16 additions & 0 deletions frontend/components/common/Logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
interface Props {
width: number;
height: number;
color?: string;
}

export default function Logo({ width, height, color = "#000" }: Props) {
return (
<svg width={width} height={height} viewBox="0 0 214 142" version="1.1">
<g id="logo/postlight/starter-kit" stroke="none" strokeWidth="1" fill={color} fillRule="evenodd">
<path d="M213.066017,71 L142.355339,141.710678 L107,106.355339 L71.644661,141.710678 L0.933983,71 L71.644661,0.289322 L107,35.644661 L142.355339,0.289322 L213.066017,71 Z M142.355339,71 L107,35.644661 L71.644661,71 L107,106.355339 L142.355339,71 Z" id="Shape" fill={color} fillRule="nonzero"></path>
</g>
</svg>

)
}
2 changes: 2 additions & 0 deletions frontend/config.js → frontend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let wpUrl = 'http://localhost:8080/wp-json';
if (process.env.HOME === '/home/node') {
wpUrl = 'http://wp-headless:8080/wp-json';
}

// TODO: These should be env vars...
const Config = {
apiUrl: wpUrl,
AUTH_TOKEN: 'auth-token',
Expand Down
5 changes: 5 additions & 0 deletions frontend/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
Loading