From ad8b5a5f9864ce9f105e59fec36bd4dbeae97cd2 Mon Sep 17 00:00:00 2001 From: Rutik Wankhade Date: Mon, 7 Oct 2024 21:52:02 +0530 Subject: [PATCH 1/3] refactor: create reusable search component for unsplash --- src/components/Themes/BackgroundTheme.js | 102 ++------------------- src/components/UnsplashSearch.js | 107 +++++++++++++++++++++++ 2 files changed, 114 insertions(+), 95 deletions(-) create mode 100644 src/components/UnsplashSearch.js diff --git a/src/components/Themes/BackgroundTheme.js b/src/components/Themes/BackgroundTheme.js index 22b76ec..70dca69 100644 --- a/src/components/Themes/BackgroundTheme.js +++ b/src/components/Themes/BackgroundTheme.js @@ -1,83 +1,24 @@ -import React, { useState, useEffect, useContext } from 'react'; -import unsplash from "../../utils/unsplashConfig"; +import React, { useContext } from 'react'; import { ImgContext } from '../../utils/ImgContext'; +import UnsplashSearch from '../UnsplashSearch'; const BackgroundTheme = ({ config }) => { - const { title, author, font, icon, customIcon, platform, bgColor } = config; - - // const [image, setImage] = useState({}) - - const [imageList, setImageList] = useState([]); - const [searchText, setSearchText] = useState('dev'); - + const { title, author, font, icon, customIcon, bgColor } = config; const { unsplashImage, setUnsplashImage } = useContext(ImgContext); - const searchImages = () => { - - unsplash.search - .getPhotos({ - query: searchText, - page: 1, - per_page: 30, - // orientation:'portrait' - - - }) - .then(response => { - // console.log(response.response.results); - setImageList(response.response.results) - }); - } - - useEffect(() => { - - unsplash.search - .getPhotos({ - query: 'setup', - page: 1, - per_page: 30 - - }) - .then(response => { - // console.log(response.response.results); - setImageList(response.response.results) - }); - }, []) - - const selectImage = (image) => { - setUnsplashImage({ - url: image.urls.regular, - name: image.user.name, - avatar: image.user.profile_image.small, - profile: `${image.user.links.html}?utm_source=https://coverview.vercel.app&utm_medium=referral`, - downloadLink: image.links.download_location - - }) - - - } - - const handleSearchSubmit = (e) => { - e.preventDefault(); - searchImages(searchText); - - } - return ( -
+
-
-
- +
- {unsplashImage ?
@@ -131,37 +72,8 @@ const BackgroundTheme = ({ config }) => { :
-
-
Click on any image to select
-
handleSearchSubmit(e)} className=" ml-auto mr-2 w-1/2 flex bg-gray-50 rounded-full border mb-2"> - setSearchText(e.target.value)} - /> + - - - -
- - -
- { - imageList.map(image => { - return {image.alt_description} selectImage(image) - } - /> - }) - } -
} diff --git a/src/components/UnsplashSearch.js b/src/components/UnsplashSearch.js new file mode 100644 index 0000000..5d62ff3 --- /dev/null +++ b/src/components/UnsplashSearch.js @@ -0,0 +1,107 @@ +import React, { useState, useEffect, useContext } from 'react'; +import unsplash from '../utils/unsplashConfig'; +import { ImgContext } from '../utils/ImgContext'; + +const UnsplashSearch = () => { + + const [imageList, setImageList] = useState([]); + const [searchText, setSearchText] = useState('setup'); + const { unsplashImage, setUnsplashImage } = useContext(ImgContext); + + + const searchImages = () => { + + unsplash.search + .getPhotos({ + query: searchText, + page: 1, + per_page: 30, + // orientation:'portrait' + + + }) + .then(response => { + // console.log(response.response.results); + setImageList(response.response.results) + }); + } + + + const selectImage = (image) => { + setUnsplashImage({ + url: image.urls.regular, + name: image.user.name, + avatar: image.user.profile_image.small, + profile: `${image.user.links.html}?utm_source=https://coverview.vercel.app&utm_medium=referral`, + downloadLink: image.links.download_location + + }) + + + } + + const handleSearchSubmit = (e) => { + e.preventDefault(); + searchImages(searchText); + + } + + useEffect(() => { + + unsplash.search + .getPhotos({ + query: 'setup', + page: 1, + per_page: 30 + + }) + .then(response => { + // console.log(response.response.results); + setImageList(response.response.results) + }); + }, []) + + return ( +
+
+ +
+
handleSearchSubmit(e)} className=" mx-auto w-full flex bg-gray-50 rounded-full border border-gray-50 mb-2"> + setSearchText(e.target.value)} + /> + + +
+ +
+ + +
+ { + imageList.map(image => { + return
+ Click to Select + {image.alt_description} selectImage(image) + } + className="rounded-lg object-cover h-44 w-full" + /> +
+ }) + } +
+
+
+ ); +} + +export default UnsplashSearch; \ No newline at end of file From e2ce7e5f6197ad7c74f7b134025b0589df67864a Mon Sep 17 00:00:00 2001 From: Rutik Wankhade Date: Mon, 7 Oct 2024 22:16:43 +0530 Subject: [PATCH 2/3] refactor: use unsplash search component in both themes --- src/components/Editor.js | 4 +- src/components/Themes/BackgroundTheme.js | 2 +- src/components/Themes/StylishTheme.js | 100 ++--------------------- src/components/UnsplashSearch.js | 9 +- src/utils/constants.js | 8 +- 5 files changed, 19 insertions(+), 104 deletions(-) diff --git a/src/components/Editor.js b/src/components/Editor.js index f3d0f7a..7a93d03 100644 --- a/src/components/Editor.js +++ b/src/components/Editor.js @@ -157,7 +157,7 @@ class Editor extends React.Component {
-
+ {/*
Pattern -
+
*/}
Platform diff --git a/src/components/Themes/BackgroundTheme.js b/src/components/Themes/BackgroundTheme.js index 70dca69..597ffbf 100644 --- a/src/components/Themes/BackgroundTheme.js +++ b/src/components/Themes/BackgroundTheme.js @@ -72,7 +72,7 @@ const BackgroundTheme = ({ config }) => { :
- +
diff --git a/src/components/Themes/StylishTheme.js b/src/components/Themes/StylishTheme.js index 56615bf..3cc81ff 100644 --- a/src/components/Themes/StylishTheme.js +++ b/src/components/Themes/StylishTheme.js @@ -1,68 +1,11 @@ -import React, { useState, useEffect, useContext } from 'react'; -import unsplash from "../../utils/unsplashConfig"; +import React, { useContext } from 'react'; import { ImgContext } from '../../utils/ImgContext'; +import UnsplashSearch from '../UnsplashSearch'; const StylishTheme = ({ config }) => { const { title, author, font, icon, customIcon, bgColor } = config; - - // const [image, setImage] = useState({}) - - const [imageList, setImageList] = useState([]); - const [searchText, setSearchText] = useState('dev'); - const { unsplashImage, setUnsplashImage } = useContext(ImgContext); - const searchImages = () => { - - unsplash.search - .getPhotos({ - query: searchText, - page: 1, - per_page: 30, - // orientation:'portrait' - - - }) - .then(response => { - // console.log(response.response.results); - setImageList(response.response.results) - }); - } - - useEffect(() => { - - unsplash.search - .getPhotos({ - query: 'setup', - page: 1, - per_page: 25 - - }) - .then(response => { - // console.log(response.response.results); - setImageList(response.response.results) - }); - }, []) - - const selectImage = (image) => { - setUnsplashImage({ - url: image.urls.regular, - name: image.user.name, - avatar: image.user.profile_image.small, - profile: `${image.user.links.html}?utm_source=https://coverview.vercel.app&utm_medium=referral`, - downloadLink: image.links.download_location - - }) - - - } - - const handleSearchSubmit = (e) => { - e.preventDefault(); - searchImages(searchText); - - } - return (
@@ -94,18 +37,15 @@ const StylishTheme = ({ config }) => {
-
+
{unsplashImage ? -
+
-
+ preview - preview -
-
: -
+
-
handleSearchSubmit(e)} className="flex bg-gray-50 rounded-full border mb-2"> - setSearchText(e.target.value)} - /> - - -
- - -
- { - imageList.map(image => { - return {image.alt_description} selectImage(image) - } - /> - }) - } -
+
} diff --git a/src/components/UnsplashSearch.js b/src/components/UnsplashSearch.js index 5d62ff3..d28a56d 100644 --- a/src/components/UnsplashSearch.js +++ b/src/components/UnsplashSearch.js @@ -2,7 +2,7 @@ import React, { useState, useEffect, useContext } from 'react'; import unsplash from '../utils/unsplashConfig'; import { ImgContext } from '../utils/ImgContext'; -const UnsplashSearch = () => { +const UnsplashSearch = ({ largeImgPreview }) => { const [imageList, setImageList] = useState([]); const [searchText, setSearchText] = useState('setup'); @@ -85,15 +85,16 @@ const UnsplashSearch = () => {
{ imageList.map(image => { - return
Click to Select {image.alt_description} selectImage(image) } - className="rounded-lg object-cover h-44 w-full" + className="rounded-lg object-cover h-full w-full" />
}) diff --git a/src/utils/constants.js b/src/utils/constants.js index 550c61a..1dae0fb 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -14,6 +14,10 @@ export const THEMES = [ label: 'background', preview: backgroundThemePlaceholder }, + { + label: 'stylish', + preview: stylishThemePlaceholder + }, { label: 'basic', preview: basicThemePlaceholder @@ -22,10 +26,6 @@ export const THEMES = [ label: 'modern', preview: modernThemePlaceholder }, - { - label: 'stylish', - preview: stylishThemePlaceholder - }, { label: 'outline', preview: outlineThemePlaceholder From 5f924efdef0ae7a84e86f7ea776a9db2b748da1d Mon Sep 17 00:00:00 2001 From: Rutik Wankhade Date: Mon, 7 Oct 2024 22:19:21 +0530 Subject: [PATCH 3/3] fix: fix bakdrop blur inconsistancy issue --- src/components/Themes/BackgroundTheme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Themes/BackgroundTheme.js b/src/components/Themes/BackgroundTheme.js index 597ffbf..1725e9d 100644 --- a/src/components/Themes/BackgroundTheme.js +++ b/src/components/Themes/BackgroundTheme.js @@ -27,7 +27,7 @@ const BackgroundTheme = ({ config }) => {
-
+