|
1 | 1 | import { useState } from "react"; |
2 | 2 | import Dialog from "@/lib/ui/model"; |
3 | 3 | import Unsplash from "@/lib/ui/unsplash"; |
4 | | -import { Button } from "@mui/material"; |
| 4 | +import { Button, Box } from "@mui/material"; |
5 | 5 | import CollectionsIcon from "@mui/icons-material/Collections"; |
6 | | - |
| 6 | +import Tooltip from "@mui/material/Tooltip"; |
| 7 | +import useInternetConnectionStatus from "@/hooks/useInternetConnectionStatus"; |
7 | 8 | interface IUnsplashModel { |
8 | 9 | field: string; |
9 | 10 | handleImageChange: (data: any) => void; |
10 | 11 | } |
11 | 12 |
|
12 | 13 | const UnsplashModel = ({ handleImageChange, field }: IUnsplashModel) => { |
13 | 14 | const [isOpen, setOpen] = useState(false); |
| 15 | + const [isConnected] = useInternetConnectionStatus(); |
14 | 16 |
|
15 | 17 | const handleClick = () => { |
16 | 18 | setOpen(prev => !prev); |
17 | 19 | }; |
18 | 20 |
|
| 21 | + const getTitle = () => { |
| 22 | + if (isConnected) return "Unsplash gallery"; |
| 23 | + |
| 24 | + return "You are not connected to the internet"; |
| 25 | + }; |
| 26 | + |
19 | 27 | return ( |
20 | 28 | <> |
21 | | - <Button startIcon={<CollectionsIcon />} onClick={handleClick}> |
22 | | - Gallery |
23 | | - </Button> |
| 29 | + <Tooltip title={getTitle()} placement="top" arrow> |
| 30 | + <Box component="div" display="flex"> |
| 31 | + <Button |
| 32 | + disabled={!isConnected} |
| 33 | + startIcon={<CollectionsIcon />} |
| 34 | + onClick={handleClick} |
| 35 | + > |
| 36 | + Gallery |
| 37 | + </Button> |
| 38 | + </Box> |
| 39 | + </Tooltip> |
24 | 40 | <Dialog isOpen={isOpen} handleClick={handleClick} title="Image Gallery"> |
25 | 41 | <Unsplash |
26 | 42 | handleImageChange={data => handleImageChange(data)} |
|
0 commit comments