Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ControlBar): implement redesigned control bar #165

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
143 changes: 89 additions & 54 deletions src/components/ControlBar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { Button, Space } from 'antd';
import styled from 'styled-components';
import { type ModelSave } from '../services/model/modelService';
import { useEffect, useRef, type ChangeEvent } from 'react';
import type React from 'react';
import {useEffect, useRef, type ChangeEvent, useState} from 'react';
import { CaretRightOutlined, PauseOutlined, } from '@ant-design/icons';

export const ControlBarContainer = styled(Space)`
position: absolute;
bottom: 1rem;
right: 1rem;
bottom: 4rem;
right: 40%;
z-index: 100;
display: flex;
gap: 1.8rem;
background-color: #C5C5C5;
padding-top: 0.5rem;
padding-right: 1.8rem;
padding-bottom: 0.5rem;
padding-left: 1.8rem;
border-radius: 25px;
`;

export const SaveBtn = styled(Button)`
Expand Down Expand Up @@ -41,6 +50,35 @@ export const RestoreBtn = styled(Button)`
}
`;

export const ControlBarBtn = styled(Button)`
shape: circle;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shape is not in CSS properties.

border: none;
cursor: pointer;
outline: none;
height: 2rem;
width: 2rem;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
background-color: #909090;
font-size: 1rem;
`;

export const ControlBarBtnWithAttr = styled(ControlBarBtn)`
&[data-icon="square"]::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
width: 40%;
height: 40%;
background-color: white;
transform: translate(-50%, -50%);
}
`;


interface ControlBarProps {
modelSaveSubs: Array<(save: ModelSave) => void>;
worker: Worker;
Expand Down Expand Up @@ -95,59 +133,56 @@ export default function ControlBar(props: ControlBarProps): React.ReactElement {
load(e.target.files![0]);
};

const [isPlaying, setIsPlaying] = useState(true);
const handleIconClick = (): void => {
if (isPlaying) {
worker.postMessage({ func: 'pause' });
} else {
worker.postMessage({ func: 'start' });
}
setIsPlaying(!isPlaying);

};


return (
<>
<input
type="file"
id="file"
ref={inputFile}
style={{ display: 'none' }}
onChange={onChange}
/>
<SaveBtn
onClick={() => {
worker.postMessage({ func: 'serialize' });
}}
>
Save Model
</SaveBtn>
<RestoreBtn
onClick={() => {
inputFile.current?.click();
}}
>
Restore Model
</RestoreBtn>
<ControlBarContainer size="small" direction="horizontal">
<Button
onClick={() => {
worker.postMessage({ func: 'start' });
}}
>
Play
</Button>
<Button
onClick={() => {
worker.postMessage({ func: 'pause' });
}}
<>
<input
type="file"
id="file"
ref={inputFile}
style={{display: 'none'}}
onChange={onChange}
/>
<SaveBtn
onClick={() => {
worker.postMessage({func: 'serialize'});
}}
>
Pause
</Button>
<Button
onClick={() => {
worker.postMessage({ func: 'stop' });
}}
Save Model
</SaveBtn>
<RestoreBtn
onClick={() => {
inputFile.current?.click();
}}
>
Stop
</Button>
<Button
onClick={() => {
worker.terminate();
}}
>
TERMINATE
</Button>
</ControlBarContainer>
</>
Restore Model
</RestoreBtn>
<ControlBarContainer size="small" direction="horizontal">
<ControlBarBtn
onClick={handleIconClick}>
{isPlaying ?
<PauseOutlined style={{ color: 'white' }}/> :
<CaretRightOutlined style={{ color: 'white', fontSize: '1.4em', marginLeft: '0.15em' }}/>}
</ControlBarBtn>
<ControlBarBtnWithAttr
data-icon="square"
onClick={() => {
worker.postMessage({ func: 'stop' });
}}
/>
</ControlBarContainer>
</>
);

}