Skip to content

Commit dda42dc

Browse files
author
Tomasz Opalach
committed
[client] fix navigation-related errors
1 parent 0d613cb commit dda42dc

File tree

9 files changed

+78
-20
lines changed

9 files changed

+78
-20
lines changed

DemoServer/client/src/components/demoDisplay/sidebar/Controls.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from "react";
22
import { IconLeft, IconCollapse, IconExpand } from "../../helpers/icons";
3-
import { Dispatch } from "redux";
43
import { connect } from "react-redux";
54
import { goToMainPage } from "../../../store/actions/navigation";
5+
import { DemoThunkDispatch } from "../../../store";
66

77
interface DispatchProps {
88
goToMainPage: () => void;
@@ -28,7 +28,7 @@ function ControlsComponent(props: Props) {
2828
</div>;
2929
}
3030

31-
function mapDispatchToProps(dispatch: Dispatch): DispatchProps {
31+
function mapDispatchToProps(dispatch: DemoThunkDispatch): DispatchProps {
3232
return {
3333
goToMainPage: () => dispatch(goToMainPage())
3434
};

DemoServer/client/src/components/demoDisplay/sidebar/Heading.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from "react";
22
import { connect } from "react-redux";
33
import { AppState } from "../../../store/state";
4-
import { Dispatch } from "redux";
54
import { IconLeft } from "../../helpers/icons";
65
import { goToMainPage } from "../../../store/actions/navigation";
6+
import { DemoThunkDispatch } from "../../../store";
77

88
interface StateProps {
99
title: string;
@@ -34,7 +34,7 @@ function mapStateToProps({ demos }: AppState): StateProps {
3434
};
3535
}
3636

37-
function mapDispatchToProps(dispatch: Dispatch): DispatchProps {
37+
function mapDispatchToProps(dispatch: DemoThunkDispatch): DispatchProps {
3838
return {
3939
goToMainPage: () => dispatch(goToMainPage())
4040
};

DemoServer/client/src/components/home/DemoItem.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import * as React from "react";
22
import * as classNames from "classnames";
33
import { DemoWithProgress } from "../../models/demo";
44
import { connect } from "react-redux";
5-
import { Dispatch } from "redux";
65
import { goToDemoPage } from "../../store/actions/navigation";
6+
import { CategorySlug } from "../../models/slugs";
7+
import { DemoThunkDispatch } from "../../store";
78

89
interface DispatchProps {
910
goToDemoPage: () => void;
1011
}
1112

1213
interface OwnProps {
13-
category: string;
14+
category: CategorySlug;
1415
demo: DemoWithProgress;
1516
}
1617

@@ -29,7 +30,7 @@ function DemoItemComponent(props: Props) {
2930
</a>;
3031
}
3132

32-
function mapDispatchToProps(dispatch: Dispatch, ownProps: OwnProps): DispatchProps {
33+
function mapDispatchToProps(dispatch: DemoThunkDispatch, ownProps: OwnProps): DispatchProps {
3334
const { demo, category } = ownProps;
3435

3536
return {

DemoServer/client/src/components/layout/header/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import * as React from "react";
22
import * as bsn from "bootstrap.native/dist/bootstrap-native-v4";
33
import { SelectDemoDropdown } from "./SelectDemoDropdown";
44
import { connect } from "react-redux";
5-
import { Dispatch } from "redux";
65
import { goToMainPage } from "../../../store/actions/navigation";
76
import { AppState } from "../../../store/state";
87
import { selectIsOnMainPage } from "../../../store/selectors/router";
98
import { SettingsMenu } from "./settings/SettingsMenu";
9+
import { DemoThunkDispatch } from "../../../store";
1010

1111
interface StateProps {
1212
isOnMainPage: boolean;
@@ -57,7 +57,7 @@ function mapStateToProps({ router }: AppState): StateProps {
5757
return { isOnMainPage };
5858
}
5959

60-
function mapDispatchToProps(dispatch: Dispatch): DispatchProps {
60+
function mapDispatchToProps(dispatch: DemoThunkDispatch): DispatchProps {
6161
return {
6262
goToMainPage: () => dispatch(goToMainPage())
6363
};

DemoServer/client/src/models/demo.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { DemoParamsDto } from "./dtos/params";
2+
import { DemoSlug, CategorySlug } from "./slugs";
23

34
export interface Demo {
4-
slug: string;
5+
slug: DemoSlug;
56
title: string;
67
}
78

@@ -10,7 +11,7 @@ export interface DemoWithProgress extends Demo {
1011
}
1112

1213
export interface DemoCategory {
13-
slug: string;
14+
slug: CategorySlug;
1415
demos: DemoWithProgress[];
1516
}
1617

DemoServer/client/src/store/actions/actionTypes.ts

+3
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ export type SETTINGS_RESET_PROGRESS_DIALOG_SHOW = "SETTINGS_RESET_PROGRESS_DIALO
3838
export type SETTINGS_RESET_PROGRESS_DIALOG_CLOSE = "SETTINGS_RESET_PROGRESS_DIALOG_CLOSE";
3939

4040
export type SETTINGS_CLEAR_PROGRESS = "SETTINGS_CLEAR_PROGRESS";
41+
42+
export type NAVIGATION_WENT_TO_MAIN_PAGE = "NAVIGATION_WENT_TO_MAIN_PAGE";
43+
export type NAVIGATION_WENT_TO_DEMO_PAGE = "NAVIGATION_WENT_TO_DEMO_PAGE";

DemoServer/client/src/store/actions/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { DemoAction } from "./demo";
55
import { ParametersAction } from "./parameters";
66
import { CallHistoryMethodAction } from "connected-react-router";
77
import { SettingsAction } from "./settings";
8+
import { NavigationAction } from "./navigation";
9+
10+
export type Action = ErrorAction
11+
| DemoAction | ParametersAction | SettingsAction
12+
| NavigationAction | CallHistoryMethodAction;
813

9-
export type Action = ErrorAction | DemoAction | ParametersAction | SettingsAction | CallHistoryMethodAction;
1014
export type DemoThunkAction = ThunkAction<void, AppState, null, Action>;

DemoServer/client/src/store/actions/navigation.ts

+40-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,49 @@
11
import { push } from "connected-react-router";
2+
import * as actionTypes from "./actionTypes";
23
import { createDemoWithWalkthroughPath } from "../../utils/paths";
34
import { DemoSlug, CategorySlug } from "../../models/slugs";
5+
import { DemoThunkAction } from ".";
6+
import { DemoThunkDispatch } from "..";
47

5-
export const goToMainPage = () => push("/");
8+
interface WentToMainPage {
9+
type: actionTypes.NAVIGATION_WENT_TO_MAIN_PAGE;
10+
}
11+
12+
interface WentToDemoPage {
13+
type: actionTypes.NAVIGATION_WENT_TO_DEMO_PAGE;
14+
category: string;
15+
demo: string;
16+
}
17+
18+
export type NavigationAction = WentToMainPage | WentToDemoPage;
619

7-
export function goToDemoPage(category: string, demo: string) {
8-
const url = createDemoWithWalkthroughPath({
9-
category: category as CategorySlug,
10-
demo: demo as DemoSlug
11-
});
20+
const wentToMainPage = (): WentToMainPage => ({
21+
type: "NAVIGATION_WENT_TO_MAIN_PAGE"
22+
});
23+
24+
const wentToDemoPage = (category: CategorySlug, demo: DemoSlug): WentToDemoPage => ({
25+
type: "NAVIGATION_WENT_TO_DEMO_PAGE",
26+
category,
27+
demo
28+
});
29+
30+
export function goToMainPage(): DemoThunkAction {
31+
return (dispatch: DemoThunkDispatch) => {
32+
dispatch(push("/"));
33+
dispatch(wentToMainPage());
34+
};
35+
}
1236

13-
return push(url);
37+
export function goToDemoPage(category: CategorySlug, demo: DemoSlug): DemoThunkAction {
38+
return (dispatch: DemoThunkDispatch) => {
39+
const url = createDemoWithWalkthroughPath({
40+
category,
41+
demo
42+
});
43+
44+
dispatch(push(url));
45+
dispatch(wentToDemoPage(category, demo));
46+
};
1447
}
1548

1649
export function goToDemoAssetPage(url: string) {

DemoServer/client/src/store/reducers/demo.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DemoEntry, WalkthroughEntry } from "../state/models";
77
import { Progress } from "../../utils/localStorage/Progress";
88
import { selectIsLastWalkthroughActive } from "../selectors/walkthroughs";
99
import { selectDemoVersionInfo } from "../selectors/demos";
10+
import { NavigationAction } from "../actions/navigation";
1011

1112
const initialState: DemoState = {
1213
language: "csharp",
@@ -56,7 +57,9 @@ const updateWalkthroughAndProgress = (state: DemoState) => {
5657
}
5758
};
5859

59-
export function demoReducer(state: DemoState = initialState, action: DemoAction | LocationChangeAction): DemoState {
60+
export function demoReducer(state: DemoState = initialState,
61+
action: DemoAction | LocationChangeAction | NavigationAction
62+
): DemoState {
6063
switch (action.type) {
6164
case "DEMO_GET_CONTEXT_REQUEST":
6265
return modifyState(state, s => {
@@ -141,6 +144,19 @@ export function demoReducer(state: DemoState = initialState, action: DemoAction
141144
return modifyState(state, s => {
142145
s.showShareMessage = action.show;
143146
});
147+
148+
case "NAVIGATION_WENT_TO_MAIN_PAGE":
149+
return modifyState(state, s => {
150+
s.demo = null;
151+
s.showResultsPanel = false;
152+
s.runResults = null;
153+
});
154+
155+
case "NAVIGATION_WENT_TO_DEMO_PAGE":
156+
return modifyState(state, s => {
157+
s.showResultsPanel = false;
158+
s.runResults = null;
159+
});
144160
}
145161

146162
return state;

0 commit comments

Comments
 (0)