Skip to content

Commit

Permalink
add status toggle on popup (gautamkrishnar#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslawPokropinski authored Dec 6, 2021
1 parent 24e8b80 commit 522b08d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import SettingsIcon from '@mui/icons-material/Settings';
import FolderIcon from '@mui/icons-material/Folder';
import HistoryIcon from '@mui/icons-material/History';
import ClearAllIcon from '@mui/icons-material/ClearAll';
import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew';

function PopupView() {
const [downloadHistory, setDownloadHistory] = useState([]);
const [extensionStatus, setExtensionStatus] = useState(false);

useEffect(() => {
const updateHistory = () => {
const history = JSON.parse(localStorage.getItem('history'));
Expand All @@ -22,6 +25,25 @@ function PopupView() {
};
}, [setDownloadHistory]);

useEffect(() => {
const updateStatus = () => {
browser.storage.sync
.get(['extensionStatus'])
.then((r) => setExtensionStatus(r.extensionStatus));
};
const inter = setInterval(updateStatus, 1000);
updateStatus();

return () => {
clearInterval(inter);
};
}, [setDownloadHistory]);

const onExtensionStatusChange = (status) => {
browser.storage.sync.set({ extensionStatus: status });
setExtensionStatus(status);
};

const parseName = (name) => {
if (name == null) return 'unknown';
if (name.length < 52) return name;
Expand All @@ -31,12 +53,20 @@ function PopupView() {

return (
<Grid container justifyContent="center" spacing={2}>
<Grid item xs={2}>
<IconButton
variant="outlined"
onClick={() => onExtensionStatusChange(!extensionStatus)}
>
<PowerSettingsNewIcon color={extensionStatus ? 'success' : 'error'} />
</IconButton>
</Grid>
<Grid item xs={2}>
<IconButton variant="outlined" onClick={() => open('./config.html')}>
<SettingsIcon />
</IconButton>
</Grid>
<Grid item xs={3} />
<Grid item xs={1} />
<Grid item xs={2}>
<IconButton variant="outlined" onClick={() => open('./history.html')}>
<HistoryIcon />
Expand Down

0 comments on commit 522b08d

Please sign in to comment.