forked from Chalarangelo/30-seconds-of-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell.js
More file actions
130 lines (125 loc) · 3.27 KB
/
Copy pathShell.js
File metadata and controls
130 lines (125 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from 'react';
import { graphql, useStaticQuery, Link } from 'gatsby';
import { connect } from 'react-redux';
import config from '../../../config';
import { toggleDarkMode } from '../state/app';
import SearchIcon from './SVGs/SearchIcon';
import GithubIcon from './SVGs/GithubIcon';
import DarkModeIcon from './SVGs/DarkModeIcon';
import LightModeIcon from './SVGs/LightModeIcon';
import ListIcon from './SVGs/ListIcon';
// ===================================================
// Application-level UI component
// ===================================================
const Shell = ({
isDarkMode,
isSearch,
isList,
dispatch,
withIcon = true,
withTitle = true,
children,
}) => {
const data = useStaticQuery(graphql`
query SiteTitleQuery {
site {
siteMetadata {
title
description
}
}
file(relativePath: { eq: "30s-icon.png" }) {
id
childImageSharp {
original {
src
}
}
}
snippetDataJson(meta: { type: { eq: "snippetListingArray" } }) {
data {
title
id
attributes {
tags
}
}
}
}
`);
return (
<div className={isDarkMode ? 'page-container dark' : 'page-container'}>
{/* Menu */}
<header className='menu'>
<Link
to='/search'
aria-label='Search'title='Search'
className={isSearch ? 'menu-button active' : 'menu-button'}
>
<SearchIcon />
</Link>
<Link
to='/list'
aria-label='Snippet list' title='Snippet list'
className={isList ? 'menu-button active' : 'menu-button'}
>
<ListIcon />
</Link>
{/* eslint-disable-next-line */}
<a target='_blank'
rel='noopener'
href={config.repositoryUrl}
aria-label='View on GitHub' title='View on GitHub'
className='menu-button'
>
<GithubIcon />
</a>
<button
aria-label={isDarkMode ? 'Switch to light mode' : 'Switch to dark mode'}
title={isDarkMode ? 'Switch to light mode' : 'Switch to dark mode'}
className='menu-button'>
{isDarkMode ? (
<LightModeIcon
key='lmit'
onClick={() => dispatch(toggleDarkMode(!isDarkMode))}
/>
) : (
<DarkModeIcon
key='dmit'
onClick={() => dispatch(toggleDarkMode(!isDarkMode))}
/>
)}
</button>
</header>
{/* Content */}
<div className='content'>
{withTitle ? (
<h1 className='website-title'>
{data.site.siteMetadata.title}
{withIcon ? (
<img
src={data.file.childImageSharp.original.src}
alt='Logo'
className='website-logo'
/>
) : (
''
)}
</h1>
) : (
''
)}
{children}
</div>
</div>
);
};
export default connect(
state => ({
isDarkMode: state.app.isDarkMode,
lastPageTitle: state.app.lastPageTitle,
lastPageUrl: state.app.lastPageUrl,
searchQuery: state.app.searchQuery,
}),
null,
)(Shell);