Skip to content

Commit 6d4668d

Browse files
Rename posts to links
1 parent d0f0afe commit 6d4668d

File tree

13 files changed

+107
-241
lines changed

13 files changed

+107
-241
lines changed

src/App.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from "react";
22
import {Route, Switch, Redirect} from "react-router-dom";
3-
import Posts from "./pages/posts/Posts";
3+
import Links from "./pages/links/Links";
44
import Login from "./pages/login/Login";
55
import Registration from "./pages/registration/Registration";
66
import NavBar from "./components/layout/NavBar";
7-
import NewPost from "./pages/posts/NewPost";
7+
import NewLink from "./pages/links/NewLink";
88
import NotFound from "./pages/error/NotFound";
9-
import UserProfile from "./pages/profile/UserProfile";
109

1110
const App = () => (
1211
<div className="App">
@@ -15,19 +14,18 @@ const App = () => (
1514
<Switch>
1615
<Route path="/login" component={Login}/>
1716
<Route path="/registration" component={Registration}/>
18-
<Route path="/profile" component={UserProfile}/>
19-
<Route path="/posts/new" component={NewPost}/>
17+
<Route path="/links/new" component={NewLink}/>
2018

21-
<Route path="/posts" component={Posts} />
22-
<Redirect exact path="/" to="/posts"/>
19+
<Route path="/links" component={Links} />
20+
<Redirect exact path="/" to="/links"/>
2321
<Route path="*">
2422
<NotFound />
2523
</Route>
2624
</Switch>
2725
</main>
2826
<footer className="footer">
2927
<div className="container">
30-
<p className="text-center">SivaLabs &copy; 2020</p>
28+
<p className="text-center">SivaLabs &copy; 2022</p>
3129
</div>
3230
</footer>
3331
</div>

src/components/layout/NavBar.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const NavBar = () => {
1616
authenticatedLinks = (
1717
<ul className="navbar-nav">
1818
<li className="nav-item">
19-
<NavLink className="nav-link" to="/posts/new">
20-
<i className="fas fa-plus-circle"/> Add
19+
<NavLink className="nav-link" to="/links/new">
20+
<i className="fas fa-plus-circle"/> Add Link
2121
</NavLink>
2222
</li>
2323
<li className="nav-item dropdown">
@@ -26,11 +26,6 @@ const NavBar = () => {
2626
<i className="fas fa-user"/> <span>{user.user.name}</span>
2727
</NavLink>
2828
<div className="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
29-
<NavLink className="dropdown-item" to="/profile">
30-
<i className="fas fa-address-card"/> My Profile
31-
</NavLink>
32-
<div className="dropdown-divider"/>
33-
3429
<NavLink className="dropdown-item" to="/logout" onClick={logoutHandler}>
3530
<i className="fas fa-sign-out-alt"/> Logout
3631
</NavLink>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from "react";
22
import {NavLink} from "react-router-dom";
3-
import {PostModel} from "../../models/PostModels";
3+
import {LinkModel} from "../../models/LinkModels";
44

5-
const Post: React.FC<PostModel> = (post) => {
6-
const tags = post.tags.map(tag => {
5+
const Link: React.FC<LinkModel> = (link) => {
6+
const tags = link.tags.map(tag => {
77
return (<span key={tag} style={{"fontSize": "20px"}}>
8-
<NavLink className="badge badge-primary" to={`/posts?tag=${tag}`}>
8+
<NavLink className="badge badge-primary" to={`/links?tag=${tag}`}>
99
{tag}
1010
</NavLink>
1111
&nbsp;
@@ -14,7 +14,7 @@ const Post: React.FC<PostModel> = (post) => {
1414
return (
1515
<div className="alert alert-primary" role="alert">
1616
<h3 className="alert-heading">
17-
<a href={post.url} target="_blank" rel="noopener noreferrer">{post.title}</a>
17+
<a href={link.url} target="_blank" rel="noopener noreferrer">{link.title}</a>
1818
</h3>
1919
<p className="mb-0">
2020
{tags}
@@ -23,4 +23,4 @@ const Post: React.FC<PostModel> = (post) => {
2323
);
2424
}
2525

26-
export default Post;
26+
export default Link;

src/components/links/LinkList.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
import Link from "./Link";
3+
import {LinksModel} from "../../models/LinkModels";
4+
5+
const LinkList: React.FC<LinksModel> = (links) => {
6+
7+
return (
8+
<div>
9+
{links.data.map(link => <Link key={link.id} {...link}/>)}
10+
</div>
11+
);
12+
};
13+
14+
export default LinkList;

src/components/posts/Pagination.tsx renamed to src/components/links/Pagination.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
import React from "react";
2-
import {PostsPaginationModel} from "../../models/PostModels";
32
import classNames from "classnames";
43
import {NavLink} from "react-router-dom";
4+
import {LinksPaginationModel} from "../../models/LinkModels";
55

6-
const Pagination: React.FC<PostsPaginationModel> = (postsPagination) => {
7-
let posts = postsPagination.posts
8-
let firstPageUrl = "/posts?page=1";
9-
let prevPageUrl = `/posts?page=${posts.pageNumber-1}`;
10-
let nextPageUrl = `/posts?page=${posts.pageNumber+1}`;
11-
let lastPageUrl = `/posts?page=${posts.totalPages}`;
6+
const Pagination: React.FC<LinksPaginationModel> = (linksPagination) => {
7+
let links = linksPagination.links
8+
let firstPageUrl = "/links?page=1";
9+
let prevPageUrl = `/links?page=${links.pageNumber-1}`;
10+
let nextPageUrl = `/links?page=${links.pageNumber+1}`;
11+
let lastPageUrl = `/links?page=${links.totalPages}`;
1212

13-
if(postsPagination.tag) {
14-
firstPageUrl += `&tag=${postsPagination.tag}`;
15-
prevPageUrl += `&tag=${postsPagination.tag}`;
16-
nextPageUrl += `&tag=${postsPagination.tag}`;
17-
lastPageUrl += `&tag=${postsPagination.tag}`;
13+
if(linksPagination.tag) {
14+
firstPageUrl += `&tag=${linksPagination.tag}`;
15+
prevPageUrl += `&tag=${linksPagination.tag}`;
16+
nextPageUrl += `&tag=${linksPagination.tag}`;
17+
lastPageUrl += `&tag=${linksPagination.tag}`;
1818
}
1919

20-
if(postsPagination.query) {
21-
firstPageUrl += `&query=${postsPagination.query}`;
22-
prevPageUrl += `&query=${postsPagination.query}`;
23-
nextPageUrl += `&query=${postsPagination.query}`;
24-
lastPageUrl += `&query=${postsPagination.query}`;
20+
if(linksPagination.query) {
21+
firstPageUrl += `&query=${linksPagination.query}`;
22+
prevPageUrl += `&query=${linksPagination.query}`;
23+
nextPageUrl += `&query=${linksPagination.query}`;
24+
lastPageUrl += `&query=${linksPagination.query}`;
2525
}
2626

2727
return (
2828
<div>
29-
{ posts.totalPages > 1 &&
29+
{ links.totalPages > 1 &&
3030
<nav aria-label="Page navigation">
3131
<ul className="pagination pagination justify-content-center">
3232
<li className={classNames({
3333
"page-item": true,
34-
disabled: !posts.hasPrevious
34+
disabled: !links.hasPrevious
3535
})}>
3636
<NavLink className="page-link" to={`${firstPageUrl}`}>First</NavLink>
3737
</li>
3838
<li className={classNames({
3939
"page-item": true,
40-
disabled: !posts.hasPrevious
40+
disabled: !links.hasPrevious
4141
})}>
4242
<NavLink className="page-link" to={`${prevPageUrl}`}>Previous</NavLink>
4343
</li>
4444
<li className={classNames({
4545
"page-item": true,
46-
disabled: !posts.hasNext
46+
disabled: !links.hasNext
4747
})}>
4848
<NavLink className="page-link" to={`${nextPageUrl}`}>Next</NavLink>
4949
</li>
5050
<li className={classNames({
5151
"page-item": true,
52-
disabled: !posts.hasNext
52+
disabled: !links.hasNext
5353
})}>
5454
<NavLink className="page-link" to={`${lastPageUrl}`}>Last</NavLink>
5555
</li>
File renamed without changes.

src/components/posts/TagNav.tsx renamed to src/components/links/TagNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const TagNav :React.FC<TagList> = (tagList) => {
1616
<div className="list-group list-group-flush">
1717
{tagList.tags.map(tag => {
1818
return(
19-
<NavLink to={`/posts?tag=${tag.name}`} key={tag.id}
19+
<NavLink to={`/links?tag=${tag.name}`} key={tag.id}
2020
className="list-group-item list-group-item-action badge badge-primary"
2121
>
2222
<i className="fas fa-tag"/>&nbsp;

src/components/posts/PostList.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

2-
export interface PostModel {
2+
export interface LinkModel {
33
id: number,
44
title: string,
55
url: string,
66
tags: string[],
77
description: string
88
}
99

10-
export interface PostsModel {
11-
data: PostModel[],
10+
export interface LinksModel {
11+
data: LinkModel[],
1212
totalElements: number,
1313
pageNumber: number,
1414
totalPages: number,
@@ -18,9 +18,9 @@ export interface PostsModel {
1818
hasPrevious: boolean;
1919
}
2020

21-
export interface PostsPaginationModel {
21+
export interface LinksPaginationModel {
2222
tag?: string
2323
query?: string
2424
page?: number
25-
posts: PostsModel
25+
links: LinksModel
2626
}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import React, {useState, useEffect} from "react";
22

3-
import PostService from '../../services/PostService';
4-
import PostList from "../../components/posts/PostList";
5-
import TagNav from "../../components/posts/TagNav";
6-
import {PostsModel, PostsPaginationModel} from "../../models/PostModels";
7-
import Search from "../../components/posts/Search";
8-
import Pagination from "../../components/posts/Pagination";
3+
import LinkService from '../../services/LinkService';
4+
import LinkList from "../../components/links/LinkList";
5+
import TagNav from "../../components/links/TagNav";
6+
import {LinksModel, LinksPaginationModel} from "../../models/LinkModels";
7+
import Search from "../../components/links/Search";
8+
import Pagination from "../../components/links/Pagination";
99
import { useHistory, RouteComponentProps} from "react-router-dom";
1010

11-
type PostsState = {
11+
type LinksState = {
1212
tag?: string
1313
query?: string
1414
page?: number
1515
}
1616

17-
type PostsProps = RouteComponentProps<{}, {}, PostsState>;
17+
type LinksProps = RouteComponentProps<{}, {}, LinksState>;
1818

19-
const Posts : React.FC<PostsProps> = ( props ) => {
19+
const Links : React.FC<LinksProps> = (props ) => {
2020
const history = useHistory();
21-
const postService = new PostService();
21+
const linkService = new LinkService();
2222

2323
const queryParams = new URLSearchParams(props.location.search);
2424

@@ -31,7 +31,7 @@ const Posts : React.FC<PostsProps> = ( props ) => {
3131
//console.log("query:", query)
3232
//console.log("tag:", tag)
3333

34-
const initialValue: PostsModel = {
34+
const initialValue: LinksModel = {
3535
hasNext: false,
3636
hasPrevious: false,
3737
isFirst: false,
@@ -40,16 +40,16 @@ const Posts : React.FC<PostsProps> = ( props ) => {
4040
totalElements: 0,
4141
totalPages: 0,
4242
data: []}
43-
const [posts, setPosts] = useState(initialValue)
43+
const [links, setLinks] = useState(initialValue)
4444
const [tags, setTags] = useState([])
45-
let postsPaginationModel : PostsPaginationModel = {
45+
let linksPaginationModel : LinksPaginationModel = {
4646
page: page,
4747
tag: tag,
4848
query: query,
49-
posts: posts || {}
49+
links: links || {}
5050
}
5151
useEffect(() => {
52-
postService.fetchTags()
52+
linkService.fetchTags()
5353
.then(response => {
5454
setTags(response.data)
5555
})
@@ -59,17 +59,17 @@ const Posts : React.FC<PostsProps> = ( props ) => {
5959
}, []);
6060

6161
useEffect(() => {
62-
postService.fetchPosts(page, tag, query)
62+
linkService.fetchLinks(page, tag, query)
6363
.then(response => {
64-
setPosts({...response.data})
64+
setLinks({...response.data})
6565
})
6666
.catch(e => {
67-
alert('Failed to get posts')
67+
alert('Failed to get links')
6868
});
6969
}, [page, tag, query]);
7070

7171
const searchHandler = (query: string) => {
72-
history.push(`/posts?query=${query}`);
72+
history.push(`/links?query=${query}`);
7373
}
7474
return (
7575
<div className="row">
@@ -78,9 +78,9 @@ const Posts : React.FC<PostsProps> = ( props ) => {
7878
<div className="row">
7979
<div className="offset-1 col-8">
8080
<Search ClickHandler={searchHandler}/>
81-
<Pagination {...postsPaginationModel} />
82-
<PostList {...posts}/>
83-
<Pagination {...postsPaginationModel} />
81+
<Pagination {...linksPaginationModel} />
82+
<LinkList {...links}/>
83+
<Pagination {...linksPaginationModel} />
8484
</div>
8585
<div className="col-3">
8686
<TagNav tags={tags}/>
@@ -92,4 +92,4 @@ const Posts : React.FC<PostsProps> = ( props ) => {
9292
);
9393
};
9494

95-
export default Posts;
95+
export default Links;

0 commit comments

Comments
 (0)