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
96 changes: 66 additions & 30 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 } from 'react';
import type React from 'react';
import { useEffect, useRef, type ChangeEvent, useState } from 'react';
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
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,34 @@
}
`;

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 @@ -82,8 +119,16 @@

console.log('wrote a save to ' + filename, sav);
}

// take a file and send its contents to the worker

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

return (
<>
Expand All @@ -103,34 +148,25 @@
Restore Model
</RestoreBtn>
<ControlBarContainer size="small" direction="horizontal">
<Button
onClick={() => {
worker.postMessage({ func: 'start' });
}}
>
Play
</Button>
<Button
onClick={() => {
worker.postMessage({ func: 'pause' });
}}
>
Pause
</Button>
<Button
<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' });
}}
>
Stop
</Button>
<Button
onClick={() => {
worker.terminate();
}}
>
TERMINATE
</Button>
/>
</ControlBarContainer>
</>
);
Expand Down
Loading