From e94602bdcd4de726ad7f1e19a28bdd3be2daca57 Mon Sep 17 00:00:00 2001 From: IGhos-P Date: Thu, 23 Jun 2022 17:32:46 +0900 Subject: [PATCH] feat : utils & soket --- yam-view/src/App.js | 28 ------ yam-view/src/components/Data/markerData.js | 103 +++++++++++++++++++++ yam-view/src/pages/WebView.js | 25 +++++ yam-view/src/utils/filterTag.js | 3 + yam-view/src/utils/findCategory.js | 26 ++++++ yam-view/src/utils/localMethod.js | 28 ++++++ 6 files changed, 185 insertions(+), 28 deletions(-) create mode 100644 yam-view/src/utils/filterTag.js create mode 100644 yam-view/src/utils/findCategory.js create mode 100644 yam-view/src/utils/localMethod.js diff --git a/yam-view/src/App.js b/yam-view/src/App.js index 64a04d3..def7fdd 100644 --- a/yam-view/src/App.js +++ b/yam-view/src/App.js @@ -6,34 +6,6 @@ import axios from "axios"; //axios.defaults.withCredentials = true; function App() { - // 받아오는 값에 따라 달라지는 tag 값 - const [textValue, setTextValue] = useState(""); - - /** react native 환경에서만 가능 */ - const onMessageHandler = (e) => { - const event = JSON.parse(e.data); - window.ReactNativeWebView.postMessage(JSON.stringify({ event: event })); - if (event.changeText) { - console.log(event.changeText); - setTextValue(event.changeText); - } - }; - - // tagChange - useEffect(() => { - const isUIWebView = () => { - return navigator.userAgent - .toLowerCase() - .match(/\(ip.*applewebkit(?!.*(version|crios))/); - }; - - const receiver = isUIWebView() ? window : document; - - receiver.addEventListener("message", onMessageHandler); - return () => { - receiver.removeEventListener("message", onMessageHandler); - }; - }); return ( diff --git a/yam-view/src/components/Data/markerData.js b/yam-view/src/components/Data/markerData.js index e546915..e50c8fb 100644 --- a/yam-view/src/components/Data/markerData.js +++ b/yam-view/src/components/Data/markerData.js @@ -1,6 +1,109 @@ // latitude : y축 // longitude : x축 +//template +// restaurantId: 1, +// restaurantName: "콜드스퀘어", // 이름 +// restaurantNumber: "010-1111-1111", // 전화번호 +// y_coordinate: 37.62197524055062, // 위도 +// x_coordinate: 127.16017523675508, // 경도 +// address: "대전광역시 00구 00동", +// heart: 3, +// category: "korea", +// menus: [ +// { +// menuId: 1, +// menuName: "비빔밥", +// price: 10000, +// category: "korea", +// menuNum: 0, +// }, +// ], +// OPEN_TIME: "오전 11:00 ~ 오후 11:00", +// SECTOR: "분식", +// MAIN_MENU: "돼지국밥, 돼지찜, 돼지전골", +// LAST_UPDATED: Date(), +// DATE_CREATED: Date(), +// +export const dummyData = [ + { + restaurantId: 1, + restaurantName: "한국집", // 이름 + restaurantNumber: "010-1111-1111", // 전화번호 + y_coordinate: 37.62197524055062, // 위도 + x_coordinate: 127.16017523675508, // 경도 + address: "대전광역시 00구 00동", + heart: 3, + category: "korea", + menus: [ + { + menuId: 1, + menuName: "비빔밥", + price: 10000, + category: "korea", + menuNum: 0, + }, + ], + }, + { + restaurantId: 1, + restaurantName: "카페", // 이름 + restaurantNumber: "010-1111-1111", // 전화번호 + y_coordinate: 37.62197524055062, // 위도 + x_coordinate: 127.16017523675508, // 경도 + address: "대전광역시 00구 00동", + heart: 3, + category: "cafe", + menus: [ + { + menuId: 1, + menuName: "비빔밥", + price: 10000, + category: "korea", + menuNum: 0, + }, + ], + }, + { + restaurantId: 1, + restaurantName: "일본집", // 이름 + restaurantNumber: "010-1111-1111", // 전화번호 + y_coordinate: 37.62197524055062, // 위도 + x_coordinate: 127.16017523675508, // 경도 + address: "대전광역시 00구 00동", + heart: 3, + category: "japan", + menus: [ + { + menuId: 1, + menuName: "비빔밥", + price: 10000, + category: "korea", + menuNum: 0, + }, + ], + }, + { + restaurantId: 1, + restaurantName: "중국집", // 이름 + restaurantNumber: "010-1111-1111", // 전화번호 + y_coordinate: 37.62197524055062, // 위도 + x_coordinate: 127.16017523675508, // 경도 + address: "대전광역시 00구 00동", + heart: 3, + category: "china", + menus: [ + { + menuId: 1, + menuName: "비빔밥", + price: 10000, + category: "korea", + menuNum: 0, + }, + ], + }, +]; + export const markerdata = [ { RESTARANT_ID: 1, diff --git a/yam-view/src/pages/WebView.js b/yam-view/src/pages/WebView.js index 3aec2c8..d83d6be 100644 --- a/yam-view/src/pages/WebView.js +++ b/yam-view/src/pages/WebView.js @@ -40,8 +40,33 @@ const requestPermission = () => { DATE_CREATED: Date(), */ const WebView = () => { + const [category, setCategory] = useState("전체"); + + /** react native 환경에서만 가능 */ + const onMessageHandler = (e) => { + const event = JSON.parse(e.data); + window.ReactNativeWebView.postMessage(JSON.stringify({ event: event })); + if (event.changeText) { + setCategory(event.changeText); + alert(event.changeText); + } + }; + useEffect(() => { mapscript(); + + const isUIWebView = () => { + return navigator.userAgent + .toLowerCase() + .match(/\(ip.*applewebkit(?!.*(version|crios))/); + }; + + const receiver = isUIWebView() ? window : document; + + receiver.addEventListener("message", onMessageHandler); + return () => { + receiver.removeEventListener("message", onMessageHandler); + }; }, []); const mapscript = () => { diff --git a/yam-view/src/utils/filterTag.js b/yam-view/src/utils/filterTag.js new file mode 100644 index 0000000..6d78272 --- /dev/null +++ b/yam-view/src/utils/filterTag.js @@ -0,0 +1,3 @@ +export const filterTag = (arr, tagList) => { + return arr.filter((item) => tagList.includes(item.tag)); +}; diff --git a/yam-view/src/utils/findCategory.js b/yam-view/src/utils/findCategory.js new file mode 100644 index 0000000..6b62805 --- /dev/null +++ b/yam-view/src/utils/findCategory.js @@ -0,0 +1,26 @@ +export const findCategory = (category) => { + switch (category) { + case "korea": + return "한식"; + case "japan": + return "일식"; + case "china": + return "중식"; + case "western": + return "양식"; + case "snack": + return "분식"; + case "fastfood": + return "패스트푸드"; + case "bakery": + return "베이커리"; + case "cafe": + return "카페"; + case "restaurant": + return "레스토랑"; + case "bar": + return "바"; + default: + return "기타"; + } +}; diff --git a/yam-view/src/utils/localMethod.js b/yam-view/src/utils/localMethod.js new file mode 100644 index 0000000..2b82a1f --- /dev/null +++ b/yam-view/src/utils/localMethod.js @@ -0,0 +1,28 @@ +export const getLocalStorage = (key) => { + try { + return JSON.parse(localStorage.getItem(key)); + } catch (e) { + return null; + } +}; +export const setLocalStorage = (key, value) => { + try { + localStorage.setItem(key, JSON.stringify(value)); + } catch (e) { + return null; + } +}; +export const removeLocalStorage = (key) => { + try { + localStorage.removeItem(key); + } catch (e) { + return null; + } +}; +export const clearLocalStorage = () => { + try { + localStorage.clear(); + } catch (e) { + return null; + } +};