From acfcf2130252e10a1b9d4188d0211d6332a14e65 Mon Sep 17 00:00:00 2001 From: Fatemeh sh Date: Fri, 11 Apr 2025 12:51:20 +0330 Subject: [PATCH 1/3] add standard naming tools --- src/Data/constants.data.ts | 16 ++++++++++++++++ src/Tools/Utils/Standardize.ts | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 src/Tools/Utils/Standardize.ts diff --git a/src/Data/constants.data.ts b/src/Data/constants.data.ts index 45da0aa..d3029c0 100644 --- a/src/Data/constants.data.ts +++ b/src/Data/constants.data.ts @@ -15,6 +15,22 @@ export enum ServiceName { HackerNews = 'Hacker News', } +export const standardNaming: { [key: string]: string } = { + x: ServiceName.X, + email: ServiceName.Email, + gmail: ServiceName.Gmail, + reddit: ServiceName.Reddit, + trello: ServiceName.Trello, + blogger: ServiceName.Blogger, + yahoo_mail: ServiceName.Yahoo, + telegram: ServiceName.Telegram, + whatsapp: ServiceName.Whatsapp, + facebook: ServiceName.Facebook, + linkedin: ServiceName.Linkedin, + custom_share: ServiceName.Custom, + hacker_news: ServiceName.HackerNews, +}; + export enum SharingMode { Direct = 'direct', Indirect = 'indirect', diff --git a/src/Tools/Utils/Standardize.ts b/src/Tools/Utils/Standardize.ts new file mode 100644 index 0000000..7a83674 --- /dev/null +++ b/src/Tools/Utils/Standardize.ts @@ -0,0 +1,3 @@ +export const toStandardName = (service_name: string) => { + return service_name.toLowerCase().replace(' ', '_'); +}; From fc7352064ee7a5bb967d4eb5090159cd31560594 Mon Sep 17 00:00:00 2001 From: Fatemeh sh Date: Fri, 11 Apr 2025 12:53:02 +0330 Subject: [PATCH 2/3] add standard naming in `ShareModal` & `Share` & `GetButton` pages --- src/Views/Layout/ShareModal/index.tsx | 4 +++- src/Views/Pages/GetButton/index.tsx | 11 ++++------- src/Views/Pages/Share/index.tsx | 5 ++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Views/Layout/ShareModal/index.tsx b/src/Views/Layout/ShareModal/index.tsx index d25072f..30d092b 100644 --- a/src/Views/Layout/ShareModal/index.tsx +++ b/src/Views/Layout/ShareModal/index.tsx @@ -10,6 +10,7 @@ import { useLocalCache, setShareModal } from '@src/Tools/Store/slices/LocalCache import { Checkbox, CheckboxGroup, Col, Modal, Radio, RadioGroup, Row, Tooltip, Whisper } from 'rsuite'; import { useData } from '@src/Tools/Hooks/useData'; import { ServiceName } from '@src/Data/constants.data'; +import { toStandardName } from '@src/Tools/Utils/Standardize'; const ShareModal = () => { const { dispatch } = useStore(); @@ -38,7 +39,8 @@ const ShareModal = () => { }; const getShareLink = (service_title: string, url: string) => { - const path = `?path=share&service=${service_title}&subject=${temp.subject}&link=${url}`; + const serviceName = toStandardName(service_title); + const path = `?path=share&service=${serviceName}&subject=${temp.subject}&link=${url}`; if (temp.encodingValue?.length) { const encoded_path = encode(path); return `${CONFIG.FRONT_DOMAIN}/?encoded=${encoded_path}`; diff --git a/src/Views/Pages/GetButton/index.tsx b/src/Views/Pages/GetButton/index.tsx index 02a3244..377f837 100644 --- a/src/Views/Pages/GetButton/index.tsx +++ b/src/Views/Pages/GetButton/index.tsx @@ -17,6 +17,7 @@ import { setShareModal } from '@src/Tools/Store/slices/LocalCacheSlice'; import { lightfair } from 'react-syntax-highlighter/dist/esm/styles/hljs'; import { ReactComponent as Clone } from '@assets/icons/clone-regular.svg'; import { Button, Checkbox, CheckboxGroup, Col, Modal, Radio, RadioGroup, Row, Tooltip, Whisper } from 'rsuite'; +import { toStandardName } from '@src/Tools/Utils/Standardize'; const GetButton = () => { const { isMobile } = useWindow(); @@ -49,7 +50,8 @@ const GetButton = () => { }; const getShareLink = (service_title: string, url: string) => { - const path = `?path=share&service=${service_title}&subject=${temp.subject}&link=${url}`; + const serviceName = toStandardName(service_title); + const path = `?path=share&service=${serviceName}&subject=${temp.subject}&link=${url}`; if (!!temp.encodingValue?.[0]) { const encoded_path = encode(path); return `${CONFIG.FRONT_DOMAIN}/?encoded=${encoded_path}`; @@ -262,12 +264,7 @@ const GetButton = () => { const checked = selectedServices.includes(service.title); return ( - + ); })} diff --git a/src/Views/Pages/Share/index.tsx b/src/Views/Pages/Share/index.tsx index 7f27c8e..25f31d5 100644 --- a/src/Views/Pages/Share/index.tsx +++ b/src/Views/Pages/Share/index.tsx @@ -4,6 +4,8 @@ import { useLocation } from 'react-router-dom'; import LoadingCover from '@src/Components/LoadingCover'; import { getServiceURL } from '@src/Data/services.data'; import { decode } from '@src/Tools/Utils/URLEncoding'; +import { toStandardName } from '@src/Tools/Utils/Standardize'; +import { standardNaming } from '@data/constants.data'; const Share = () => { const location = useLocation(); @@ -18,7 +20,8 @@ const Share = () => { const subject = urlParams.get('subject') || ''; const link = urlParams.get('link') || ''; - const url = getServiceURL(encodeURIComponent(link), subject)[service]; + const serviceName = standardNaming[toStandardName(service)]; + const url = getServiceURL(encodeURIComponent(link), subject)[serviceName]; setTimeout(() => { window.open(url, '_self'); }, 100); From 368e6dfafd8d1540ac762093153b047967ff733c Mon Sep 17 00:00:00 2001 From: Fatemeh sh Date: Fri, 11 Apr 2025 12:54:02 +0330 Subject: [PATCH 3/3] update `blacklist` in redux --- src/Tools/Store/slices/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tools/Store/slices/index.ts b/src/Tools/Store/slices/index.ts index 322fa78..312df1c 100644 --- a/src/Tools/Store/slices/index.ts +++ b/src/Tools/Store/slices/index.ts @@ -13,7 +13,7 @@ const reducers = combineReducers({ storage, key: 'storage', keyPrefix: `${CONFIG.APP_SHORT_NAME}-`, - blacklist: ['openShareModal', 'activePage'], + blacklist: ['shareModal', 'activePage'], transforms: [compressor] as any, }, LocalCacheReducer.reducer