Skip to content

Commit 077f7d1

Browse files
committed
fix tab active & local video
1 parent ff1b74c commit 077f7d1

8 files changed

+105
-82
lines changed

src/App.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
import React, { Component } from 'react';
1+
import { Component } from 'react';
22
import ResponsiveContainer from '#/ResponsiveContainer';
3-
import {
4-
Button,
5-
Container,
6-
Divider,
7-
Grid,
8-
Header,
9-
Icon,
10-
Image,
11-
List,
12-
Menu,
13-
Segment,
14-
Sidebar,
15-
} from 'semantic-ui-react';
3+
164
import Footer from '#/Footer';
175
import Homepage from './Homepage';
186
import { Route } from 'react-router';
19-
import { Router, Routes } from 'react-router-dom';
7+
import { Routes } from 'react-router-dom';
208
import Blog from './Blog';
219
import Foundation from './Foundation';
10+
import { foundationPathName, blogListPathName } from './const';
2211
interface IProps {}
2312

2413
interface IState {}
@@ -33,8 +22,8 @@ class App extends Component<IProps, IState> {
3322
<>
3423
<ResponsiveContainer>
3524
<Routes>
36-
<Route path="/foundation" element={<Foundation />}></Route>
37-
<Route path="/blog_list" element={<Blog />}></Route>
25+
<Route path={foundationPathName} element={<Foundation />}></Route>
26+
<Route path={blogListPathName} element={<Blog />}></Route>
3827
<Route path="/" element={<Homepage />}></Route>
3928
</Routes>
4029
</ResponsiveContainer>

src/DesktopContainer.tsx

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
import React, { Component } from 'react';
2-
import HomepageHeading from '#/HomepageHeading';
3-
import { Media } from '#/const';
2+
import {
3+
blogListPathName,
4+
foundationPathName,
5+
homePathName,
6+
Media,
7+
} from '#/const';
48
import {
59
Button,
610
Container,
7-
Divider,
8-
Grid,
9-
Header,
10-
Icon,
11-
Image,
12-
List,
1311
Menu,
1412
Segment,
15-
Sidebar,
1613
Popup,
1714
Visibility,
15+
MenuItemProps,
1816
} from 'semantic-ui-react';
19-
import { Route } from 'react-router';
20-
import { Router, Routes } from 'react-router-dom';
2117
import CustomRouter from '#/CustomRouter';
2218
import { history } from '#/const';
2319
import { scrollToTopAndRoute } from '#/utils';
24-
import Homepage from '#/Homepage';
25-
import Blog from '#/Blog';
2620

2721
interface IProps {}
2822

2923
interface IState {
24+
activeItem: string;
3025
fixed: boolean;
3126
muteVideo: boolean;
3227
}
@@ -39,18 +34,30 @@ class DesktopContainer extends Component<IProps, IState> {
3934
static defaultProps = {};
4035

4136
state = {
37+
activeItem: homePathName,
4238
fixed: false,
4339
muteVideo: true,
4440
};
4541

4642
hideFixedMenu = () => this.setState({ fixed: false });
4743
showFixedMenu = () => this.setState({ fixed: true });
4844

49-
handleMuteVideoClicked = () => {
50-
this.setState({ muteVideo: !this.state.muteVideo });
45+
componentDidMount = async () => {
46+
let pathname = window.location.pathname;
47+
if (pathname.length > 1) {
48+
this.setState({
49+
activeItem: pathname,
50+
});
51+
}
5152
};
5253

53-
componentDidMount = async () => {};
54+
handleMenuItemClick = (
55+
event: React.MouseEvent<HTMLElement>,
56+
menuItemProps: MenuItemProps
57+
) => {
58+
this.setState({ activeItem: menuItemProps.name! });
59+
scrollToTopAndRoute(menuItemProps.name!);
60+
};
5461

5562
render() {
5663
const { children } = this.props;
@@ -83,7 +90,11 @@ class DesktopContainer extends Component<IProps, IState> {
8390
size="large"
8491
>
8592
<Container>
86-
<Menu.Item as="a" href="/" active>
93+
<Menu.Item
94+
as="a"
95+
href="/"
96+
active={this.state.activeItem === homePathName}
97+
>
8798
Home
8899
</Menu.Item>
89100
<Popup
@@ -129,15 +140,21 @@ class DesktopContainer extends Component<IProps, IState> {
129140
inverted
130141
on="hover"
131142
/>
132-
<Menu.Item onClick={() => scrollToTopAndRoute('/blog_list')}>
143+
<Menu.Item
144+
name={blogListPathName}
145+
onClick={this.handleMenuItemClick}
146+
active={this.state.activeItem === blogListPathName}
147+
>
133148
BLOG
134149
</Menu.Item>
135150

136-
<Menu.Item position="right">
137-
<Button
138-
onClick={() => scrollToTopAndRoute('/foundation')}
139-
inverted={!fixed}
140-
>
151+
<Menu.Item
152+
position="right"
153+
name={foundationPathName}
154+
active={this.state.activeItem === foundationPathName}
155+
onClick={this.handleMenuItemClick}
156+
>
157+
<Button inverted={!fixed}>
141158
ArchLinuxStudio Foundation
142159
</Button>
143160
</Menu.Item>

src/Foundation.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import React, { Component } from 'react';
1+
import { Component } from 'react';
22
import {
33
Button,
44
Container,
55
Divider,
66
Grid,
77
Header,
88
Icon,
9-
Image,
10-
List,
11-
Menu,
129
Segment,
13-
Sidebar,
1410
} from 'semantic-ui-react';
1511

1612
interface IProps {}

src/Homepage.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import { Component } from 'react';
22
import {
33
Button,
44
Container,
@@ -7,10 +7,7 @@ import {
77
Header,
88
Icon,
99
Image,
10-
List,
11-
Menu,
1210
Segment,
13-
Sidebar,
1411
} from 'semantic-ui-react';
1512

1613
import ES from '#/images/ES.webp';
@@ -19,6 +16,7 @@ import RS_GTA from '#/images/RS_GTA1.jpg';
1916
import HomepageHeading from '#/HomepageHeading';
2017
import './homepage_video.css';
2118
import Loading from '#/images/loading.gif';
19+
import FSF30 from '#/videos/FSF_30_720p.webm';
2220

2321
interface IProps {}
2422

@@ -85,7 +83,7 @@ class Homepage extends Component<IProps, IState> {
8583
autoPlay={true}
8684
loop={true}
8785
playsInline={true}
88-
src="https://static.fsf.org/nosvn/FSF30-video/FSF_30_720p.webm"
86+
src={FSF30}
8987
poster={Loading}
9088
></video>
9189

@@ -224,6 +222,7 @@ class Homepage extends Component<IProps, IState> {
224222
href="https://en.wikipedia.org/wiki/Blockchain"
225223
target="_blank"
226224
size="large"
225+
rel="noreferrer"
227226
>
228227
Read More
229228
</Button>
@@ -237,6 +236,7 @@ class Homepage extends Component<IProps, IState> {
237236
<a
238237
href="https://github.com/ArchLinuxStudio?q=blockchain&type=all&language=&sort="
239238
target="_blank"
239+
rel="noreferrer"
240240
>
241241
Case Studies
242242
</a>

src/MobileContainer.tsx

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,53 @@
1-
import React, { Component } from 'react';
2-
import HomepageHeading from '#/HomepageHeading';
3-
import { Media } from '#/const';
1+
import { Component } from 'react';
2+
3+
import {
4+
blogListPathName,
5+
foundationPathName,
6+
homePathName,
7+
Media,
8+
} from '#/const';
49
import CustomRouter from '#/CustomRouter';
510
import { SemanticToastContainer, toast } from 'react-semantic-toasts';
611

712
import {
813
Button,
914
Container,
10-
Divider,
11-
Grid,
12-
Header,
1315
Icon,
14-
Image,
15-
List,
1616
Menu,
1717
Segment,
1818
Popup,
1919
Sidebar,
20+
MenuItemProps,
2021
} from 'semantic-ui-react';
2122
import { history } from '#/const';
2223
import { scrollToTopAndRoute } from '#/utils';
23-
import Homepage from '#/Homepage';
24-
import Blog from '#/Blog';
25-
import { Route } from 'react-router';
26-
import { Router, Routes } from 'react-router-dom';
2724

2825
interface IProps {}
2926

3027
interface IState {
28+
activeItem: string;
3129
sidebarOpened: boolean;
3230
}
3331

3432
class MobileContainer extends Component<IProps, IState> {
3533
static defaultProps = {};
3634

3735
state = {
36+
activeItem: homePathName,
3837
sidebarOpened: false,
3938
};
4039
handleSidebarHide = () => this.setState({ sidebarOpened: false });
4140

4241
handleToggle = () => this.setState({ sidebarOpened: true });
4342

4443
componentDidMount = async () => {
44+
let pathname = window.location.pathname;
45+
if (pathname.length > 1) {
46+
this.setState({
47+
activeItem: pathname,
48+
});
49+
}
50+
4551
setTimeout(() => {
4652
toast(
4753
{
@@ -57,6 +63,14 @@ class MobileContainer extends Component<IProps, IState> {
5763
}, 500);
5864
};
5965

66+
handleMenuItemClick = (
67+
event: React.MouseEvent<HTMLElement>,
68+
menuItemProps: MenuItemProps
69+
) => {
70+
this.setState({ activeItem: menuItemProps.name!, sidebarOpened: false });
71+
scrollToTopAndRoute(menuItemProps.name!);
72+
};
73+
6074
render() {
6175
const { children } = this.props;
6276
const { sidebarOpened } = this.state;
@@ -72,7 +86,11 @@ class MobileContainer extends Component<IProps, IState> {
7286
vertical
7387
visible={sidebarOpened}
7488
>
75-
<Menu.Item as="a" href="/" active>
89+
<Menu.Item
90+
as="a"
91+
href="/"
92+
active={this.state.activeItem === homePathName}
93+
>
7694
Home
7795
</Menu.Item>
7896
<Popup
@@ -81,6 +99,7 @@ class MobileContainer extends Component<IProps, IState> {
8199
as="a"
82100
href="https://archlinuxstudio.github.io/ArchLinuxTutorial/#/"
83101
target="_blank"
102+
active={this.state.activeItem === homePathName}
84103
>
85104
ALT
86105
</Menu.Item>
@@ -118,7 +137,11 @@ class MobileContainer extends Component<IProps, IState> {
118137
inverted
119138
on="hover"
120139
/>
121-
<Menu.Item onClick={() => scrollToTopAndRoute('/blog_list')}>
140+
<Menu.Item
141+
name={blogListPathName}
142+
onClick={this.handleMenuItemClick}
143+
active={this.state.activeItem === blogListPathName}
144+
>
122145
BLOG
123146
</Menu.Item>
124147
<Menu.Item as="a">Placeholder_hidden</Menu.Item>
@@ -136,24 +159,13 @@ class MobileContainer extends Component<IProps, IState> {
136159
<Menu.Item onClick={this.handleToggle}>
137160
<Icon name="sidebar" />
138161
</Menu.Item>
139-
<Menu.Item position="right">
140-
<Button
141-
as="a"
142-
href="https://en.cryptobadges.io/donate/1Lth3oca4WnMnTnwHBcDLkEqniA2pBxkeC"
143-
target="_blank"
144-
inverted
145-
>
146-
Donate BTC
147-
</Button>
148-
<Button
149-
as="a"
150-
href="https://en.cryptobadges.io/donate/0x5A218a8d570d9947f42e0a4916ece7a60A181c2d"
151-
target="_blank"
152-
inverted
153-
style={{ marginLeft: '0.5em' }}
154-
>
155-
Donate ETH
156-
</Button>
162+
<Menu.Item
163+
position="right"
164+
name={foundationPathName}
165+
onClick={this.handleMenuItemClick}
166+
active={this.state.activeItem === foundationPathName}
167+
>
168+
<Button inverted>ArchLinuxStudio Foundation</Button>
157169
</Menu.Item>
158170
</Menu>
159171
</Container>

src/const.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ export const { MediaContextProvider, Media } = createMedia({
1010
});
1111

1212
export const history = createBrowserHistory();
13+
14+
export const homePathName = '/home';
15+
export const blogListPathName = '/blog_list';
16+
export const foundationPathName = '/foundation';

src/react-app-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
/// <reference types="react-scripts" />
2+
3+
declare module '*.webm' {
4+
const src: string;
5+
export default src;
6+
}

src/videos/FSF_30_720p.webm

56 MB
Binary file not shown.

0 commit comments

Comments
 (0)