-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove default add btn in advanced settings, add block btn on u… (
#4075) * feat: Remove default add btn in advanced settings, add block btn on users * make reusable component
- Loading branch information
1 parent
fc15e64
commit f783008
Showing
6 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/shared/src/components/contentPreference/BlockButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { ReactElement } from 'react'; | ||
import React from 'react'; | ||
import type { ContentPreferenceType } from '../../graphql/contentPreference'; | ||
import { ContentPreferenceStatus } from '../../graphql/contentPreference'; | ||
import { Button } from '../buttons/Button'; | ||
import { ButtonVariant, ButtonSize } from '../buttons/common'; | ||
import { useContentPreference } from '../../hooks/contentPreference/useContentPreference'; | ||
|
||
type BlockButtonProps = { | ||
feedId: string; | ||
entityId: string; | ||
entityName: string; | ||
status?: ContentPreferenceStatus; | ||
entityType: ContentPreferenceType; | ||
variant?: ButtonVariant; | ||
size?: ButtonSize; | ||
}; | ||
|
||
const BlockButton = ({ | ||
variant = ButtonVariant.Secondary, | ||
size = ButtonSize.Small, | ||
feedId, | ||
entityId, | ||
entityName, | ||
entityType, | ||
status, | ||
}: BlockButtonProps): ReactElement => { | ||
const { block, unblock } = useContentPreference(); | ||
|
||
return ( | ||
<Button | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
if (status === ContentPreferenceStatus.Blocked) { | ||
unblock({ | ||
id: entityId, | ||
entity: entityType, | ||
entityName, | ||
feedId, | ||
}); | ||
} else { | ||
block({ | ||
id: entityId, | ||
entity: entityType, | ||
entityName, | ||
feedId, | ||
}); | ||
} | ||
}} | ||
variant={variant} | ||
size={size} | ||
> | ||
{status === ContentPreferenceStatus.Blocked ? 'Unblock' : 'Block'} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default BlockButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters