2022-04-06 22:27:08 +02:00
|
|
|
import React, { useRef, useEffect } from 'react';
|
2022-02-15 01:02:51 +01:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import SnapSettingsCard from '../../../../components/app/flask/snap-settings-card';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import Typography from '../../../../components/ui/typography/typography';
|
|
|
|
import {
|
|
|
|
TYPOGRAPHY,
|
|
|
|
COLORS,
|
|
|
|
FLEX_DIRECTION,
|
|
|
|
JUSTIFY_CONTENT,
|
|
|
|
ALIGN_ITEMS,
|
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import Box from '../../../../components/ui/box';
|
|
|
|
import { SNAPS_VIEW_ROUTE } from '../../../../helpers/constants/routes';
|
|
|
|
import { disableSnap, enableSnap } from '../../../../store/actions';
|
|
|
|
import { getSnaps } from '../../../../selectors';
|
2022-03-23 17:47:54 +01:00
|
|
|
import { handleSettingsRefs } from '../../../../helpers/utils/settings-search';
|
2022-02-15 01:02:51 +01:00
|
|
|
|
|
|
|
const SnapListTab = () => {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const history = useHistory();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const snaps = useSelector(getSnaps);
|
2022-04-06 22:27:08 +02:00
|
|
|
const settingsRef = useRef();
|
2022-02-15 01:02:51 +01:00
|
|
|
const onClick = (snap) => {
|
2022-05-11 22:14:53 +02:00
|
|
|
history.push(`${SNAPS_VIEW_ROUTE}/${encodeURIComponent(snap.id)}`);
|
2022-02-15 01:02:51 +01:00
|
|
|
};
|
|
|
|
const onToggle = (snap) => {
|
|
|
|
if (snap.enabled) {
|
|
|
|
dispatch(disableSnap(snap.id));
|
|
|
|
} else {
|
|
|
|
dispatch(enableSnap(snap.id));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-23 17:47:54 +01:00
|
|
|
useEffect(() => {
|
|
|
|
handleSettingsRefs(t, t('snaps'), settingsRef);
|
2022-04-06 22:27:08 +02:00
|
|
|
}, [settingsRef, t]);
|
2022-03-23 17:47:54 +01:00
|
|
|
|
2022-02-15 01:02:51 +01:00
|
|
|
return (
|
2022-03-23 17:47:54 +01:00
|
|
|
<div className="snap-list-tab" ref={settingsRef}>
|
2022-02-15 01:02:51 +01:00
|
|
|
{Object.entries(snaps).length ? (
|
|
|
|
<div className="snap-list-tab__body">
|
|
|
|
<Box display="flex" flexDirection={FLEX_DIRECTION.COLUMN}>
|
|
|
|
<Typography variant={TYPOGRAPHY.H5} marginBottom={2}>
|
|
|
|
{t('expandExperience')}
|
|
|
|
</Typography>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H6}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
2022-02-15 01:02:51 +01:00
|
|
|
marginBottom={2}
|
|
|
|
>
|
|
|
|
{t('manageSnaps')}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<div className="snap-list-tab__wrapper">
|
|
|
|
{Object.entries(snaps).map(([key, snap]) => {
|
|
|
|
return (
|
|
|
|
<SnapSettingsCard
|
|
|
|
className="snap-settings-card"
|
|
|
|
isEnabled={snap.enabled}
|
|
|
|
key={key}
|
|
|
|
onToggle={() => {
|
|
|
|
onToggle(snap);
|
|
|
|
}}
|
|
|
|
description={snap.manifest.description}
|
|
|
|
url={snap.id}
|
|
|
|
name={snap.manifest.proposedName}
|
|
|
|
status={snap.status}
|
|
|
|
version={snap.version}
|
|
|
|
onClick={() => {
|
|
|
|
onClick(snap);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Box
|
|
|
|
className="snap-list-tab__container--no-snaps"
|
|
|
|
width="full"
|
|
|
|
height="full"
|
|
|
|
justifyContent={JUSTIFY_CONTENT.CENTER}
|
|
|
|
alignItems={ALIGN_ITEMS.CENTER}
|
|
|
|
>
|
2022-03-09 16:24:53 +01:00
|
|
|
<Typography variant={TYPOGRAPHY.H4} color={COLORS.TEXT_ALTERNATIVE}>
|
2022-02-15 01:02:51 +01:00
|
|
|
<span>{t('noSnaps')}</span>
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SnapListTab;
|