Skip to content

Commit

Permalink
feat: change file name system
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramin committed Nov 28, 2022
1 parent 364d9e5 commit d1b6ac6
Show file tree
Hide file tree
Showing 27 changed files with 41 additions and 47 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'import/prefer-default-export': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'prefer-arrow-callback': [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import { apiRequestObject } from 'utils/api';
import { REQUEST_TYPE } from 'constants/RequestType';
import { REQUEST_TYPES } from 'constants/request-types';
import { removeUndefinedFromObject } from 'utils/object';

const url = '/photos/';
const API_URL = '/photos/';

export const transformer = ({
data
}: {
data: {
url: string;
title: string;
albumId: number;
}[];
}) => {
export const transformer = ({ data }: any) => {
// change or convert response
return data?.slice(0, 5)?.map((item) =>
return data?.slice(0, 5)?.map(({ title, url, albumId }: any) =>
removeUndefinedFromObject({
// just 5 item
title: item.title || '',
url: item.url || '',
album: item.albumId === 1 ? 'A' : 'B'
url,
title,
album: albumId === 1 ? 'A' : 'B'
})
);
};

export const getIndexPageData = apiRequestObject({
url,
type: REQUEST_TYPE.GET,
url: API_URL,
type: REQUEST_TYPES.GET,
inputTransformer: ({ albumId }: { albumId: number }) => ({
// change or convert your data
albumId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useEffect } from 'react';
import { ToastContainer, toast, Slide, Zoom, Flip, Bounce } from 'react-toastify';

import { SNACKBAR_POSITIONS, SNACKBAR_TYPES } from 'constants/Snackbar';
import { SNACKBAR_POSITIONS, SNACKBAR_TYPES } from 'constants/snackbar';

import 'react-toastify/dist/ReactToastify.min.css';

Expand Down Expand Up @@ -40,14 +40,15 @@ export function SnackbarWrapper() {
const toastId = type + message;

if (type === SNACKBAR_TYPES.MESSAGE) {
return toast(message, {
toast(message, {
icon,
toastId,
position,
autoClose: delay,
theme: TOAST_COLOR_TYPES.DARK,
transition: TOAST_TRANSITION_TYPES.SLIDE
});
return;
}

toast[type]?.(message, {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const REQUEST_TYPE: {
export const REQUEST_TYPES: {
GET: 'GET';
POST: 'POST';
} = {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/hooks/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { useEffect, useMemo, useState } from 'react';

import { noop } from 'lodash';
import { redirect } from 'utils/url';
import { userSelectors } from 'store/user/userSelectors';
import { INDEX_PAGE_ROUTE } from 'routes/RedirectRoutes';
import { userSelectors } from 'store/user/user-selectors';
import { INDEX_PAGE_ROUTE } from 'routes/redirect-routes';
import {
hasAPICache,
setAPICache,
getAPICacheData,
checkAPICacheTime
} from 'services/api/cacheSystem';
} from 'services/api/cache-system';

interface Properties {
apiMethod: any;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
setAPICache,
getAPICacheData,
checkAPICacheTime
} from 'services/api/cacheSystem';
} from 'services/api/cache-system';

interface Properties {
apiData?: any;
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { reportWebVitals } from 'reportWebVitals';

import { store } from 'store';
import { Routes } from 'routes';
import { SnackbarWrapper } from 'components/shared/snackbar/SnackbarWrapper';
import { SnackbarWrapper } from 'components/shared/snackbar-wrapper';

import 'animate.css';
import 'styles/index.scss';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from 'react-router-dom';
import { INDEX_PAGE_ROUTE } from 'routes/RedirectRoutes';
import { INDEX_PAGE_ROUTE } from 'routes/redirect-routes';

export function NotFoundPage() {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useState } from 'react';
import { useAPI } from 'hooks/useApi';
import { usePageData } from 'hooks/usePageData';
import { getIndexPageData } from 'api/indexPage/get-index-page-data';
import { getIndexPageData } from 'api/index-page/get-index-page-data';

export function IndexPage() {
const [data, setData] = useState([]);
Expand Down
8 changes: 4 additions & 4 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
} from 'react-router-dom';

import { NotFoundPage } from 'pages/404';
import ScrollToTop from 'routes/ScrollToTop';
import { PAGE_ROUTES } from 'routes/PageRoutes';
import { PrivateRoute } from 'routes/PrivateRoute';
import { NOT_FOUND_ROUTE } from 'routes/RedirectRoutes';
import ScrollToTop from 'routes/scroll-to-top';
import { PAGE_ROUTES } from 'routes/page-routes';
import { PrivateRoute } from 'routes/private-route';
import { NOT_FOUND_ROUTE } from 'routes/redirect-routes';

export function Routes() {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/routes/PageRoutes.tsx → src/routes/page-routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { INDEX_PAGE_ROUTE } from 'routes/RedirectRoutes';
import { INDEX_PAGE_ROUTE } from 'routes/redirect-routes';

// PAGES
import { IndexPage } from 'pages';
Expand Down
4 changes: 2 additions & 2 deletions src/routes/PrivateRoute.tsx → src/routes/private-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ReactNode } from 'react';
import { useSelector } from 'react-redux';
import { Route, Navigate } from 'react-router-dom';

import { userSelectors } from 'store/user/userSelectors';
import { NOT_FOUND_ROUTE, USER_LOGIN_ROUTE } from 'routes/RedirectRoutes';
import { userSelectors } from 'store/user/user-selectors';
import { NOT_FOUND_ROUTE, USER_LOGIN_ROUTE } from 'routes/redirect-routes';

interface Properties {
deactivate: boolean;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import axios, { AxiosRequestConfig } from 'axios';
import { store } from 'store';
import { redirect } from 'utils/url';
import { sendLog } from 'services/log';
import { SNACKBAR_TYPES } from 'constants/Snackbar';
import { userLogoutAction } from 'store/user/userSlice';
import { generateSnackbar } from 'utils/generateSnackbar';
import { SNACKBAR_TYPES } from 'constants/snackbar';
import { userLogoutAction } from 'store/user/user-slice';
import { generateSnackbar } from 'utils/generate-snackbar';
import { serviceGet, servicePost } from 'services/api/initialize';
import {
INDEX_PAGE_ROUTE,
NOT_FOUND_ROUTE,
USER_LOGIN_ROUTE
} from 'routes/RedirectRoutes';
} from 'routes/redirect-routes';

function handleResponse({
response,
Expand Down
4 changes: 2 additions & 2 deletions src/services/api/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import QS from 'qs';
import axios from 'axios';
import { isMobile } from 'react-device-detect';

import { generateSnackbar } from 'utils/generateSnackbar';
import { CONNECTION_ERROR } from 'constants/ErrorMessages';
import { generateSnackbar } from 'utils/generate-snackbar';
import { CONNECTION_ERROR } from 'constants/error-messages';

const TOKEN = ''; // Read Your TOKEN
const MAX_REQUEST_PER_SECOND = 20;
Expand Down
4 changes: 2 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configureStore } from '@reduxjs/toolkit';
import { REDUCER_NAMES } from 'constants/reducerNames';
import { REDUCER_NAMES } from 'constants/reducer-names';

import useReducer from 'store/user/userSlice';
import useReducer from 'store/user/user-slice';

export const store = configureStore({
reducer: {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSlice } from '@reduxjs/toolkit';
import { REDUCER_NAMES } from 'constants/reducerNames';
import { REDUCER_NAMES } from 'constants/reducer-names';

const initialState = {
isAuthenticated: false // for private route system
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { REQUEST_TYPE } from 'constants/RequestType';
import { get, post, CancelToken } from 'services/api';
import { REQUEST_TYPES } from 'constants/request-types';

type RequestList = {
[key: string]: number;
Expand All @@ -19,7 +19,7 @@ export function apiRequestObject({
url,
transformer,
inputTransformer,
type = REQUEST_TYPE.GET
type = REQUEST_TYPES.GET
}: Properties) {
const source = CancelToken.source();

Expand Down Expand Up @@ -56,7 +56,7 @@ export function apiRequestObject({
resolve(response);
};
// GET
if (type === REQUEST_TYPE.GET) {
if (type === REQUEST_TYPES.GET) {
get({
url,
config: {
Expand All @@ -67,7 +67,7 @@ export function apiRequestObject({
}).then(handleResponse);
}
// POST
if (type === REQUEST_TYPE.POST) {
if (type === REQUEST_TYPES.POST) {
post({
url,
data: modifiedData,
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit d1b6ac6

Please sign in to comment.