aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-16 01:09:27 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-24 00:53:06 +0100
commit39231032ef9abfc3a90af7bf0460037aa220ce11 (patch)
tree0159913431d04689c5a988eb4d69e001486d9bac /packages/renderer
parentchore(deps): Bump dependencies (diff)
downloadsophie-39231032ef9abfc3a90af7bf0460037aa220ce11.tar.gz
sophie-39231032ef9abfc3a90af7bf0460037aa220ce11.tar.zst
sophie-39231032ef9abfc3a90af7bf0460037aa220ce11.zip
feat: Basic location bar
Still needs adding event handlers to actually navigate the browser. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/renderer')
-rw-r--r--packages/renderer/src/components/App.tsx16
-rw-r--r--packages/renderer/src/components/locationBar/LocationBar.tsx54
-rw-r--r--packages/renderer/src/components/locationBar/LocationTextField.tsx59
-rw-r--r--packages/renderer/src/components/locationBar/NavigationButtons.tsx75
-rw-r--r--packages/renderer/src/components/sidebar/ServiceIcon.tsx (renamed from packages/renderer/src/components/ServiceIcon.tsx)0
-rw-r--r--packages/renderer/src/components/sidebar/ServiceSwitcher.tsx (renamed from packages/renderer/src/components/ServiceSwitcher.tsx)3
-rw-r--r--packages/renderer/src/components/sidebar/Sidebar.tsx (renamed from packages/renderer/src/components/Sidebar.tsx)14
-rw-r--r--packages/renderer/src/components/sidebar/ToggleDarkModeButton.tsx (renamed from packages/renderer/src/components/ToggleDarkModeButton.tsx)2
-rw-r--r--packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx55
-rw-r--r--packages/renderer/src/stores/RendererStore.ts9
10 files changed, 280 insertions, 7 deletions
diff --git a/packages/renderer/src/components/App.tsx b/packages/renderer/src/components/App.tsx
index 1174bbb..cf97074 100644
--- a/packages/renderer/src/components/App.tsx
+++ b/packages/renderer/src/components/App.tsx
@@ -22,7 +22,8 @@ import Box from '@mui/material/Box';
22import React from 'react'; 22import React from 'react';
23 23
24import BrowserViewPlaceholder from './BrowserViewPlaceholder'; 24import BrowserViewPlaceholder from './BrowserViewPlaceholder';
25import Sidebar from './Sidebar'; 25import LocationBar from './locationBar/LocationBar';
26import Sidebar from './sidebar/Sidebar';
26 27
27export default function App(): JSX.Element { 28export default function App(): JSX.Element {
28 return ( 29 return (
@@ -36,7 +37,18 @@ export default function App(): JSX.Element {
36 }} 37 }}
37 > 38 >
38 <Sidebar /> 39 <Sidebar />
39 <BrowserViewPlaceholder /> 40 <Box
41 sx={{
42 flex: 1,
43 display: 'flex',
44 flexDirection: 'column',
45 alignItems: 'stretch',
46 height: '100%',
47 }}
48 >
49 <LocationBar />
50 <BrowserViewPlaceholder />
51 </Box>
40 </Box> 52 </Box>
41 ); 53 );
42} 54}
diff --git a/packages/renderer/src/components/locationBar/LocationBar.tsx b/packages/renderer/src/components/locationBar/LocationBar.tsx
new file mode 100644
index 0000000..e1f470d
--- /dev/null
+++ b/packages/renderer/src/components/locationBar/LocationBar.tsx
@@ -0,0 +1,54 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import { styled } from '@mui/material/styles';
22import { observer } from 'mobx-react-lite';
23import React from 'react';
24
25import { useStore } from '../StoreProvider';
26
27import LocationTextField from './LocationTextField';
28import NavigationButtons from './NavigationButtons';
29
30const LocationBarRoot = styled('header', {
31 name: 'LocationBar',
32 slot: 'Root',
33})(({ theme, hidden }) => ({
34 display: hidden ? 'none' : 'flex',
35 flexDirection: 'row',
36 padding: theme.spacing(1),
37 gap: theme.spacing(1),
38 borderBottom: `1px solid ${theme.palette.divider}`,
39}));
40
41function LocationBar(): JSX.Element {
42 const {
43 settings: { selectedService, showLocationBar },
44 } = useStore();
45
46 return (
47 <LocationBarRoot id="locationBar" hidden={!showLocationBar}>
48 <NavigationButtons service={selectedService} />
49 <LocationTextField service={selectedService} />
50 </LocationBarRoot>
51 );
52}
53
54export default observer(LocationBar);
diff --git a/packages/renderer/src/components/locationBar/LocationTextField.tsx b/packages/renderer/src/components/locationBar/LocationTextField.tsx
new file mode 100644
index 0000000..a618bf6
--- /dev/null
+++ b/packages/renderer/src/components/locationBar/LocationTextField.tsx
@@ -0,0 +1,59 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import IconGlobe from '@mui/icons-material/Public';
22import FilledInput from '@mui/material/FilledInput';
23import InputAdornment from '@mui/material/InputAdornment';
24import { Service } from '@sophie/shared';
25import { observer } from 'mobx-react-lite';
26import React from 'react';
27
28function LocationTextField({
29 service,
30}: {
31 service: Service | undefined;
32}): JSX.Element {
33 return (
34 <FilledInput
35 aria-label="Location"
36 inputProps={{
37 spellCheck: false,
38 }}
39 size="small"
40 fullWidth
41 hiddenLabel
42 disableUnderline
43 sx={(theme) => ({
44 borderRadius: 1,
45 '&.Mui-focused': {
46 outline: `2px solid ${theme.palette.primary.main}`,
47 },
48 })}
49 startAdornment={
50 <InputAdornment position="start">
51 <IconGlobe fontSize="small" />
52 </InputAdornment>
53 }
54 value={service?.currentUrl ?? ''}
55 />
56 );
57}
58
59export default observer(LocationTextField);
diff --git a/packages/renderer/src/components/locationBar/NavigationButtons.tsx b/packages/renderer/src/components/locationBar/NavigationButtons.tsx
new file mode 100644
index 0000000..82ed657
--- /dev/null
+++ b/packages/renderer/src/components/locationBar/NavigationButtons.tsx
@@ -0,0 +1,75 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import IconArrowBack from '@mui/icons-material/ArrowBack';
22import IconArrowForward from '@mui/icons-material/ArrowForward';
23import IconStop from '@mui/icons-material/Close';
24import IconHome from '@mui/icons-material/HomeOutlined';
25import IconRefresh from '@mui/icons-material/Refresh';
26import Box from '@mui/material/Box';
27import IconButton from '@mui/material/IconButton';
28import { Service } from '@sophie/shared';
29import { observer } from 'mobx-react-lite';
30import React from 'react';
31
32function NavigationButtons({
33 service,
34}: {
35 service: Service | undefined;
36}): JSX.Element {
37 return (
38 <Box
39 sx={{
40 display: 'flex',
41 flexDirection: 'row',
42 }}
43 >
44 <IconButton
45 aria-label="Go back"
46 disabled={service === undefined || !service.canGoBack}
47 >
48 <IconArrowBack />
49 </IconButton>
50 <IconButton
51 aria-label="Go forward"
52 disabled={service === undefined || !service.canGoForward}
53 >
54 <IconArrowForward />
55 </IconButton>
56 {service?.state === 'loading' ? (
57 <IconButton aria-label="Stop">
58 <IconStop />
59 </IconButton>
60 ) : (
61 <IconButton aria-label="Refresh" disabled={service === undefined}>
62 <IconRefresh />
63 </IconButton>
64 )}
65 <IconButton
66 aria-label="Go to service homepage"
67 disabled={service === undefined}
68 >
69 <IconHome />
70 </IconButton>
71 </Box>
72 );
73}
74
75export default observer(NavigationButtons);
diff --git a/packages/renderer/src/components/ServiceIcon.tsx b/packages/renderer/src/components/sidebar/ServiceIcon.tsx
index 83b2a5f..83b2a5f 100644
--- a/packages/renderer/src/components/ServiceIcon.tsx
+++ b/packages/renderer/src/components/sidebar/ServiceIcon.tsx
diff --git a/packages/renderer/src/components/ServiceSwitcher.tsx b/packages/renderer/src/components/sidebar/ServiceSwitcher.tsx
index 2cf997e..3b47990 100644
--- a/packages/renderer/src/components/ServiceSwitcher.tsx
+++ b/packages/renderer/src/components/sidebar/ServiceSwitcher.tsx
@@ -24,8 +24,9 @@ import { alpha, styled } from '@mui/material/styles';
24import { observer } from 'mobx-react-lite'; 24import { observer } from 'mobx-react-lite';
25import React from 'react'; 25import React from 'react';
26 26
27import { useStore } from '../StoreProvider';
28
27import ServiceIcon from './ServiceIcon'; 29import ServiceIcon from './ServiceIcon';
28import { useStore } from './StoreProvider';
29 30
30const ServiceSwitcherRoot = styled(Tabs, { 31const ServiceSwitcherRoot = styled(Tabs, {
31 name: 'ServiceSwitcher', 32 name: 'ServiceSwitcher',
diff --git a/packages/renderer/src/components/Sidebar.tsx b/packages/renderer/src/components/sidebar/Sidebar.tsx
index 0eb8f93..80826ca 100644
--- a/packages/renderer/src/components/Sidebar.tsx
+++ b/packages/renderer/src/components/sidebar/Sidebar.tsx
@@ -24,6 +24,7 @@ import React from 'react';
24 24
25import ServiceSwitcher from './ServiceSwitcher'; 25import ServiceSwitcher from './ServiceSwitcher';
26import ToggleDarkModeButton from './ToggleDarkModeButton'; 26import ToggleDarkModeButton from './ToggleDarkModeButton';
27import ToggleLocationBarButton from './ToggleLocationBarButton';
27 28
28export default function Sidebar(): JSX.Element { 29export default function Sidebar(): JSX.Element {
29 return ( 30 return (
@@ -34,15 +35,22 @@ export default function Sidebar(): JSX.Element {
34 display: 'flex', 35 display: 'flex',
35 flexDirection: 'column', 36 flexDirection: 'column',
36 alignItems: 'center', 37 alignItems: 'center',
37 justifyContent: 'space-between', 38 paddingY: 1,
38 paddingBottom: 1, 39 gap: 1,
39 backgroundClip: 'padding-box',
40 background: alpha(theme.palette.text.primary, 0.09), 40 background: alpha(theme.palette.text.primary, 0.09),
41 backgroundClip: 'padding-box',
41 borderInlineEnd: `1px solid ${theme.palette.divider}`, 42 borderInlineEnd: `1px solid ${theme.palette.divider}`,
42 minWidth: 69, 43 minWidth: 69,
43 })} 44 })}
44 > 45 >
46 <ToggleLocationBarButton />
45 <ServiceSwitcher /> 47 <ServiceSwitcher />
48 <Box
49 sx={{
50 flex: 1,
51 WebkitAppRegion: 'drag',
52 }}
53 />
46 <ToggleDarkModeButton /> 54 <ToggleDarkModeButton />
47 </Box> 55 </Box>
48 ); 56 );
diff --git a/packages/renderer/src/components/ToggleDarkModeButton.tsx b/packages/renderer/src/components/sidebar/ToggleDarkModeButton.tsx
index 695756a..164b066 100644
--- a/packages/renderer/src/components/ToggleDarkModeButton.tsx
+++ b/packages/renderer/src/components/sidebar/ToggleDarkModeButton.tsx
@@ -24,7 +24,7 @@ import IconButton from '@mui/material/IconButton';
24import { observer } from 'mobx-react-lite'; 24import { observer } from 'mobx-react-lite';
25import React from 'react'; 25import React from 'react';
26 26
27import { useStore } from './StoreProvider'; 27import { useStore } from '../StoreProvider';
28 28
29export default observer(() => { 29export default observer(() => {
30 const store = useStore(); 30 const store = useStore();
diff --git a/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx b/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
new file mode 100644
index 0000000..7e20598
--- /dev/null
+++ b/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
@@ -0,0 +1,55 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import IconChevronLeft from '@mui/icons-material/KeyboardDoubleArrowLeft';
22import IconChevronRight from '@mui/icons-material/KeyboardDoubleArrowRight';
23import CircularProgress from '@mui/material/CircularProgress';
24import IconButton from '@mui/material/IconButton';
25import { observer } from 'mobx-react-lite';
26import React from 'react';
27
28import { useStore } from '../StoreProvider';
29
30function ToggleLocationBarButton(): JSX.Element {
31 const store = useStore();
32 const {
33 settings: { selectedService, showLocationBar },
34 } = store;
35
36 let icon: JSX.Element;
37 if (selectedService?.state === 'loading') {
38 icon = <CircularProgress color="inherit" size="1.5rem" />;
39 } else {
40 icon = showLocationBar ? <IconChevronLeft /> : <IconChevronRight />;
41 }
42
43 return (
44 <IconButton
45 aria-pressed={showLocationBar}
46 aria-controls="locationBar"
47 aria-label="Show location bar"
48 onClick={() => store.toggleLocationBar()}
49 >
50 {icon}
51 </IconButton>
52 );
53}
54
55export default observer(ToggleLocationBarButton);
diff --git a/packages/renderer/src/stores/RendererStore.ts b/packages/renderer/src/stores/RendererStore.ts
index 4d85929..1acc605 100644
--- a/packages/renderer/src/stores/RendererStore.ts
+++ b/packages/renderer/src/stores/RendererStore.ts
@@ -72,6 +72,15 @@ const RendererStore = types
72 this.setThemeSource('dark'); 72 this.setThemeSource('dark');
73 } 73 }
74 }, 74 },
75 setShowLocationBar(showLocationBar: boolean): void {
76 getEnv(self).dispatchMainAction({
77 action: 'set-show-location-bar',
78 showLocationBar,
79 });
80 },
81 toggleLocationBar(): void {
82 this.setShowLocationBar(!self.settings.showLocationBar);
83 },
75 })); 84 }));
76 85
77/* 86/*