bruno/renderer/components/Sidebar/TitleBar/index.js

71 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-03-07 13:44:49 +01:00
import React, { useState, forwardRef, useRef } from 'react';
2022-03-10 04:31:05 +01:00
import Toast from 'components/Toast';
import Dropdown from 'components/Dropdown';
import { useDispatch } from 'react-redux';
import { createCollection } from 'providers/ReduxStore/slices/collections';
2022-03-07 13:44:49 +01:00
import { IconDots } from '@tabler/icons';
2022-03-10 04:31:05 +01:00
import CreateCollection from '../CreateCollection';
2022-03-07 13:44:49 +01:00
import StyledWrapper from './StyledWrapper';
const TitleBar = () => {
2022-03-07 13:44:49 +01:00
const [modalOpen, setModalOpen] = useState(false);
2022-03-10 04:31:05 +01:00
const [showToast, setShowToast] = useState({show: false});
const dispatch = useDispatch();
2022-03-07 13:44:49 +01:00
const menuDropdownTippyRef = useRef();
const onMenuDropdownCreate = (ref) => menuDropdownTippyRef.current = ref;
const MenuIcon = forwardRef((props, ref) => {
return (
<div ref={ref} className="dropdown-icon cursor-pointer">
<IconDots size={22}/>
</div>
);
});
2022-03-10 04:31:05 +01:00
const handleCancel = () => setModalOpen(false);
const handleCloseToast = () => setShowToast({show: false});
2022-03-07 13:44:49 +01:00
const handleConfirm = (values) => {
setModalOpen(false);
dispatch(createCollection(values.collectionName))
2022-03-07 13:44:49 +01:00
};
return (
<StyledWrapper className="px-2 py-2 flex items-center">
2022-03-10 04:31:05 +01:00
{showToast.show && <Toast text={showToast.text} type={showToast.type} duration={showToast.duration} handleClose={handleCloseToast}/>}
2022-03-07 13:44:49 +01:00
{modalOpen ? (
<CreateCollection
handleCancel={handleCancel}
handleConfirm={handleConfirm}
/>
) : null}
<div>
<span className="ml-2">Collections</span>
</div>
<div className="collection-dropdown flex flex-grow items-center justify-end">
<Dropdown onCreate={onMenuDropdownCreate} icon={<MenuIcon />} placement='bottom-start'>
<div className="dropdown-item" onClick={(e) => {
menuDropdownTippyRef.current.hide();
setModalOpen(true);
}}>
Create Collection
</div>
<div className="dropdown-item" onClick={(e) => {
menuDropdownTippyRef.current.hide();
}}>
Import Collection
</div>
<div className="dropdown-item" onClick={(e) => {
menuDropdownTippyRef.current.hide();
}}>
Settings
</div>
</Dropdown>
</div>
</StyledWrapper>
)
};
2022-03-10 04:31:05 +01:00
export default TitleBar;