-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathindex.tsx
More file actions
55 lines (48 loc) · 1.47 KB
/
index.tsx
File metadata and controls
55 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import useUASButton from '#app/hooks/useUASButton';
import styles from './index.styles';
interface SaveArticleButtonProps {
isSignedIn: boolean;
articleId: string;
service: string;
}
/** A button component that allows users to save an article for later reading,
* showing the button based on user sign in status and feature toggles,
* and displaying the saved status, loading state, and handling errors from the UAS API.
* FUTURE TODO : Implement button click handler to toggle saved state */
const SaveArticleButton = ({
isSignedIn,
articleId,
service,
}: SaveArticleButtonProps) => {
const { showButton, isSaved, loading, error } = useUASButton({
isSignedIn,
articleId,
service,
});
if (!showButton) {
return null;
}
// TODO : Labels and text will be updated in a future PR to support translations and figma designs
const buttonLabel = isSaved ? 'Remove from saved' : 'Save for later';
const getButtonText = () => {
if (loading) return 'Loading...';
return isSaved ? 'Remove from saved' : 'Save for later';
};
// TODO : Will modify based on future error handling implementation,
// currently just hides the button if there is an error fetching save status
if (error) {
return null;
}
return (
<button
css={styles.buttonWrapper}
type="button"
disabled={loading}
aria-label={buttonLabel}
title={buttonLabel}
>
{getButtonText()}
</button>
);
};
export default SaveArticleButton;