Skip to content

Commit 3beba40

Browse files
top menu done
1 parent ea800fe commit 3beba40

File tree

14 files changed

+108
-55
lines changed

14 files changed

+108
-55
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
quote_type = single

src/app/app.route.conts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum AppRoute {
2+
Home = '/',
3+
Articles = '/articles',
4+
AboutMe = '/amout-me',
5+
}

src/components/layout.tsx

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import Head from 'next/head';
2-
// import Image from 'next/image';
3-
import Link from 'next/link';
42
import { translate, translationKeys } from '../logic/translations/translation.service';
53
import styled from 'styled-components';
4+
import { Menu } from './menu/menu';
65

7-
const name = '[Your Name]';
8-
9-
interface LayoutProps {
10-
home?: boolean;
11-
}
12-
13-
export const Layout: React.FC<LayoutProps> = ({ children, home }) => {
6+
export const Layout: React.FC = ({ children }) => {
147
return (
15-
<Main>
8+
<>
169
<Head>
1710
<link rel="icon" href="/favicon.ico" />
1811
<meta name="description" content="Learn how to build a personal website using Next.js" />
@@ -30,40 +23,17 @@ export const Layout: React.FC<LayoutProps> = ({ children, home }) => {
3023
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@700&display=swap" rel="stylesheet" />
3124
</Head>
3225
<header>
33-
{home ? (
34-
<>
35-
{/* <Image priority src="/images/profile.jpg" height={144} width={144} alt={name} /> */}
36-
<h1>{name} </h1>
37-
</>
38-
) : (
39-
<>
40-
{/* <Link href="/">
41-
<a>
42-
<Image priority src="/images/profile.jpg" height={108} width={108} alt={name} />
43-
</a>
44-
</Link> */}
45-
<h2>
46-
<Link href="/">
47-
<a>{name}</a>
48-
</Link>
49-
</h2>
50-
</>
51-
)}
26+
<Menu />
5227
</header>
53-
<main>{children}</main>
54-
{!home && (
55-
<div>
56-
<Link href="/">
57-
<a>← Back to home</a>
58-
</Link>
59-
</div>
60-
)}
61-
</Main>
28+
<Main>
29+
<main>{children}</main>
30+
</Main>
31+
</>
6232
);
6333
};
6434

6535
const Main = styled.div`
6636
max-width: 36rem;
6737
padding: 0 1rem;
68-
margin: 3rem auto 6rem;
38+
margin: 0 auto 6rem;
6939
`;

src/components/link.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Link from 'next/link';
2+
import styled from 'styled-components';
3+
4+
export const LinkTo = styled(Link)``;

src/components/menu/menu.const.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { AppRoute } from '../../app/app.route.conts';
2+
3+
export const topMenuItems = [AppRoute.Home, AppRoute.Articles, AppRoute.AboutMe];

src/components/menu/menu.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import styled from 'styled-components';
2+
import { translate, translationKeys } from '../../logic/translations/translation.service';
3+
import { topMenuItems } from './menu.const';
4+
import { LinkTo } from '../../components/link';
5+
6+
export const Menu = () => {
7+
return (
8+
<MenuContainer>
9+
{topMenuItems.map((route) => (
10+
<MenuItem key={route}>
11+
<LinkTo href={route}>{translate(translationKeys.site.routes[route])}</LinkTo>
12+
</MenuItem>
13+
))}
14+
</MenuContainer>
15+
);
16+
};
17+
18+
const MenuContainer = styled.div`
19+
margin-top: 32px;
20+
margin-right: 64px;
21+
display: flex;
22+
justify-content: flex-end;
23+
24+
@media only screen and (max-width: 768px) {
25+
margin-top: 0;
26+
margin-right: 0;
27+
justify-content: center;
28+
border-bottom-color: black;
29+
border-bottom-style: solid;
30+
border-bottom-width: thin;
31+
}
32+
`;
33+
34+
const MenuItem = styled.div`
35+
padding: 16px;
36+
`;

src/content/accessing-i18next-translation-from-json-keys-instead-of-string-path.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
title: 'Accessing i18next translation from JSON keys instead of string path'
33
date: '2021-05-25'
4+
author: 'Wojciech Cendrzak'
5+
image: '/images/translate.png'
46
---
57

68
**TypeScript** is awesome. Like **i18next** too. It works with TypeScript great but has one drawback. We need to provide a translation key as a plain string. It doesn't matter for small apps, but it does indeed for complex one when your translation file start to have hundreds of lines.

src/logic/translations/locales/en.json

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { AppRoute } from '../../../app/app.route.conts';
2+
3+
export const en = {
4+
site: {
5+
// TDO: use this title
6+
title: 'Code Calligraphy',
7+
routes: {
8+
[AppRoute.Home]: 'Home',
9+
[AppRoute.Articles]: 'Articles',
10+
[AppRoute.AboutMe]: 'AboutMe',
11+
},
12+
},
13+
common: {
14+
buttons: {
15+
backToHome: {
16+
title: 'Back to home',
17+
},
18+
},
19+
},
20+
homePage: {
21+
title: 'Home page',
22+
aboutMe: {
23+
title: 'About me',
24+
description: "I'am frontend developer",
25+
},
26+
},
27+
};

src/logic/translations/translation.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import en from './locales/en.json';
1+
import { en } from './locales/en';
22
import i18next, { TFunction } from 'i18next';
33
import { getTranslationKeys } from 'i18n-keys';
44

0 commit comments

Comments
 (0)