Skip to content

Commit

Permalink
fix: 🐛 rename to helpers and rootUrl var
Browse files Browse the repository at this point in the history
  • Loading branch information
yeukfei02 committed Nov 12, 2021
1 parent dbcfd43 commit 3ea6f53
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import Settings from './settings/Settings';
import Contact from './contact/Contact';
import RestaurantDetails from './restaurantDetails/RestaurantDetails';

import { getFirebaseConfig, getRootUrl } from '../common/Common';
import { getFirebaseConfig, getRootUrl } from '../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

// use default theme
// const theme = createMuiTheme();
Expand Down Expand Up @@ -135,7 +135,7 @@ function App(): JSX.Element {

const addTokenToServer = async (currentToken: string, refreshedToken: string) => {
const response = await axios.post(
`${ROOT_URL}/firebase/add-token-to-server`,
`${rootUrl}/firebase/add-token-to-server`,
{
currentToken: currentToken,
refreshedToken: refreshedToken,
Expand All @@ -153,7 +153,7 @@ function App(): JSX.Element {

const subscribeTopic = async (currentToken: string) => {
const response = await axios.post(
`${ROOT_URL}/firebase/subscribe-topic`,
`${rootUrl}/firebase/subscribe-topic`,
{
currentTokenList: [currentToken],
topic: 'all',
Expand Down
10 changes: 5 additions & 5 deletions src/components/cardView/CardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import _ from 'lodash';
import axios from 'axios';

import Snackbar from '../snackBar/SnackBar';
import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

const useStyles = makeStyles(theme => ({
card: {
Expand Down Expand Up @@ -114,7 +114,7 @@ function CardView(props: any): JSX.Element {
};

const getRestaurantsDetailsReviewById = async (id: string) => {
const response = await axios.get(`${ROOT_URL}/restaurant/get-restaurant-details-review/${id}`, {
const response = await axios.get(`${rootUrl}/restaurant/get-restaurant-details-review/${id}`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -218,7 +218,7 @@ function CardView(props: any): JSX.Element {
setAddToFavoritesClicked(true);

const response = await axios.post(
`${ROOT_URL}/favourites/add-to-favourites`,
`${rootUrl}/favourites/add-to-favourites`,
{
item: item,
},
Expand Down Expand Up @@ -258,7 +258,7 @@ function CardView(props: any): JSX.Element {
};

const handleDeleteFavouritesById = async (_id: string) => {
const response = await axios.delete(`${ROOT_URL}/favourites/delete-favourites/${_id}`, {
const response = await axios.delete(`${rootUrl}/favourites/delete-favourites/${_id}`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/contact/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import MyStoreCheckout from '../myStoreCheckout/MyStoreCheckout';
import { useTranslation } from 'react-i18next';
import _ from 'lodash';

import { getStripeApiKey } from '../../common/Common';
import { getStripeApiKey } from '../../helpers/helpers';

const useStyles = makeStyles(theme => ({
root: {
Expand Down
8 changes: 4 additions & 4 deletions src/components/favourites/Favourites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import axios from 'axios';
import CardView from '../cardView/CardView';
import FloatingActionButton from '../floatingActionButton/FloatingActionButton';
import Snackbar from '../snackBar/SnackBar';
import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

const useStyles = makeStyles(theme => ({
root: {
Expand Down Expand Up @@ -58,7 +58,7 @@ function Favourites(): JSX.Element {
}, [deleteAllFavouritesStatus]);

const getFavourites = async () => {
const response = await axios.get(`${ROOT_URL}/favourites/get-favourites`, {
const response = await axios.get(`${rootUrl}/favourites/get-favourites`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -149,7 +149,7 @@ function Favourites(): JSX.Element {
const handleDeleteAllFavourites = async () => {
setDeleteAllFavouritesButtonClicked(true);

const response = await axios.delete(`${ROOT_URL}/favourites/delete-all-favourites`, {
const response = await axios.delete(`${rootUrl}/favourites/delete-all-favourites`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down
14 changes: 7 additions & 7 deletions src/components/mainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import axios from 'axios';
import FloatingActionButton from '../floatingActionButton/FloatingActionButton';
import Snackbar from '../snackBar/SnackBar';
import DisplayResult from '../displayResult/DisplayResult';
import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

const groupStyles = {
display: 'flex',
Expand Down Expand Up @@ -111,7 +111,7 @@ function MainPage(): JSX.Element {
}, [transcript]);

const getSelectedTermList = async () => {
const response = await axios.get(`${ROOT_URL}/category/get-categories`, {
const response = await axios.get(`${rootUrl}/category/get-categories`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -252,7 +252,7 @@ function MainPage(): JSX.Element {
};

const findLocationTextByLatLong = async (latitude: number, longitude: number) => {
const response = await axios.get(`${ROOT_URL}/restaurant/find-location-text-by-lat-long`, {
const response = await axios.get(`${rootUrl}/restaurant/find-location-text-by-lat-long`, {
params: {
latitude: latitude,
longitude: longitude,
Expand All @@ -271,7 +271,7 @@ function MainPage(): JSX.Element {
};

const findRestaurantsByLocation = async (selectedTerm: string, location: any) => {
const response = await axios.get(`${ROOT_URL}/restaurant/find-restaurants-by-location`, {
const response = await axios.get(`${rootUrl}/restaurant/find-restaurants-by-location`, {
params: {
term: selectedTerm,
location: location,
Expand All @@ -296,7 +296,7 @@ function MainPage(): JSX.Element {
};

const findRestaurantsByLatLong = async (selectedTerm: string, latitude: number, longitude: number) => {
const response = await axios.get(`${ROOT_URL}/restaurant/find-restaurants-by-lat-long`, {
const response = await axios.get(`${rootUrl}/restaurant/find-restaurants-by-lat-long`, {
params: {
term: selectedTerm,
latitude: latitude,
Expand Down Expand Up @@ -780,7 +780,7 @@ function MainPage(): JSX.Element {
setRandomButtonClicked(true);

if (_.isEmpty(formattedRandomFoodList)) {
const response = await axios.get(`${ROOT_URL}/category/get-categories`, {
const response = await axios.get(`${rootUrl}/category/get-categories`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/myStoreCheckout/CheckoutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { useTranslation } from 'react-i18next';
import CardSection from './CardSection';
import Snackbar from '../snackBar/SnackBar';

import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

const selectStyles = {
container: (base: any, state: any) => ({
Expand Down Expand Up @@ -119,7 +119,7 @@ function CheckoutForm(props: any) {

const creditCardPayment = async (amount: number, currency: any, token: string, card: any) => {
const response = await axios.post(
`${ROOT_URL}/stripe/credit-card-payment`,
`${rootUrl}/stripe/credit-card-payment`,
{
amount: Math.round(amount * 100),
currency: currency.value,
Expand Down
8 changes: 4 additions & 4 deletions src/components/randomFood/RandomFood.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import axios from 'axios';
import CardView from '../cardView/CardView';
import FloatingActionButton from '../floatingActionButton/FloatingActionButton';
import Snackbar from '../snackBar/SnackBar';
import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

const useStyles = makeStyles(theme => ({
root: {
Expand Down Expand Up @@ -83,7 +83,7 @@ function RandomFood(): JSX.Element {
}, [openSuccessAlert, message]);

const getRandomFoodList = async () => {
const response = await axios.get(`${ROOT_URL}/category/get-categories`, {
const response = await axios.get(`${rootUrl}/category/get-categories`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -128,7 +128,7 @@ function RandomFood(): JSX.Element {
latitude: number,
longitude: number,
) => {
const response = await axios.get(`${ROOT_URL}/restaurant/find-restaurants-by-lat-long`, {
const response = await axios.get(`${rootUrl}/restaurant/find-restaurants-by-lat-long`, {
params: {
term: useRandomFoodCategory ? selectedTerm : '',
latitude: latitude,
Expand Down
8 changes: 4 additions & 4 deletions src/components/randomFoodMapView/RandomFoodMapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import axios from 'axios';

import CustomMapList from '../customMap/CustomMapList';
import Snackbar from '../snackBar/SnackBar';
import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

function RandomFoodMapView(): JSX.Element {
const { t } = useTranslation();
Expand Down Expand Up @@ -50,7 +50,7 @@ function RandomFoodMapView(): JSX.Element {
}, [openSuccessAlert, message]);

const getRandomFoodList = async () => {
const response = await axios.get(`${ROOT_URL}/category/get-categories`, {
const response = await axios.get(`${rootUrl}/category/get-categories`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -90,7 +90,7 @@ function RandomFoodMapView(): JSX.Element {
};

const findRestaurantsByLatLong = async (selectedTerm: string, latitude: number, longitude: number) => {
const response = await axios.get(`${ROOT_URL}/restaurant/find-restaurants-by-lat-long`, {
const response = await axios.get(`${rootUrl}/restaurant/find-restaurants-by-lat-long`, {
params: {
term: selectedTerm,
latitude: latitude,
Expand Down
6 changes: 3 additions & 3 deletions src/components/restaurantDetails/RestaurantDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import ImageSlider from '../imageSlider/ImageSlider';
import CustomMap from '../customMap/CustomMap';
import Snackbar from '../snackBar/SnackBar';

import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

const useStyles = makeStyles(theme => ({
root: {
Expand Down Expand Up @@ -54,7 +54,7 @@ function RestaurantDetails(props: any) {
}, [openSuccessAlert, message]);

const getRestaurantsDetailsById = async (id: string) => {
const response = await axios.get(`${ROOT_URL}/restaurant/get-restaurant-details/${id}`, {
const response = await axios.get(`${rootUrl}/restaurant/get-restaurant-details/${id}`, {
headers: {
'Content-Type': 'application/json',
},
Expand Down
8 changes: 4 additions & 4 deletions src/components/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import axios from 'axios';

import Snackbar from '../snackBar/SnackBar';

import { getRootUrl } from '../../common/Common';
import { getRootUrl } from '../../helpers/helpers';

const ROOT_URL = getRootUrl();
const rootUrl = getRootUrl();

const useStyles = makeStyles(theme => ({
root: {
Expand Down Expand Up @@ -107,7 +107,7 @@ function Settings(): JSX.Element {

const subscribeTopic = async (currentToken: string | null) => {
const response = await axios.post(
`${ROOT_URL}/firebase/subscribe-topic`,
`${rootUrl}/firebase/subscribe-topic`,
{
currentTokenList: [currentToken],
topic: 'all',
Expand All @@ -125,7 +125,7 @@ function Settings(): JSX.Element {

const unsubscribeTopic = async (currentToken: string | null) => {
const response = await axios.post(
`${ROOT_URL}/firebase/unsubscribe-topic`,
`${rootUrl}/firebase/unsubscribe-topic`,
{
currentTokenList: [currentToken],
topic: 'all',
Expand Down
9 changes: 5 additions & 4 deletions src/common/Common.tsx → src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ export const getStripeApiKey = (): string | undefined => {
};

export const getRootUrl = (): string => {
let ROOT_URL = '';
let rootUrl = '';

if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
ROOT_URL = 'http://localhost:3000/api';
rootUrl = 'http://localhost:3000/api';
} else {
ROOT_URL = 'https://www.lunch-picker-api.com/api';
rootUrl = 'https://www.lunch-picker-api.com/api';
}

return ROOT_URL;
return rootUrl;
};

0 comments on commit 3ea6f53

Please sign in to comment.