CurationPanel.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React from 'react';
  2. import { ChannelEntity } from '../entities/ChannelEntity';
  3. import { isVerifiedChannel, isCensoredChannel } from './ChannelHelpers';
  4. import { useMyMembership } from '@polkadot/joy-utils/MyMembershipContext';
  5. import TxButton from '@polkadot/joy-utils/TxButton';
  6. import { ChannelCurationStatus } from '@joystream/types/lib/content-working-group';
  7. import { AccountId } from '@polkadot/types/interfaces';
  8. type ChannelCurationPanelProps = {
  9. channel: ChannelEntity
  10. };
  11. export const CurationPanel = (props: ChannelCurationPanelProps) => {
  12. const { curationActor, allAccounts } = useMyMembership();
  13. const { channel } = props;
  14. const canUseAccount = (account: AccountId) => {
  15. if (!allAccounts || !Object.keys(allAccounts).length) {
  16. return false
  17. }
  18. const ix = Object.keys(allAccounts).findIndex((key) => {
  19. return account.eq(allAccounts[key].json.address)
  20. });
  21. return ix != -1
  22. }
  23. const renderToggleCensorshipButton = () => {
  24. if (!curationActor) { return null }
  25. const [curation_actor, role_account] = curationActor;
  26. const accountAvailable = canUseAccount(role_account);
  27. const isCensored = isCensoredChannel(channel);
  28. const new_curation_status = new ChannelCurationStatus(
  29. isCensored ? 'Normal' : 'Censored'
  30. );
  31. return <TxButton
  32. accountId={role_account.toString()}
  33. type='submit'
  34. size='medium'
  35. icon={isCensored ? 'x' : 'warning'}
  36. isDisabled={!accountAvailable}
  37. label={isCensored ? 'Un-Censor' : 'Censor'}
  38. params={[
  39. curation_actor,
  40. channel.id,
  41. null, // not changing verified status
  42. new_curation_status // toggled curation status
  43. ]}
  44. tx={'contentWorkingGroup.updateChannelAsCurationActor'}
  45. />
  46. }
  47. const renderToggleVerifiedButton = () => {
  48. if (!curationActor) { return null }
  49. const [curation_actor, role_account] = curationActor;
  50. const accountAvailable = canUseAccount(role_account);
  51. const isVerified = isVerifiedChannel(channel);
  52. return <TxButton
  53. accountId={role_account.toString()}
  54. type='submit'
  55. size='medium'
  56. icon={isVerified ? 'x' : 'checkmark'}
  57. isDisabled={!accountAvailable}
  58. label={isVerified ? 'Remove Verification' : 'Verify'}
  59. params={[
  60. curation_actor,
  61. channel.id,
  62. !isVerified, // toggle verified
  63. null // not changing curation status
  64. ]}
  65. tx={'contentWorkingGroup.updateChannelAsCurationActor'}
  66. />
  67. }
  68. return <>
  69. <div style={{ float: 'right' }}>
  70. {renderToggleCensorshipButton()}
  71. {renderToggleVerifiedButton()}
  72. </div>
  73. </>
  74. }