Skip to content

Commit

Permalink
feat: added settings page for access key and access secret
Browse files Browse the repository at this point in the history
  • Loading branch information
wwills2 committed Jan 23, 2024
1 parent 615ee7b commit 1552051
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 10 deletions.
18 changes: 17 additions & 1 deletion src/renderer/components/blocks/layout/LeftNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
HiOutlineArrowLeft,
HiOutlineArrowRight,
HiChartPie,
HiGlobeAlt
HiGlobeAlt,
} from 'react-icons/hi';
import { IoSettingsOutline } from 'react-icons/io5';
import styled from 'styled-components';
import { useLocation } from 'react-router-dom';
import { useState } from 'react';
Expand Down Expand Up @@ -67,6 +68,14 @@ const LeftNav = () => {
>
<FormattedMessage id="browser"/>
</Sidebar.Item>
<Sidebar.Item
style={{ cursor: 'pointer' }}
active={isActive(ROUTES.SETTINGS)}
onClick={() => navigate(ROUTES.SETTINGS)}
icon={IoSettingsOutline}
>
<FormattedMessage id="settings"/>
</Sidebar.Item>
<Sidebar.Item
style={{ cursor: 'pointer' }}
active={isActive(ROUTES.APP_DEFAULT)}
Expand Down Expand Up @@ -121,6 +130,13 @@ const LeftNav = () => {
>
<HiGlobeAlt />
</Sidebar.Item>
<Sidebar.Item
style={{ cursor: 'pointer' }}
active={isActive(ROUTES.SETTINGS)}
onClick={() => navigate(ROUTES.SETTINGS)}
>
<IoSettingsOutline />
</Sidebar.Item>
<Sidebar.Item
style={{ cursor: 'pointer' }}
active={isActive(ROUTES.APP_DEFAULT)}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/pages/Browser/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const ForwardButton: React.FC<NavButton> = ({onClick}) => {
const HomeButton: React.FC<NavButton> = ({onClick}) => {
return (
<StyledNavButton onClick={onClick} color={navButtonColor}>
<HiHome font-size={navButtonIconSize}/>
<HiHome fontSize={navButtonIconSize}/>
</StyledNavButton>
);
}
Expand Down
93 changes: 93 additions & 0 deletions src/renderer/pages/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Button, TextInput } from "flowbite-react";
import styled from "styled-components";
import { FormattedMessage } from "react-intl";
import {useCallback, useEffect, useRef} from "react";
import {useDispatch, useSelector} from "react-redux";
import {
getAccessKey,
getAccessSecret,
setAccessKey,
setAccessSecret
} from "@/store/slices/userOptions";

const SettingsDiv = styled('div')`
height: 100%;
width: 100%;
padding: 10px;
display: flex;
justify-content: center;
`;

interface SettingsProps {

}

interface AccessSettingsProps {

}

const AccessSettings: React.FC<AccessSettingsProps> = () => {

const dispatch = useDispatch();
const accessKeyTextInput = useRef<HTMLInputElement>(null);
const accessSecretTextInput = useRef<HTMLInputElement>(null);
const accessKey = useSelector((state: any) => getAccessKey(state));
const accessSecret = useSelector((state: any) => getAccessSecret(state));

useEffect(() => {
if (accessKeyTextInput.current && accessSecretTextInput.current) {
accessKeyTextInput.current.value = accessKey;
accessSecretTextInput.current.value = accessSecret;
}
}, [accessKeyTextInput, accessSecretTextInput, accessSecret, accessKey]);

const onSave = useCallback(() => {
if (accessKeyTextInput.current && accessSecretTextInput.current) {
if (accessKeyTextInput.current.value != '' && accessSecretTextInput.current.value != '') {
dispatch(setAccessKey(accessKeyTextInput.current.value as string));
dispatch(setAccessSecret(accessSecretTextInput.current.value as string));
}
}
}, [dispatch]);

return (
<>
<div>
<div className="mb-2 block">
<FormattedMessage id="access-key"/>
</div>
<TextInput
id="acessKey"
type="text"
ref={accessKeyTextInput}
required/>
</div>
<div>
<div className="mb-2 block">
<FormattedMessage id="access-secret"/>
</div>
<TextInput
id="accessSecret"
type="text"
ref={accessSecretTextInput}
required/>
</div>
<div style={{height: "20px"}}/>
<Button type="submit" onClick={onSave} style={{width: "100%"}}>
<FormattedMessage id="save"/>
</Button>
</>
);
}

const Settings: React.FC<SettingsProps> = () => {
return (
<SettingsDiv>
<div style={{width: "448px"}}>
<AccessSettings/>
</div>
</SettingsDiv>
);
}

export {Settings};
1 change: 1 addition & 0 deletions src/renderer/pages/Settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Settings';
3 changes: 2 additions & 1 deletion src/renderer/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './AppDefault';
export * from './Hello1';
export * from './Hello2';
export * from './Browser'
export * from './Browser';
export * from './Settings';
export * from './Error';
6 changes: 5 additions & 1 deletion src/renderer/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const AppNavigator: React.FC = () => {
<Route
path={ROUTES.BROWSER}
element={<Pages.Browser/>}
/>
/>
<Route
path={ROUTES.SETTINGS}
element={<Pages.Settings/>}
/>
<Route
path={ROUTES.APP_DEFAULT}
element={<Pages.AppDefault />}
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/routes/route-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export default {
APP_DEFAULT: '/AppDefault',
HELLO_1: '/Hello1',
HELLO_2: '/Hello2',
BROWSER: '/Browser'
BROWSER: '/Browser',
SETTINGS: '/Settings',
};
3 changes: 2 additions & 1 deletion src/renderer/store/slices/userOptions/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './userOptions.slice';
export * from './userOptions.slice';
export * from './userOptions.view';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
selectedTheme: 'light'
selectedTheme: 'light',
accessKey: '',
accessSecret: '',
};
20 changes: 19 additions & 1 deletion src/renderer/store/slices/userOptions/userOptions.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,30 @@ export const userOptionsSlice = createSlice({
} else {
state.selectedTheme = 'light';
}
},

setAccessKey: (state, { payload }) => {

if ((typeof payload === 'string') && payload) {
state.accessKey = payload;
}else{
console.error("invalid access key. key must be a string and must not be null");
}
},

setAccessSecret: (state, { payload }) => {

if ((typeof payload === 'string') && payload) {
state.accessSecret = payload;
}else{
console.error("invalid access secret. secret must be a string and must not be null");
}
}
},
});

export const {
toggleTheme,
toggleTheme,setAccessKey, setAccessSecret
} = userOptionsSlice.actions;

export default userOptionsSlice.reducer;
7 changes: 7 additions & 0 deletions src/renderer/store/slices/userOptions/userOptions.view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getAccessKey = (state) => {
return state.userOptions.accessKey;
}

export const getAccessSecret = (state) => {
return state.userOptions.accessSecret;
}
7 changes: 5 additions & 2 deletions src/renderer/translations/tokens/en-US.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{

"app-default": "App Default",
"hello-1": "Hello 1",
"hello-2": "Hello 2",
"browser": "Browser"
"browser": "Browser",
"settings": "Settings",
"access-key": "Access Key",
"access-secret": "Access Secret",
"save": "Save"
}

0 comments on commit 1552051

Please sign in to comment.