Skip to content

Commit 6fa936c

Browse files
committed
feat: add refresh icon button to the top-right image
1 parent 1140321 commit 6fa936c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/components/shared/DisplayRandomPicture.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* eslint-disable @next/next/no-img-element */
22

33
'use client';
4-
import { Send } from '@mui/icons-material';
4+
import styled from '@emotion/styled';
5+
import { Autorenew, Send } from '@mui/icons-material';
56
import Avatar from '@mui/material/Avatar';
67
import Button from '@mui/material/Button';
8+
import { purple } from '@mui/material/colors';
79
import Stack from '@mui/material/Stack';
810
import React, { useEffect, useState } from 'react';
911

@@ -12,6 +14,28 @@ import { useClientContext } from '@/hooks/useClientContext';
1214

1315
import SubmitButton from '@/components/shared/SubmitButton';
1416

17+
const StyledRefreshButton = styled.div`
18+
position: absolute;
19+
right: 0;
20+
top: 0;
21+
margin: 0.5rem;
22+
cursor: pointer;
23+
svg {
24+
width: 20px;
25+
height: 20px;
26+
}
27+
:hover {
28+
svg {
29+
path {
30+
fill: ${purple[500]};
31+
}
32+
}
33+
.MuiAvatar-circular {
34+
background-color: ${purple[50]};
35+
}
36+
}
37+
`;
38+
1539
const DisplayRandomPicture = () => {
1640
const [imageUrl, setImageUrl] = useState('');
1741
const [loading, setLoading] = useState(true);
@@ -59,6 +83,7 @@ const DisplayRandomPicture = () => {
5983
justifyContent='center'
6084
alignItems='center'
6185
spacing={2}
86+
sx={{ position: 'relative', width: '300px', margin: '0 auto' }}
6287
>
6388
{error && <p>{error}</p>}
6489
{imageUrl && (
@@ -88,6 +113,11 @@ const DisplayRandomPicture = () => {
88113
Get Another Picture
89114
</Button>
90115
</SubmitButton>
116+
<StyledRefreshButton onClick={fetchRandomPicture}>
117+
<Avatar sx={{ width: 24, height: 24 }}>
118+
<Autorenew />
119+
</Avatar>
120+
</StyledRefreshButton>
91121
{renderAlertBar()}
92122
</Stack>
93123
);

0 commit comments

Comments
 (0)