Skip to content

Commit 488073c

Browse files
authored
Merge pull request #98 from Mayank0255/refactor/style-format-1
Restructure The File Structure And Adopt Atomic Design
2 parents e9deb78 + caba737 commit 488073c

File tree

121 files changed

+499
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+499
-350
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"redux-thunk": "^2.4.1",
3232
"reselect": "^4.1.5",
3333
"sass": "^1.45.2",
34+
"styled-system": "^5.1.5",
3435
"uuid": "^8.3.2"
3536
},
3637
"scripts": {

src/App.js

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import React, {useEffect} from 'react';
22
import {Provider} from 'react-redux';
3+
import {Switch} from 'react-router-dom';
4+
35
import store from './redux/store';
46
import setAuthToken from './redux/auth/auth.utils';
57
import {loadUser} from './redux/auth/auth.actions';
6-
import RoutesTree from './RoutesTree';
78

8-
import Header from './components/Header/Header.component';
9+
import Header from './components/organisms/Header/Header.component';
910
import Alert from './components/Alert/Alert.component';
11+
import HomePage from './modules/HomePage/HomePage.component';
12+
import QuestionsPage from './modules/QuestionsPage/QuestionsPage.component';
13+
import AllTagsPage from './modules/AllTagsPage/AllTagsPage.component';
14+
import AllUsersPage from './modules/AllUsersPage/AllUsersPage.component';
15+
import Register from './modules/Register/Register.component';
16+
import Login from './modules/Login/Login.component';
17+
import Post from './modules/Post/Post.component';
18+
import PostForm from './modules/PostForm/PostForm.component';
19+
import TagPage from './modules/TagPage/TagPage.component';
20+
import ProfilePage from './modules/ProfilePage/ProfilePage.component';
21+
import NotFound from './modules/NotFound/NotFound.component';
22+
23+
import { BaseRoute, LayoutRoute } from './Router';
1024

1125
import './App.css';
1226

@@ -24,7 +38,84 @@ const App = () => {
2438
<div className='App'>
2539
<Header />
2640
<Alert />
27-
<RoutesTree />
41+
<Switch>
42+
<LayoutRoute
43+
exact
44+
path='/'
45+
title='CLONE Stack Overflow - Where Developers Learn, Share, & Build Careers'
46+
>
47+
<HomePage/>
48+
</LayoutRoute>
49+
<LayoutRoute
50+
exact
51+
path='/questions'
52+
title='All Questions - CLONE Stack Overflow'
53+
>
54+
<QuestionsPage/>
55+
</LayoutRoute>
56+
<LayoutRoute
57+
exact
58+
path='/tags'
59+
title='Tags - CLONE Stack Overflow'
60+
>
61+
<AllTagsPage/>
62+
</LayoutRoute>
63+
<LayoutRoute
64+
exact
65+
path='/users'
66+
title='Users - CLONE Stack Overflow'
67+
>
68+
<AllUsersPage/>
69+
</LayoutRoute>
70+
<BaseRoute
71+
exact
72+
path='/register'
73+
title='Sign Up - CLONE Stack Overflow'
74+
>
75+
<Register/>
76+
</BaseRoute>
77+
<BaseRoute
78+
exact
79+
path='/login'
80+
title='Log In - CLONE Stack Overflow'
81+
>
82+
<Login/>
83+
</BaseRoute>
84+
<LayoutRoute
85+
exact
86+
path='/questions/:id'
87+
title='Users - CLONE Stack Overflow'
88+
>
89+
<Post/>
90+
</LayoutRoute>
91+
<LayoutRoute
92+
exact
93+
path='/users/:id'
94+
title='Users - CLONE Stack Overflow'
95+
>
96+
<ProfilePage/>
97+
</LayoutRoute>
98+
<LayoutRoute
99+
exact
100+
path='/tags/:tagname'
101+
title='Users - CLONE Stack Overflow'
102+
>
103+
<TagPage/>
104+
</LayoutRoute>
105+
<BaseRoute
106+
exact
107+
path='/add/question'
108+
title='Ask a Question - CLONE Stack Overflow'
109+
>
110+
<PostForm/>
111+
</BaseRoute>
112+
<BaseRoute
113+
path='*'
114+
title='Error 404'
115+
>
116+
<NotFound/>
117+
</BaseRoute>
118+
</Switch>
28119
</div>
29120
</Provider>
30121
);

src/Router.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { Route } from 'react-router-dom';
3+
4+
import LayoutWrapper from './components/organisms/LayoutWrapper/LayoutWrapper.component';
5+
6+
import usePageTitle from './hooks/usePageTitle';
7+
8+
export const LayoutRoute = ({ title, children, ...props }) => {
9+
usePageTitle(title);
10+
11+
return (
12+
<Route {...props}>
13+
<LayoutWrapper>
14+
{children}
15+
</LayoutWrapper>
16+
</Route>
17+
)
18+
}
19+
20+
export const BaseRoute = ({ title, children, ...props }) => {
21+
usePageTitle(title);
22+
23+
return (
24+
<Route {...props}>
25+
{children}
26+
</Route>
27+
)
28+
}

src/RoutesTree.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/api/answersApi.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import axios from 'axios';
2+
3+
import {
4+
allAnswersData as _allAnswersData,
5+
createSingleAnswer as _createSingleAnswer,
6+
deleteSingleAnswer as _deleteSingleAnswer
7+
} from './urls';
8+
9+
export const allAnswersData = (id) => {
10+
return axios.get(_allAnswersData.replace('{id}', id));
11+
}
12+
13+
export const createSingleAnswer = (postId, formData) => {
14+
const config_headers = {
15+
headers: {
16+
"Content-Type": "application/json",
17+
},
18+
};
19+
20+
return axios.post(_createSingleAnswer.replace('{postId}', postId), formData, config_headers);
21+
}
22+
23+
export const deleteSingleAnswer = (AnswerId) => {
24+
return axios.delete(_deleteSingleAnswer.replace('{AnswerId}', AnswerId));
25+
}

src/api/authApi.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import axios from 'axios';
2+
3+
import {loadUserData as _loadUserData, registerUser as _registerUser, loginUser as _loginUser} from './urls';
4+
5+
export const loadUserData = () => {
6+
return axios.get(_loadUserData);
7+
};
8+
9+
export const registerUser = (username, password) => {
10+
const config_headers = {
11+
headers: {
12+
'Content-Type': 'application/json',
13+
Accept: "application/json",
14+
},
15+
};
16+
17+
const body = JSON.stringify({ username, password });
18+
19+
return axios.post(_registerUser, body, config_headers);
20+
};
21+
22+
export const loginUser = (username, password) => {
23+
const config_headers = {
24+
headers: {
25+
'Content-Type': 'application/json',
26+
Accept: "application/json",
27+
},
28+
};
29+
30+
const body = JSON.stringify({username, password});
31+
32+
return axios.post(_loginUser, body, config_headers);
33+
};

src/api/commentsApi.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import axios from 'axios';
2+
3+
import {
4+
allCommentsData as _allCommentsData,
5+
createSingleComment as _createSingleComment,
6+
deleteSingleComment as _deleteSingleComment
7+
} from './urls';
8+
9+
export const allCommentsData = (id) => {
10+
return axios.get(_allCommentsData.replace('{id}', id));
11+
}
12+
13+
export const createSingleComment = (postId, formData) => {
14+
const config_headers = {
15+
headers: {
16+
"Content-Type": "application/json",
17+
},
18+
};
19+
20+
return axios.post(_createSingleComment.replace('{postId}', postId), formData, config_headers);
21+
}
22+
23+
export const deleteSingleComment = (CommentId) => {
24+
return axios.delete(_deleteSingleComment.replace('{CommentId}', CommentId));
25+
}

src/api/postsApis.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import axios from 'axios';
2+
3+
import {
4+
allPostsData as _allPostsData,
5+
singlePostData as _singlePostData,
6+
allTagPostsData as _allTagPostsData,
7+
createSinglePost as _createSinglePost,
8+
deleteSinglePost as _deleteSinglePost
9+
} from './urls';
10+
11+
export const allPostsData = () => {
12+
return axios.get(_allPostsData);
13+
}
14+
15+
export const singlePostData = (id) => {
16+
return axios.get(_singlePostData.replace('{id}', id));
17+
}
18+
19+
export const allTagPostsData = (tagName) => {
20+
return axios.get(_allTagPostsData.replace('{tagName}', tagName));
21+
}
22+
23+
export const createSinglePost = (formData) => {
24+
const config_headers = {
25+
headers: {
26+
"Content-Type": "application/json",
27+
},
28+
};
29+
30+
return axios.post(_createSinglePost, formData, config_headers);
31+
}
32+
33+
export const deleteSinglePost = (id) => {
34+
return axios.delete(_deleteSinglePost.replace('{id}', id));
35+
}

src/api/tagsApi.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import axios from 'axios';
2+
3+
import { allTagsData as _allTagsData, singleTagData as _singleTagData } from './urls';
4+
5+
export const allTagsData = () => {
6+
return axios.get(_allTagsData);
7+
}
8+
9+
export const singleTagData = (tagName) => {
10+
return axios.get(_singleTagData.replace('{tagName}', tagName));
11+
}

0 commit comments

Comments
 (0)