Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/naming #65

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add `ServiceName` enum
### Changed
- Update naming conventions
## [0.5] - 2025-01-15
### Added
- Support `Reddit`
Expand Down
16 changes: 16 additions & 0 deletions src/Data/constants.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export enum ServiceName {
X = 'X',
Email = 'Email',
Gmail = 'Gmail',
Reddit = 'Reddit',
Trello = 'Trello',
Blogger = 'Blogger',
Yahoo = 'Yahoo Mail',
Telegram = 'Telegram',
Whatsapp = 'WhatsApp',
Facebook = 'Facebook',
Linkedin = 'LinkedIn',
Custom = 'Custom Share',
Pinterest = 'Pinterest',
HackerNews = 'Hacker News',
}
57 changes: 29 additions & 28 deletions src/Data/services.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,100 +11,101 @@ import Facebook from '@assets/icons/services/facebook.svg';
import Linkedin from '@assets/icons/services/linkedin.svg';
import Pinterest from '@assets/icons/services/pinterest.svg';
import HackerNews from '@assets/icons/services/hacker-news.svg';
import { ServiceName } from './constants.data';

export const services_url = (url: string, subject?: string): { [key: string]: string } => {
export const serviceUrls = (url: string, subject?: string): { [key: string]: string } => {
Copy link
Member

@AHReccese AHReccese Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use SERVICE_URL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this constant is indeed a function (processes input and the result varies depending on the input), wouldn't it be better to use the lowerCamelCase style?

Copy link
Member

@AHReccese AHReccese Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go with getServiceURL
@F-Shahali

return {
Email: `mailto:?subject=${subject}&body=${url}`,
Gmail: `https://mail.google.com/mail/u/0/?ui=2&fs=1&tf=cm&su=${subject}&body=${url}`,
Telegram: `https://telegram.me/share/url?url=${url}&text=${subject}`,
X: `https://x.com/intent/post?url=${url}&text=${subject}`,
WhatsApp: `https://api.whatsapp.com/send?text=${subject}%20${url}`,
'Yahoo Mail': `http://compose.mail.yahoo.com/?subject=${subject}&body=${url}`,
'Hacker News': `https://news.ycombinator.com/submitlink?u=${url}&t=${subject}`,
Facebook: `https://www.facebook.com/sharer/sharer.php?u=${url}&t=${subject}`,
LinkedIn: `https://www.linkedin.com/shareArticle?mini=true&url=${url}&text=${subject}`,
Reddit: `https://www.reddit.com/submit?url=${url}&title=${subject}`,
Pinterest: `https://www.pinterest.com/pin/create/button/?url=${url}&media=&description=${subject}`,
Blogger: `https://www.blogger.com/blog_this.pyra?u=${url}&n=${subject}&t&pli=1`,
Trello: `https://trello.com/add-card?name=${subject}&desc=${url}`,
[ServiceName.Email]: `mailto:?subject=${subject}&body=${url}`,
[ServiceName.Gmail]: `https://mail.google.com/mail/u/0/?ui=2&fs=1&tf=cm&su=${subject}&body=${url}`,
[ServiceName.Telegram]: `https://telegram.me/share/url?url=${url}&text=${subject}`,
[ServiceName.X]: `https://x.com/intent/post?url=${url}&text=${subject}`,
[ServiceName.Whatsapp]: `https://api.whatsapp.com/send?text=${subject}%20${url}`,
[ServiceName.Yahoo]: `http://compose.mail.yahoo.com/?subject=${subject}&body=${url}`,
[ServiceName.HackerNews]: `https://news.ycombinator.com/submitlink?u=${url}&t=${subject}`,
[ServiceName.Facebook]: `https://www.facebook.com/sharer/sharer.php?u=${url}&t=${subject}`,
[ServiceName.Linkedin]: `https://www.linkedin.com/shareArticle?mini=true&url=${url}&text=${subject}`,
[ServiceName.Reddit]: `https://www.reddit.com/submit?url=${url}&title=${subject}`,
[ServiceName.Pinterest]: `https://www.pinterest.com/pin/create/button/?url=${url}&media=&description=${subject}`,
[ServiceName.Blogger]: `https://www.blogger.com/blog_this.pyra?u=${url}&n=${subject}&t&pli=1`,
[ServiceName.Trello]: `https://trello.com/add-card?name=${subject}&desc=${url}`,
};
};

export const Services = [
export const services = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SERVICES

{
title: 'Email',
title: ServiceName.Email,
icon: Email,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/email.svg',
bg: '#888990',
},
{
title: 'Gmail',
title: ServiceName.Gmail,
icon: Gmail,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/gmail.svg',
bg: '#EA4335',
},
{
title: 'Telegram',
title: ServiceName.Telegram,
icon: Telegram,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/telegram.svg',
bg: '#2CA5E0',
},
{
title: 'X',
title: ServiceName.X,
icon: X,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/x.svg',
bg: '#1A1A1A',
},
{
title: 'WhatsApp',
title: ServiceName.Whatsapp,
icon: Whatsapp,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/whatsapp.svg',
bg: '#12AF0A',
},
{
title: 'Yahoo Mail',
title: ServiceName.Yahoo,
icon: Yahoo,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/yahoo.svg',
bg: '#400090',
},
{
title: 'Hacker News',
title: ServiceName.HackerNews,
icon: HackerNews,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/hacker-news.svg',
bg: '#ff6600',
},
{
title: 'Facebook',
title: ServiceName.Facebook,
icon: Facebook,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/facebook.svg',
bg: '#0866ff',
},
{
title: 'LinkedIn',
title: ServiceName.Linkedin,
icon: Linkedin,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/linkedin.svg',
bg: '#007bb5',
},
{
title: 'Reddit',
title: ServiceName.Reddit,
icon: Reddit,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/reddit.svg',
bg: '#ff4500',
},
{
title: 'Pinterest',
title: ServiceName.Pinterest,
icon: Pinterest,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/pinterest.svg',
bg: '#e60023',
},
{
title: 'Blogger',
title: ServiceName.Blogger,
icon: Blogger,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/blogger.svg',
bg: '#fda352',
},
{
title: 'Trello',
title: ServiceName.Trello,
icon: Trello,
iconUrl: 'https://github.com/openscilab/mybutton/raw/main/src/Assets/icons/services/trello.svg',
bg: '#0079bf',
Expand Down
6 changes: 3 additions & 3 deletions src/Views/Layout/ShareModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useStore from '@src/Tools/Store/useStore';
import { classes } from '@src/Tools/Utils/React';
import { CONFIG } from '@src/App/Config/constants';
import { encode } from '@src/Tools/Utils/URLEncoding';
import { Services, services_url } from '@src/Data/services.data';
import { services, serviceUrls } from '@src/Data/services.data';
import EditableInput from '@src/Components/EditableInput/EditableInput';
import { setOpenShareModal, useLocalCache } from '@src/Tools/Store/slices/LocalCacheSlice';
import { Checkbox, CheckboxGroup, Col, Modal, Radio, RadioGroup, Row, Tooltip, Whisper } from 'rsuite';
Expand Down Expand Up @@ -122,11 +122,11 @@ const ShareModal = () => {
</div>
<div className='services-list'>
<Row>
{Services.map((service, i) => {
{services.map((service, i) => {
const validated_url = urlValidation(temp.url);
const href =
temp.shareMode === 'direct'
? services_url(validated_url, temp.subject)[service.title]
? serviceUrls(validated_url, temp.subject)[service.title]
: getShareLink(service.title, validated_url);
return (
<Col xs={12} sm={8} key={i}>
Expand Down
8 changes: 4 additions & 4 deletions src/Views/Pages/GetButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { classes } from '../../../Tools/Utils/React';
import { encode } from '@src/Tools/Utils/URLEncoding';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { copyToClipboard } from '@src/Tools/Utils/React';
import { Services, services_url } from '@src/Data/services.data';
import { services, serviceUrls } from '@src/Data/services.data';
import EditableInput from '@src/Components/EditableInput/EditableInput';
import { lightfair } from 'react-syntax-highlighter/dist/esm/styles/hljs';
import { ReactComponent as Clone } from '@assets/icons/clone-regular.svg';
Expand Down Expand Up @@ -63,8 +63,8 @@ const GetButton = () => {
}

const validated_url = urlValidation(temp.url || '');
const selected = Services.filter(service => selectedServices.includes(service.title));
const urls = services_url(validated_url, temp.subject);
const selected = services.filter(service => selectedServices.includes(service.title));
const urls = serviceUrls(validated_url, temp.subject);

const buttons = (
<div className='flex-center'>
Expand Down Expand Up @@ -237,7 +237,7 @@ const GetButton = () => {
<Modal.Body>
<div className='services-list'>
<Row>
{Services.map((service, i) => {
{services.map((service, i) => {
const checked = selectedServices.includes(service.title);
return (
<Col xs={12} sm={8} key={i}>
Expand Down
4 changes: 2 additions & 2 deletions src/Views/Pages/Share/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './index.scss';
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import LoadingCover from '@src/Components/LoadingCover';
import { services_url } from '@src/Data/services.data';
import { serviceUrls } from '@src/Data/services.data';
import { decode } from '@src/Tools/Utils/URLEncoding';

const Share = () => {
Expand All @@ -18,7 +18,7 @@ const Share = () => {
const subject = urlParams.get('subject') || '';
const link = urlParams.get('link') || '';

const url = services_url(encodeURIComponent(link), subject)[service];
const url = serviceUrls(encodeURIComponent(link), subject)[service];
setTimeout(() => {
window.open(url, '_self');
}, 100);
Expand Down
Loading