Widget: add actions
This commit is contained in:
parent
000121d74f
commit
97b5c5af43
|
@ -1,9 +1,9 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Stack, Text } from 'soapbox/components/ui';
|
import { Stack, HStack, Text, IconButton } from 'soapbox/components/ui';
|
||||||
|
|
||||||
interface IWidgetTitle {
|
interface IWidgetTitle {
|
||||||
title: string | React.ReactNode
|
title: string | React.ReactNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
const WidgetTitle = ({ title }: IWidgetTitle): JSX.Element => (
|
const WidgetTitle = ({ title }: IWidgetTitle): JSX.Element => (
|
||||||
|
@ -16,12 +16,31 @@ const WidgetBody: React.FC = ({ children }): JSX.Element => (
|
||||||
|
|
||||||
interface IWidget {
|
interface IWidget {
|
||||||
title: string | React.ReactNode,
|
title: string | React.ReactNode,
|
||||||
|
onActionClick?: () => void,
|
||||||
|
actionIcon?: string,
|
||||||
|
actionTitle?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Widget: React.FC<IWidget> = ({ title, children }): JSX.Element => {
|
const Widget: React.FC<IWidget> = ({
|
||||||
|
title,
|
||||||
|
children,
|
||||||
|
onActionClick,
|
||||||
|
actionIcon = require('@tabler/icons/icons/arrow-right.svg'),
|
||||||
|
actionTitle,
|
||||||
|
}): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
<Stack space={2}>
|
<Stack space={2}>
|
||||||
|
<HStack alignItems='center'>
|
||||||
<WidgetTitle title={title} />
|
<WidgetTitle title={title} />
|
||||||
|
{onActionClick && (
|
||||||
|
<IconButton
|
||||||
|
className='w-6 h-6 ml-2'
|
||||||
|
src={actionIcon}
|
||||||
|
onClick={onActionClick}
|
||||||
|
title={actionTitle}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</HStack>
|
||||||
<WidgetBody>{children}</WidgetBody>
|
<WidgetBody>{children}</WidgetBody>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||||
import { Link } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import { Text, Widget } from 'soapbox/components/ui';
|
import { Text, Widget } from 'soapbox/components/ui';
|
||||||
import { useAppSelector, useSoapboxConfig } from 'soapbox/hooks';
|
import { useAppSelector, useSoapboxConfig } from 'soapbox/hooks';
|
||||||
|
|
||||||
import SiteWallet from './site_wallet';
|
import SiteWallet from './site_wallet';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
actionTitle: { id: 'crypto_donate_panel.actions.view', defaultMessage: 'Click to see {count} {count, plural, one {wallet} other {wallets}}' },
|
||||||
|
});
|
||||||
|
|
||||||
interface ICryptoDonatePanel {
|
interface ICryptoDonatePanel {
|
||||||
limit: number,
|
limit: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
const CryptoDonatePanel: React.FC<ICryptoDonatePanel> = ({ limit = 3 }): JSX.Element | null => {
|
const CryptoDonatePanel: React.FC<ICryptoDonatePanel> = ({ limit = 3 }): JSX.Element | null => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const addresses = useSoapboxConfig().get('cryptoAddresses');
|
const addresses = useSoapboxConfig().get('cryptoAddresses');
|
||||||
const siteTitle = useAppSelector((state) => state.instance.title);
|
const siteTitle = useAppSelector((state) => state.instance.title);
|
||||||
|
|
||||||
|
@ -19,11 +26,16 @@ const CryptoDonatePanel: React.FC<ICryptoDonatePanel> = ({ limit = 3 }): JSX.Ele
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const more = addresses.size - limit;
|
const handleAction = () => {
|
||||||
const hasMore = more > 0;
|
history.push('/donate/crypto');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Widget title={<FormattedMessage id='crypto_donate_panel.heading' defaultMessage='Donate Cryptocurrency' />}>
|
<Widget
|
||||||
|
title={<FormattedMessage id='crypto_donate_panel.heading' defaultMessage='Donate Cryptocurrency' />}
|
||||||
|
onActionClick={handleAction}
|
||||||
|
actionTitle={intl.formatMessage(messages.actionTitle, { count: addresses.size })}
|
||||||
|
>
|
||||||
<Text>
|
<Text>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='crypto_donate_panel.intro.message'
|
id='crypto_donate_panel.intro.message'
|
||||||
|
@ -33,18 +45,6 @@ const CryptoDonatePanel: React.FC<ICryptoDonatePanel> = ({ limit = 3 }): JSX.Ele
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<SiteWallet limit={limit} />
|
<SiteWallet limit={limit} />
|
||||||
|
|
||||||
{hasMore && (
|
|
||||||
<Link className='wtf-panel__expand-btn' to='/donate/crypto'>
|
|
||||||
<Text>
|
|
||||||
<FormattedMessage
|
|
||||||
id='crypto_donate_panel.actions.more'
|
|
||||||
defaultMessage='Click to see {count} more {count, plural, one {wallet} other {wallets}}'
|
|
||||||
values={{ count: more }}
|
|
||||||
/>
|
|
||||||
</Text>
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
</Widget>
|
</Widget>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,8 +36,16 @@ const WhoToFollowPanel = ({ limit }: IWhoToFollowPanel) => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: This page actually doesn't look good right now
|
||||||
|
// const handleAction = () => {
|
||||||
|
// history.push('/suggestions');
|
||||||
|
// };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Widget title={<FormattedMessage id='who_to_follow.title' defaultMessage='People To Follow' />}>
|
<Widget
|
||||||
|
title={<FormattedMessage id='who_to_follow.title' defaultMessage='People To Follow' />}
|
||||||
|
// onAction={handleAction}
|
||||||
|
>
|
||||||
{suggestionsToRender.map((suggestion: ImmutableMap<string, any>) => (
|
{suggestionsToRender.map((suggestion: ImmutableMap<string, any>) => (
|
||||||
<AccountContainer
|
<AccountContainer
|
||||||
key={suggestion.get('account')}
|
key={suggestion.get('account')}
|
||||||
|
|
Loading…
Reference in New Issue