From df3989fea3edce78a43a4cb660a62aedfec7ddc2 Mon Sep 17 00:00:00 2001 From: yonghyon Date: Tue, 13 Feb 2024 19:16:40 +0900 Subject: [PATCH] debug key --- .../src/actions/actionTypes.js | 1 + .../src/actions/commonActions.js | 7 +- com.twin.app.shoptime/src/api/TAxios.js | 16 ++-- com.twin.app.shoptime/src/api/apiConfig.js | 54 ++++++++++++- .../src/components/TabLayout/TabLayout.jsx | 8 +- .../src/hooks/useDebugKey.js | 40 +++++++++ com.twin.app.shoptime/src/lunaSend/common.js | 1 + .../src/reducers/commonReducer.js | 1 + .../src/reducers/localSettingsReducer.js | 32 ++++++++ .../src/reducers/panelReducer.js | 3 +- com.twin.app.shoptime/src/store/store.js | 2 + com.twin.app.shoptime/src/utils/Config.js | 4 +- .../src/utils/helperMethods.js | 14 ++++ .../src/views/DebugPanel/DebugPanel.jsx | 81 ++++++++++++++++++- .../views/DebugPanel/DebugPanel.module.less | 72 +++++++++++++++++ .../src/views/ErrorPanel/ErrorPanel.jsx | 4 +- .../src/views/HomePanel/HomePanel.jsx | 2 + .../src/views/IntroPanel/IntroPanel.jsx | 2 + 18 files changed, 325 insertions(+), 19 deletions(-) create mode 100644 com.twin.app.shoptime/src/hooks/useDebugKey.js create mode 100644 com.twin.app.shoptime/src/reducers/localSettingsReducer.js diff --git a/com.twin.app.shoptime/src/actions/actionTypes.js b/com.twin.app.shoptime/src/actions/actionTypes.js index 434e56e3..83f7fc44 100644 --- a/com.twin.app.shoptime/src/actions/actionTypes.js +++ b/com.twin.app.shoptime/src/actions/actionTypes.js @@ -12,6 +12,7 @@ export const types = { // common actions GET_HTTP_HEADER: "GET_HTTP_HEADER", CHANGE_APP_STATUS: "CHANGE_APP_STATUS", + CHANGE_LOCAL_SETTINGS: "CHANGE_LOCAL_SETTINGS", // appData actions ADD_MAIN_INDEX: "ADD_MAIN_INDEX", diff --git a/com.twin.app.shoptime/src/actions/commonActions.js b/com.twin.app.shoptime/src/actions/commonActions.js index 4e36955c..3ee062c9 100644 --- a/com.twin.app.shoptime/src/actions/commonActions.js +++ b/com.twin.app.shoptime/src/actions/commonActions.js @@ -7,6 +7,11 @@ export const changeAppStatus = (status) => ({ payload: status, }); +export const changeLocalSettings = (status) => ({ + type: types.CHANGE_LOCAL_SETTINGS, + payload: status +}); + export const getHttpHeaderForServiceRequest = onComplete => (dispatch, getState) => { console.log('getHttpHeaderForServiceRequest '); lunaSend.getHttpHeaderForServiceRequest({ @@ -42,7 +47,7 @@ export const getHttpHeaderForServiceRequest = onComplete => (dispatch, getState) const version = res["X-Device-Netcast-Platform-Version"] || ""; convertedRes["os_ver"] = version; dispatch({ type: types.GET_HTTP_HEADER, payload: convertedRes }); - dispatch(changeAppStatus({webOSVersion: version.substring(0,version.lastIndexOf('.'))})); + dispatch(changeAppStatus({webOSVersion: version.substring(0,version.lastIndexOf('.')), serverHOST: res["HOST"]})); }, onFailure: (err) => { console.log("getHttpHeaderForServiceRequest fail",err); diff --git a/com.twin.app.shoptime/src/api/TAxios.js b/com.twin.app.shoptime/src/api/TAxios.js index 71e49a52..9d0c3dba 100644 --- a/com.twin.app.shoptime/src/api/TAxios.js +++ b/com.twin.app.shoptime/src/api/TAxios.js @@ -103,7 +103,8 @@ export const TAxios = ( }); }; - const executeRequest = (accessToken, httpHeader) => { + const executeRequest = (accessToken, getState) => { + const httpHeader = getState().common.httpHeader; const AUTHORIZATION = { headers: {...httpHeader} }; if (accessToken) { @@ -111,8 +112,12 @@ export const TAxios = ( } if (typeof window === "object") { - let url = Array.isArray(baseUrl) ? getUrl(baseUrl[0]) : getUrl(baseUrl); + let url = Array.isArray(baseUrl) ? getUrl(getState, baseUrl[0]) : getUrl(getState, baseUrl); + if(!url){ + //todo error page + return; + } if (type === "get") { const _urlparams = HelperMethods.createQueryString(urlParams); url += url ? `?${_urlparams}` : ""; @@ -146,12 +151,13 @@ export const TAxios = ( checkAccessToken().then((accessToken) => { if (!noTokenRefresh) { tokenRefresh(dispatch, getState) - .then(() => executeRequest(accessToken, getState().common.httpHeader)) - .catch(() => { + .then(() => executeRequest(accessToken, getState)) + .catch((e) => { /* 토큰 갱신 실패 처리 */ + console.error('tokenRefresh error', e); }); } else { - executeRequest(accessToken, getState().common.httpHeader); + executeRequest(accessToken, getState); } }); }; diff --git a/com.twin.app.shoptime/src/api/apiConfig.js b/com.twin.app.shoptime/src/api/apiConfig.js index b74d06e1..cb3efff4 100644 --- a/com.twin.app.shoptime/src/api/apiConfig.js +++ b/com.twin.app.shoptime/src/api/apiConfig.js @@ -1,4 +1,5 @@ -export const SHOPTIME_BASE_URL = "https://qt3-aic.lgshopsvc.lgappstv.com/"; +// export const SHOPTIME_BASE_URL = "https://qt3-aic.lgshopsvc.lgappstv.com/"; +export const SHOPTIME_BASE_URL = ".lgshopsvc.lgappstv.com/"; export const URLS = { //device controller @@ -50,7 +51,52 @@ export const URLS = { //event controller GET_WELCOME_EVENT_INFO: "/lgsp/v1/event/event.lge", }; - -export const getUrl = (endStr) => { - return SHOPTIME_BASE_URL + endStr; +const getRicCode = (country, ricCodeSetting) =>{ + if(ricCodeSetting !== 'system'){ + return ricCodeSetting; + } + if (country == "US") { + return "aic"; + } else if (country == "DE" || country == "GB") { + return "eic"; + } else if (country == "RU") { + return "ruc"; + } + return null; +} +export const getUrl = (getState, endStr) => { + const serverHOST = getState().common.appStatus.serverHOST; + const {serverType, ricCodeSetting} = getState().localSettings; + if(!serverHOST){ + console.error('getUrl: Not supported. Host is missing'); + return ""; + } + let sdpURL = serverHOST.split(".")[0]; + let countryCode = "", ricCode=""; + if (sdpURL.indexOf("-") > 0) { + countryCode = sdpURL.split("-")[1]; + } else { + countryCode = sdpURL; + } + ricCode = getRicCode(countryCode, ricCodeSetting); + if(!ricCode){ + return ""; + } + sdpURL = sdpURL.toLowerCase(); + if(serverType !== 'system'){ + sdpURL = serverType; + } + let newUrl = ""; + if (sdpURL.indexOf("qt2") >= 0) { + // dev + newUrl = "https://qt3-" + ricCode + SHOPTIME_BASE_URL; + //"https://qt3-aic.lgshopsvc.lgappstv.com/"; + } else if (sdpURL.indexOf("qt") >= 0) { + // Qa - cdn + newUrl = "https://qt-" + ricCode + SHOPTIME_BASE_URL; + } else { + // Prod + newUrl = "https://" + ricCode + SHOPTIME_BASE_URL; + } + return newUrl + endStr; }; diff --git a/com.twin.app.shoptime/src/components/TabLayout/TabLayout.jsx b/com.twin.app.shoptime/src/components/TabLayout/TabLayout.jsx index 8c850201..3dd7855d 100644 --- a/com.twin.app.shoptime/src/components/TabLayout/TabLayout.jsx +++ b/com.twin.app.shoptime/src/components/TabLayout/TabLayout.jsx @@ -172,7 +172,7 @@ export default function TabLayout({ topPanelName, onTabActivated }) { switch (type) { case "Category": - result = data?.homeCategory.map((item) => ({ + result = data?.homeCategory && data.homeCategory.map((item) => ({ id: item.lgCatCd, title: item.lgCatNm, target: [ @@ -188,13 +188,13 @@ export default function TabLayout({ topPanelName, onTabActivated }) { })); break; case "GNB": - result = data?.gnb.map((item) => ({ + result = data?.gnb && data.gnb.map((item) => ({ title: item.menuNm, })); break; case "Featured Brands": - result = data?.shortFeaturedBrands.map((item) => ({ + result = data?.shortFeaturedBrands && data.shortFeaturedBrands.map((item) => ({ Id: item.patnrId, path: item.patncLogoPath, target: [ @@ -206,7 +206,7 @@ export default function TabLayout({ topPanelName, onTabActivated }) { })); break; case "My Page": - result = data?.mypage.map((item) => ({ + result = data?.mypage && data.mypage.map((item) => ({ title: item.menuNm, target: [ { diff --git a/com.twin.app.shoptime/src/hooks/useDebugKey.js b/com.twin.app.shoptime/src/hooks/useDebugKey.js new file mode 100644 index 00000000..bbfb3813 --- /dev/null +++ b/com.twin.app.shoptime/src/hooks/useDebugKey.js @@ -0,0 +1,40 @@ +import { useRef, useCallback, useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import * as Config from "../utils/Config"; +import { on, off } from "@enact/core/dispatcher"; +import { pushPanel } from "../actions/panelActions"; + +const useDebugKey = ({isLandingPage=false}) => { + const panels = useSelector((state) => state.panels.panels); + const debugKey = useRef([]); + const dispatch = useDispatch(); + + const handleKeydown = useCallback( + (ev) => { + if (isLandingPage && panels && panels.length > 0) { + return; + } + if (ev && ev.key >= 0 && ev.key <= 9) { + if (debugKey.current.length >= Config.DEBUG_KEY.length) { + debugKey.current.shift(); + } + debugKey.current.push(String(ev.key)); + if (debugKey.current.join("") === Config.DEBUG_KEY) { + debugKey.current = []; + dispatch(pushPanel({ name: Config.panel_names.DEBUG_PANEL, panelInfo: {} })); + } + } + }, + [panels, dispatch, isLandingPage] + ); + + useEffect(() => { + on("keydown", handleKeydown); + return () => { + off("keydown", handleKeydown); + }; + }, [handleKeydown]); + +}; + +export default useDebugKey; \ No newline at end of file diff --git a/com.twin.app.shoptime/src/lunaSend/common.js b/com.twin.app.shoptime/src/lunaSend/common.js index 430c4da0..ca009e4d 100644 --- a/com.twin.app.shoptime/src/lunaSend/common.js +++ b/com.twin.app.shoptime/src/lunaSend/common.js @@ -62,6 +62,7 @@ export const getHttpHeaderForServiceRequest = ({onSuccess, onFailure, onComplete } }else{ onSuccess({ + "HOST": "US.nextlgsdp.com", "Authorization": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJuZXh0bGdzZHAuY29tIiwiYXVkIjoibmV4dGxnc2RwLmNvbSIsImlhdCI6MTcwNzc4NTUyNSwiZXhwIjoxNzA3NzkyNzI1LCJtYWNBZGRyZXNzIjoiZWVkMDQ2NjdiNjUzOWU3YmQxMDA1OTljYjBkYTI5ZjRjZTgyZGZlOGZkNzIzMDAxZGVmMjg4NWRkNWZiODRmNWNiMzZlM2QwNzYzNWZjZGJjYWNjNGVjMzI5NWIwNjZjOTMwNmNmNDI1ZGQzMmQ2MDMxMjc1NWNkOTIyNjEwMzcifQ.vqPdYGnN46diesDBLzA4UhACCJVdIycLs7wZu9M55Hc", "X-Authentication": "MkOLvUocrJ69RH/iV1ZABJhjR2g=", "X-Device-ID": "OemUY5qbPITZv96QKlxrtcqT6ypeX6us2qANLng3/0QCUhv2mecK1UDTMYb/hjpjey9dC/kFycc/5R8u+oK56JIWyYC4V278z64YDPKbDXIsd+eECvyf+Rdm8BneIUPM", diff --git a/com.twin.app.shoptime/src/reducers/commonReducer.js b/com.twin.app.shoptime/src/reducers/commonReducer.js index 39f002a0..a125059c 100644 --- a/com.twin.app.shoptime/src/reducers/commonReducer.js +++ b/com.twin.app.shoptime/src/reducers/commonReducer.js @@ -5,6 +5,7 @@ const initialState = { showLoadingPanel: { show: true, type: "launching" }, isLoading: true, webOSVersion:"", //"5.0", "9.0" ... + serverHOST: "", //"US.nextlgsdp.com", cursorVisible: false }, httpHeader: null diff --git a/com.twin.app.shoptime/src/reducers/localSettingsReducer.js b/com.twin.app.shoptime/src/reducers/localSettingsReducer.js new file mode 100644 index 00000000..0649e18b --- /dev/null +++ b/com.twin.app.shoptime/src/reducers/localSettingsReducer.js @@ -0,0 +1,32 @@ +import { types } from "../actions/actionTypes"; +import { readLocalStorage, writeLocalStorage } from "../utils/helperMethods"; +import * as Config from "../utils/Config"; + +const initialLocalSettings = { + serverType: Config.DEFAULT_SERVERTYPE, + ricCodeSetting: Config.DEFAULT_RIC_CODE +}; + +const updateInitialLocalSettings = () => { + const data = readLocalStorage('localSettings',initialLocalSettings); + if( Object.keys(data).length !== Object.keys(initialLocalSettings).length){ + writeLocalStorage('localSettings', initialLocalSettings); + return initialLocalSettings; + }else{ + return data; + } +}; + +export const localSettingsReducer = (state = updateInitialLocalSettings(), action) => { + switch (action.type) { + case types.CHANGE_LOCAL_SETTINGS: { + const newState = Object.assign({}, state, action.payload); + writeLocalStorage('localSettings', newState); + return newState; + } + default: + return state; + } +}; + +export default localSettingsReducer; diff --git a/com.twin.app.shoptime/src/reducers/panelReducer.js b/com.twin.app.shoptime/src/reducers/panelReducer.js index fde68ea3..eb23f66b 100644 --- a/com.twin.app.shoptime/src/reducers/panelReducer.js +++ b/com.twin.app.shoptime/src/reducers/panelReducer.js @@ -6,10 +6,11 @@ const initialState = { isModalOpen: false, }; +// last one will be on top const forceTopPanels = [ panel_names.ERROR_PANEL, - panel_names.DEBUG_PANEL, panel_names.INTRO_PANEL, + panel_names.DEBUG_PANEL, ]; export const panelsReducer = (state = initialState, action) => { diff --git a/com.twin.app.shoptime/src/store/store.js b/com.twin.app.shoptime/src/store/store.js index 7640e679..fc2c2dc7 100644 --- a/com.twin.app.shoptime/src/store/store.js +++ b/com.twin.app.shoptime/src/store/store.js @@ -4,6 +4,7 @@ import thunk from "redux-thunk"; import { appDataReducer } from "../reducers/appDataReducer"; import { brandReducer } from "../reducers/brandReducer"; import { commonReducer } from "../reducers/commonReducer"; +import { localSettingsReducer } from "../reducers/localSettingsReducer"; import { deviceReducer } from "../reducers/deviceReducer"; import { eventReducer } from "../reducers/eventReducer"; import { homeReducer } from "../reducers/homeReducer"; @@ -18,6 +19,7 @@ const rootReducer = combineReducers({ panels: panelsReducer, device: deviceReducer, common: commonReducer, + localSettings: localSettingsReducer, appData: appDataReducer, home: homeReducer, brand: brandReducer, diff --git a/com.twin.app.shoptime/src/utils/Config.js b/com.twin.app.shoptime/src/utils/Config.js index aeb2a6ab..77e0393d 100644 --- a/com.twin.app.shoptime/src/utils/Config.js +++ b/com.twin.app.shoptime/src/utils/Config.js @@ -5,8 +5,8 @@ export const DEBUG_KEY = "5286"; export const TESTPANEL_KEY = "5325"; export const SFT_TEST = "5555"; export const SFT_TEST2 = "6666"; -export const ACTIVITY_SCENERY = "8282"; - +export const DEFAULT_SERVERTYPE = "qt2"; //system, qt2, qt, prd +export const DEFAULT_RIC_CODE = 'aic'; //system, aic, eic, ruc export const panel_names = { INTRO_PANEL: "intropanel", HOME_PANEL: "homepanel", diff --git a/com.twin.app.shoptime/src/utils/helperMethods.js b/com.twin.app.shoptime/src/utils/helperMethods.js index ddad37ad..9de46896 100644 --- a/com.twin.app.shoptime/src/utils/helperMethods.js +++ b/com.twin.app.shoptime/src/utils/helperMethods.js @@ -121,4 +121,18 @@ export const clearLaunchParams = () => { }else{ localLaunchParams = {}; } +}; + +export const readLocalStorage = (key, defaultValue) => { + const value = typeof window === 'object' && window.localStorage.getItem(key); + if (!value && defaultValue !== undefined) { + return defaultValue; + } + return value === 'undefined' ? null : JSON.parse(value); +}; + +export const writeLocalStorage = (key, value) => { + if (typeof window === 'object') { + window.localStorage.setItem(key, JSON.stringify(value)); + } }; \ No newline at end of file diff --git a/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.jsx b/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.jsx index cf560eed..3ba76d50 100644 --- a/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.jsx +++ b/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.jsx @@ -1,5 +1,84 @@ +import React, { useCallback, useMemo } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import SpotlightContainerDecorator from "@enact/spotlight/SpotlightContainerDecorator"; +import RadioItem from '@enact/sandstone/RadioItem'; +import css from "./DebugPanel.module.less"; import TPanel from "../../components/TPanel/TPanel"; +import THeader from "../../components/THeader/THeader"; +import appinfo from '../../../webos-meta/appinfo.json'; +import TScroller from "../../components/TScroller/TScroller"; +import { changeLocalSettings } from "../../actions/commonActions"; + +const Container = SpotlightContainerDecorator({ enterTo: "last-focused" }, "div"); export default function DebugPanel() { - return Debug; + const dispatch = useDispatch(); + const appStatus = useSelector((state) => state.common.appStatus); + const httpHeader = useSelector((state) => state.common.httpHeader); + const localSettings = useSelector((state) => state.localSettings); + const infos = useMemo(() => { + let v = []; + v.push({title: 'Version(App)', value: appinfo.version}); + v.push({title: 'WebOS', value: appStatus.webOSVersion+"("+httpHeader?.os_ver+")"}); + v.push({title: ' ', value: ' '}); + return v; + }, [appStatus, httpHeader]); + + const onChangeServer = useCallback((type) => () => { + if(type === localSettings.serverType){ + return; + }else{ + dispatch(changeLocalSettings({ serverType: type, ricCodeSetting: 'system' })); + } + }, [dispatch, localSettings]); + + const onChangeServerRic = useCallback((type) => () => { + dispatch(changeLocalSettings({ ricCodeSetting: type })); + if(typeof window === 'object'){ + window.location.reload(); + } + }, [dispatch, localSettings]); + + const disabledRic = useMemo(()=>{ + return false;//localSettings.serverType !== 'prd'; + },[localSettings]); + + return + + {infos.map((item, index) => + {return( +
+
+
{item.title}
+
+
+
{item.value}
+
+
+ ) + } + )} + + + +
+ {'Server'} + system + qt2(qt3) + qt + prd +
+
+ +
+ {'RicCode(Reboot)'} + system + aic + eic + ruc +
+
+
+
+
; } diff --git a/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.module.less b/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.module.less index e69de29b..0289c206 100644 --- a/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.module.less +++ b/com.twin.app.shoptime/src/views/DebugPanel/DebugPanel.module.less @@ -0,0 +1,72 @@ +.scroller{ + height:650px; + } + .settingLayer{ + width: 100%; + height: auto; + padding-bottom: 30px; + } +.titleArea { + position: relative; + display: block; + color: black; + font-size: 28px; + .titleBox { + position: relative; + display: inline-block; + width: 420px; + height: auto; + left: 75px; + top: 0rem; + .text { + position: relative; + top: 0rem; + text-align: start; + margin-top: 13px; + font-weight: bold; + } + } + .textArea { + position: relative; + display: inline-block; + width: 1000px; + height: auto; + left: 60px; + background-color: rgba(174, 0, 255, 0.0); + .text { + position: relative; + color: rgb(252, 252, 252); + text-align: start; + margin-top: 13px; + color: black; + } + } + .title { + position: relative; + width:100%; + text-align: center; + font-size: 36px; + font-weight: 'bold'; + } + .switchs { + position: relative; + display: inline-flex; + width: 100%; + .switchTitle { + position: relative; + width: 660px; + height: 72px; + line-height: 72px; + margin-left: 75px; + font-size: 30px; + font-weight: bold; + color: black; + background-color: bisque; + } + .switch{ + width: 250px; + color: black; + margin-bottom: 0px; + } + } + } \ No newline at end of file diff --git a/com.twin.app.shoptime/src/views/ErrorPanel/ErrorPanel.jsx b/com.twin.app.shoptime/src/views/ErrorPanel/ErrorPanel.jsx index 660aaddb..567ff20d 100644 --- a/com.twin.app.shoptime/src/views/ErrorPanel/ErrorPanel.jsx +++ b/com.twin.app.shoptime/src/views/ErrorPanel/ErrorPanel.jsx @@ -1,5 +1,7 @@ +import React from "react"; import TPanel from "../../components/TPanel/TPanel"; - +import useDebugKey from '../../hooks/useDebugKey'; export default function ErrorPanel() { + useDebugKey({}); return Error; } diff --git a/com.twin.app.shoptime/src/views/HomePanel/HomePanel.jsx b/com.twin.app.shoptime/src/views/HomePanel/HomePanel.jsx index 54aca8ba..280a3f28 100644 --- a/com.twin.app.shoptime/src/views/HomePanel/HomePanel.jsx +++ b/com.twin.app.shoptime/src/views/HomePanel/HomePanel.jsx @@ -18,9 +18,11 @@ import HomeOnSale from '../HomePanel/HomeOnSale/HomeOnSale'; import css from '../HomePanel/HomePanel.module.less'; import PopularShow from '../HomePanel/PopularShow/PopularShow'; import SubCategory from '../HomePanel/SubCategory/SubCategory'; +import useDebugKey from '../../hooks/useDebugKey'; export default function HomePanel() { const dispatch = useDispatch(); + useDebugKey({isLandingPage: true}); const homeLayoutInfo = useSelector((state) => state.home.layoutData); const homeTopDisplayInfos = useSelector( (state) => state.home.mainContentsData.homeTopDisplayInfos diff --git a/com.twin.app.shoptime/src/views/IntroPanel/IntroPanel.jsx b/com.twin.app.shoptime/src/views/IntroPanel/IntroPanel.jsx index ab8cca15..55396313 100644 --- a/com.twin.app.shoptime/src/views/IntroPanel/IntroPanel.jsx +++ b/com.twin.app.shoptime/src/views/IntroPanel/IntroPanel.jsx @@ -13,6 +13,7 @@ import TPopUp from "../../components/TPopUp/TPopUp"; import * as Config from "../../utils/Config"; import { $L } from "../../utils/helperMethods"; import css from "./IntroPanel.module.less"; +import useDebugKey from '../../hooks/useDebugKey'; const Container = SpotlightContainerDecorator( { enterTo: "last-focused" }, @@ -21,6 +22,7 @@ const Container = SpotlightContainerDecorator( export default function IntroPanel({ children, ...rest }) { const dispatch = useDispatch(); + useDebugKey({}); const termsData = useSelector((state) => state.home.termsData); const [showExitButton, setShowExitButton] = useState(false);