diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-02-27 01:52:55 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-03-06 18:56:47 +0100 |
commit | 098d6f9bb1fd26f2d192db497992ab95b258ce55 (patch) | |
tree | 22905f87e6ad53032b6ff39bb3af274df2f6287c /packages/renderer | |
parent | refactor: Shared model type factories (diff) | |
download | sophie-098d6f9bb1fd26f2d192db497992ab95b258ce55.tar.gz sophie-098d6f9bb1fd26f2d192db497992ab95b258ce55.tar.zst sophie-098d6f9bb1fd26f2d192db497992ab95b258ce55.zip |
feat: Location bar actions
The buttons and the text field in the location bar shall now affect the
BrowserView of the loaded service.
Some error handling is still needed, e.g., when loading a web page fails
due to a DNS error.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/renderer')
4 files changed, 79 insertions, 11 deletions
diff --git a/packages/renderer/src/components/locationBar/GoAdornment.tsx b/packages/renderer/src/components/locationBar/GoAdornment.tsx index 43c8b7b..f049b8e 100644 --- a/packages/renderer/src/components/locationBar/GoAdornment.tsx +++ b/packages/renderer/src/components/locationBar/GoAdornment.tsx | |||
@@ -20,11 +20,15 @@ | |||
20 | 20 | ||
21 | import IconGo from '@mui/icons-material/Send'; | 21 | import IconGo from '@mui/icons-material/Send'; |
22 | import Button from '@mui/material/Button'; | 22 | import Button from '@mui/material/Button'; |
23 | import React from 'react'; | 23 | import React, { MouseEventHandler } from 'react'; |
24 | 24 | ||
25 | import ButtonAdornment, { NO_LABEL_BUTTON_CLASS_NAME } from './ButtonAdornment'; | 25 | import ButtonAdornment, { NO_LABEL_BUTTON_CLASS_NAME } from './ButtonAdornment'; |
26 | 26 | ||
27 | export default function GoAdornment(): JSX.Element { | 27 | export default function GoAdornment({ |
28 | onClick, | ||
29 | }: { | ||
30 | onClick: MouseEventHandler<HTMLButtonElement>; | ||
31 | }): JSX.Element { | ||
28 | return ( | 32 | return ( |
29 | <ButtonAdornment position="end"> | 33 | <ButtonAdornment position="end"> |
30 | <Button | 34 | <Button |
@@ -32,6 +36,7 @@ export default function GoAdornment(): JSX.Element { | |||
32 | color="inherit" | 36 | color="inherit" |
33 | startIcon={<IconGo />} | 37 | startIcon={<IconGo />} |
34 | className={NO_LABEL_BUTTON_CLASS_NAME} | 38 | className={NO_LABEL_BUTTON_CLASS_NAME} |
39 | onClick={onClick} | ||
35 | /> | 40 | /> |
36 | </ButtonAdornment> | 41 | </ButtonAdornment> |
37 | ); | 42 | ); |
diff --git a/packages/renderer/src/components/locationBar/LocationTextField.tsx b/packages/renderer/src/components/locationBar/LocationTextField.tsx index e6da59f..e711abc 100644 --- a/packages/renderer/src/components/locationBar/LocationTextField.tsx +++ b/packages/renderer/src/components/locationBar/LocationTextField.tsx | |||
@@ -94,9 +94,18 @@ function LocationTextField({ | |||
94 | setChanged(true); | 94 | setChanged(true); |
95 | }} | 95 | }} |
96 | onKeyUp={(event) => { | 96 | onKeyUp={(event) => { |
97 | if (event.key === 'Escape') { | 97 | switch (event.key) { |
98 | resetValue(); | 98 | case 'Escape': |
99 | event.preventDefault(); | 99 | resetValue(); |
100 | event.preventDefault(); | ||
101 | break; | ||
102 | case 'Enter': | ||
103 | service?.go(value); | ||
104 | event.preventDefault(); | ||
105 | break; | ||
106 | default: | ||
107 | // Nothing to do, let the key event through. | ||
108 | break; | ||
100 | } | 109 | } |
101 | }} | 110 | }} |
102 | size="small" | 111 | size="small" |
@@ -106,7 +115,9 @@ function LocationTextField({ | |||
106 | startAdornment={ | 115 | startAdornment={ |
107 | <UrlAdornment changed={changed} splitResult={splitResult} /> | 116 | <UrlAdornment changed={changed} splitResult={splitResult} /> |
108 | } | 117 | } |
109 | endAdornment={changed ? <GoAdornment /> : undefined} | 118 | endAdornment={ |
119 | changed ? <GoAdornment onClick={() => service?.go(value)} /> : undefined | ||
120 | } | ||
110 | value={value} | 121 | value={value} |
111 | /> | 122 | /> |
112 | ); | 123 | ); |
diff --git a/packages/renderer/src/components/locationBar/NavigationButtons.tsx b/packages/renderer/src/components/locationBar/NavigationButtons.tsx index ce59692..e71d3d8 100644 --- a/packages/renderer/src/components/locationBar/NavigationButtons.tsx +++ b/packages/renderer/src/components/locationBar/NavigationButtons.tsx | |||
@@ -48,25 +48,35 @@ function NavigationButtons({ | |||
48 | <IconButton | 48 | <IconButton |
49 | aria-label="Back" | 49 | aria-label="Back" |
50 | disabled={service === undefined || !service.canGoBack} | 50 | disabled={service === undefined || !service.canGoBack} |
51 | onClick={() => service?.goBack()} | ||
51 | > | 52 | > |
52 | {direction === 'ltr' ? <IconArrowBack /> : <IconArrowForward />} | 53 | {direction === 'ltr' ? <IconArrowBack /> : <IconArrowForward />} |
53 | </IconButton> | 54 | </IconButton> |
54 | <IconButton | 55 | <IconButton |
55 | aria-label="Forward" | 56 | aria-label="Forward" |
56 | disabled={service === undefined || !service.canGoForward} | 57 | disabled={service === undefined || !service.canGoForward} |
58 | onClick={() => service?.goForward()} | ||
57 | > | 59 | > |
58 | {direction === 'ltr' ? <IconArrowForward /> : <IconArrowBack />} | 60 | {direction === 'ltr' ? <IconArrowForward /> : <IconArrowBack />} |
59 | </IconButton> | 61 | </IconButton> |
60 | {service?.state === 'loading' ? ( | 62 | {service?.state === 'loading' ? ( |
61 | <IconButton aria-label="Stop"> | 63 | <IconButton aria-label="Stop" onClick={() => service?.stop()}> |
62 | <IconStop /> | 64 | <IconStop /> |
63 | </IconButton> | 65 | </IconButton> |
64 | ) : ( | 66 | ) : ( |
65 | <IconButton aria-label="Refresh" disabled={service === undefined}> | 67 | <IconButton |
68 | aria-label="Refresh" | ||
69 | disabled={service === undefined} | ||
70 | onClick={(event) => service?.reload(event.shiftKey)} | ||
71 | > | ||
66 | <IconRefresh /> | 72 | <IconRefresh /> |
67 | </IconButton> | 73 | </IconButton> |
68 | )} | 74 | )} |
69 | <IconButton aria-label="Home" disabled={service === undefined}> | 75 | <IconButton |
76 | aria-label="Home" | ||
77 | disabled={service === undefined} | ||
78 | onClick={() => service?.goHome()} | ||
79 | > | ||
70 | <IconHome /> | 80 | <IconHome /> |
71 | </IconButton> | 81 | </IconButton> |
72 | </Box> | 82 | </Box> |
diff --git a/packages/renderer/src/stores/Service.ts b/packages/renderer/src/stores/Service.ts index c2c938a..7878ea0 100644 --- a/packages/renderer/src/stores/Service.ts +++ b/packages/renderer/src/stores/Service.ts | |||
@@ -18,12 +18,54 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { defineServiceModel } from '@sophie/shared'; | 21 | import { defineServiceModel, ServiceAction } from '@sophie/shared'; |
22 | import { Instance } from 'mobx-state-tree'; | 22 | import { Instance } from 'mobx-state-tree'; |
23 | 23 | ||
24 | import getEnv from '../env/getEnv'; | ||
25 | |||
24 | import ServiceSettings from './ServiceSettings'; | 26 | import ServiceSettings from './ServiceSettings'; |
25 | 27 | ||
26 | const Service = defineServiceModel(ServiceSettings); | 28 | const Service = defineServiceModel(ServiceSettings).actions((self) => ({ |
29 | dispatch(serviceAction: ServiceAction): void { | ||
30 | getEnv(self).dispatchMainAction({ | ||
31 | action: 'dispatch-service-action', | ||
32 | serviceId: self.id, | ||
33 | serviceAction, | ||
34 | }); | ||
35 | }, | ||
36 | goBack(): void { | ||
37 | this.dispatch({ | ||
38 | action: 'back', | ||
39 | }); | ||
40 | }, | ||
41 | goForward(): void { | ||
42 | this.dispatch({ | ||
43 | action: 'forward', | ||
44 | }); | ||
45 | }, | ||
46 | reload(ignoreCache = false): void { | ||
47 | this.dispatch({ | ||
48 | action: 'reload', | ||
49 | ignoreCache, | ||
50 | }); | ||
51 | }, | ||
52 | stop(): void { | ||
53 | this.dispatch({ | ||
54 | action: 'stop', | ||
55 | }); | ||
56 | }, | ||
57 | go(url: string): void { | ||
58 | this.dispatch({ | ||
59 | action: 'go', | ||
60 | url, | ||
61 | }); | ||
62 | }, | ||
63 | goHome(): void { | ||
64 | this.dispatch({ | ||
65 | action: 'go-home', | ||
66 | }); | ||
67 | }, | ||
68 | })); | ||
27 | 69 | ||
28 | /* | 70 | /* |
29 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 71 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |