Skip to content

Commit 728142e

Browse files
authored
Merge pull request #24 from knowankit/feat/refine-ui-2
Refine image selection unsplash
2 parents f967ed2 + e0aae85 commit 728142e

File tree

10 files changed

+107
-22
lines changed

10 files changed

+107
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email-editor",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src/components/drop-container/create-template-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Tooltip from "@mui/material/Tooltip";
88
import TextField from "@mui/material/TextField";
99
import IconButton from "@mui/material/IconButton";
1010
import useTemplatesStore from "@/store/templates";
11+
import { v4 as uuidv4 } from "uuid";
1112

1213
const CreateTemplateButton = () => {
1314
const [isOpen, setOpen] = useState(false);
@@ -26,7 +27,7 @@ const CreateTemplateButton = () => {
2627
};
2728

2829
const handleCreateTemplate = () => {
29-
createNewTemplate({ ...emailData, templateName });
30+
createNewTemplate({ ...emailData, templateName, templateId: uuidv4() });
3031

3132
handleClose();
3233
};

src/components/left-sidebar/accordions/templates/echip.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import Chip from "@mui/material/Chip";
2-
import Stack from "@mui/material/Stack";
3-
import DoneIcon from "@mui/icons-material/Done";
42
import DeleteIcon from "@mui/icons-material/Delete";
3+
import useEmailStore from "@/store/email";
54

65
interface IEChip {
76
handleClick: () => void;
87
handleDelete: () => void;
98
template: {
10-
templateName: string;
9+
templateName?: string;
10+
templateId?: string;
1111
};
1212
}
1313

1414
const EChip = ({ handleClick, handleDelete, template }: IEChip) => {
15+
const { emailData } = useEmailStore();
16+
1517
return (
1618
<Chip
1719
label={template.templateName}
1820
onClick={handleClick}
21+
color={
22+
template.templateId === emailData.templateId ? "primary" : "default"
23+
}
1924
sx={{ mr: 1 }}
2025
onDelete={handleDelete}
2126
deleteIcon={<DeleteIcon />}

src/components/left-sidebar/accordions/templates/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import Typography from "@mui/material/Typography";
77
import { useState } from "react";
88
import Box from "@mui/material/Box";
9-
import Paper from "@mui/material/Paper";
109
import Alert from "@mui/material/Alert";
1110

1211
import useTemplatesStore from "@/store/templates";

src/components/right-sidebar/hero-attributes/settings.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Button } from "@mui/material";
1414
import { useState } from "react";
1515
import React from "react";
1616
import UnsplashModel from "@/lib/ui/unsplash/model";
17-
17+
import ImagePreview from "@/lib/ui/image-preview";
1818
interface ISetting {
1919
expanded: HeroAttributesAccordionType;
2020
changeTab: (value: HeroAttributesAccordionType) => void;
@@ -67,15 +67,7 @@ const Settings = ({ expanded, changeTab }: ISetting) => {
6767
<AccordionDetails>
6868
<Box>
6969
<Box display="flex">
70-
<Box
71-
sx={{
72-
height: "100px",
73-
width: "100px",
74-
marginRight: "1rem",
75-
backgroundImage: `url("${activeNode?.section.attributes["background-url"]}")`,
76-
backgroundSize: "cover"
77-
}}
78-
/>
70+
<ImagePreview formData={formData} />
7971
<UnsplashModel
8072
handleImageChange={data => handleImageChange(data)}
8173
field="background-url"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useEffect, useState } from "react";
2+
3+
const useInternetConnectionStatus = () => {
4+
const [isConnected, setConnection] = useState(false);
5+
6+
useEffect(() => {
7+
window.addEventListener("offline", () => {
8+
setConnection(false);
9+
});
10+
11+
window.addEventListener("online", () => {
12+
setConnection(true);
13+
});
14+
15+
setConnection(navigator.onLine);
16+
}, []);
17+
18+
return [isConnected];
19+
};
20+
21+
export default useInternetConnectionStatus;

src/lib/ui/image-preview/index.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Box from "@mui/material/Box";
2+
import IconButton from "@mui/material/IconButton";
3+
import VisibilityIcon from "@mui/icons-material/Visibility";
4+
5+
interface ImagePreview {
6+
formData: {
7+
"background-url": string;
8+
};
9+
height?: string;
10+
width?: string;
11+
}
12+
13+
const ImagePreview = ({
14+
formData,
15+
height = "100px",
16+
width = "100px"
17+
}: ImagePreview) => {
18+
return (
19+
<Box
20+
sx={{
21+
height,
22+
width,
23+
marginRight: "1rem",
24+
backgroundImage: `url("${formData["background-url"]}")`,
25+
backgroundSize: "cover",
26+
opacity: "0.8"
27+
}}
28+
>
29+
<Box
30+
height="inherit"
31+
display="flex"
32+
justifyContent="center"
33+
alignItems="center"
34+
>
35+
<IconButton
36+
aria-label="view image"
37+
size="small"
38+
onClick={() => {
39+
alert("Show model with full image");
40+
}}
41+
>
42+
<VisibilityIcon fontSize="small" color="info" />
43+
</IconButton>
44+
</Box>
45+
</Box>
46+
);
47+
};
48+
49+
export default ImagePreview;

src/lib/ui/unsplash/model.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
import { useState } from "react";
22
import Dialog from "@/lib/ui/model";
33
import Unsplash from "@/lib/ui/unsplash";
4-
import { Button } from "@mui/material";
4+
import { Button, Box } from "@mui/material";
55
import CollectionsIcon from "@mui/icons-material/Collections";
6-
6+
import Tooltip from "@mui/material/Tooltip";
7+
import useInternetConnectionStatus from "@/hooks/useInternetConnectionStatus";
78
interface IUnsplashModel {
89
field: string;
910
handleImageChange: (data: any) => void;
1011
}
1112

1213
const UnsplashModel = ({ handleImageChange, field }: IUnsplashModel) => {
1314
const [isOpen, setOpen] = useState(false);
15+
const [isConnected] = useInternetConnectionStatus();
1416

1517
const handleClick = () => {
1618
setOpen(prev => !prev);
1719
};
1820

21+
const getTitle = () => {
22+
if (isConnected) return "Unsplash gallery";
23+
24+
return "You are not connected to the internet";
25+
};
26+
1927
return (
2028
<>
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>
2440
<Dialog isOpen={isOpen} handleClick={handleClick} title="Image Gallery">
2541
<Unsplash
2642
handleImageChange={data => handleImageChange(data)}

src/store/email.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface StoreState {
99
tagName: string;
1010
attributes: any;
1111
children: any;
12+
templateId?: string;
1213
};
1314
activeNode: any | null;
1415
}

src/store/templates.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ interface MJMLNodeAttributes {
99
}
1010

1111
interface MJMLNode {
12-
templateName: string
12+
templateName?: string
13+
templateId?: string;
1314
tagName: string;
1415
attributes: MJMLNodeAttributes;
1516
children: MJMLNode[];

0 commit comments

Comments
 (0)