Skip to content

Commit 56a2e1a

Browse files
committed
Merge branch 'main' of https://github.com/kailash360/user-story into add-tests
2 parents e34e8b8 + 488947b commit 56a2e1a

File tree

9 files changed

+68
-72
lines changed

9 files changed

+68
-72
lines changed

.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
root: true
99
plugins:
1010
- react
11+
- react-hooks
1112
rules:
1213
arrow-spacing: 'error'
1314
no-const-assign: 'error'
@@ -16,3 +17,5 @@ rules:
1617
prefer-template: 'error'
1718
prefer-destructuring: ['error', { 'object': true, 'array': false }]
1819
object-curly-spacing: [2, 'always']
20+
react-hooks/rules-of-hooks: 'error'
21+
react-hooks/exhaustive-deps: 'warn'

src/components/Footer.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
export default () => {
3+
function Footer() {
44
return (
55
<div className='footer-main'>
66
<a className='link link-default' href='/policies'>
@@ -11,3 +11,5 @@ export default () => {
1111
</div>
1212
)
1313
}
14+
15+
export default Footer

src/components/Pagination.js

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,54 +31,56 @@ const Pagination = (props) => {
3131
}, [storyCount])
3232

3333
return (
34-
<div className='pagination'>
35-
<span
36-
className={`btn btn-pagination ${
37-
currNumber <= 1 ? 'btn-pagination-disabled' : ''
38-
}`}
39-
onClick={() => {
40-
if (pages.find((page) => page === currNumber - 1)) {
41-
setCurrNumber((currNumber) => currNumber - 1)
42-
getPage(currNumber - 1)
43-
}
44-
}}
45-
>
46-
<EOS_KEYBOARD_ARROW_LEFT className='eos-icons eos-18' />
47-
{`Prev`}
48-
</span>
49-
<div className='btn btn-pagination'>
50-
{pages
51-
? pages.map((ele, key) => {
52-
return (
53-
<span
54-
className={`number ${currNumber === ele ? 'selected' : ''}`}
55-
onClick={() => {
56-
setCurrNumber(ele)
57-
getPage(ele)
58-
}}
59-
key={key}
60-
>
61-
{ele}
62-
</span>
63-
)
64-
})
65-
: ''}
34+
storyCount > 5 && (
35+
<div className='pagination'>
36+
<span
37+
className={`btn btn-pagination ${
38+
currNumber <= 1 ? 'btn-pagination-disabled' : ''
39+
}`}
40+
onClick={() => {
41+
if (pages.find((page) => page === currNumber - 1)) {
42+
setCurrNumber((currNumber) => currNumber - 1)
43+
getPage(currNumber - 1)
44+
}
45+
}}
46+
>
47+
<EOS_KEYBOARD_ARROW_LEFT className='eos-icons eos-18' />
48+
{`Prev`}
49+
</span>
50+
<div className='btn btn-pagination'>
51+
{pages
52+
? pages.map((ele, key) => {
53+
return (
54+
<span
55+
className={`number ${currNumber === ele ? 'selected' : ''}`}
56+
onClick={() => {
57+
setCurrNumber(ele)
58+
getPage(ele)
59+
}}
60+
key={key}
61+
>
62+
{ele}
63+
</span>
64+
)
65+
})
66+
: ''}
67+
</div>
68+
<span
69+
className={`btn btn-pagination ${
70+
currNumber >= pages?.length ? 'btn-pagination-disabled' : ''
71+
}`}
72+
onClick={() => {
73+
if (pages.find((page) => page === currNumber + 1)) {
74+
setCurrNumber((currNumber) => currNumber + 1)
75+
getPage(currNumber + 1)
76+
}
77+
}}
78+
>
79+
{`Next`}
80+
<EOS_KEYBOARD_ARROW_RIGHT className='eos-icons eos-18' />
81+
</span>
6682
</div>
67-
<span
68-
className={`btn btn-pagination ${
69-
currNumber >= pages?.length ? 'btn-pagination-disabled' : ''
70-
}`}
71-
onClick={() => {
72-
if (pages.find((page) => page === currNumber + 1)) {
73-
setCurrNumber((currNumber) => currNumber + 1)
74-
getPage(currNumber + 1)
75-
}
76-
}}
77-
>
78-
{`Next`}
79-
<EOS_KEYBOARD_ARROW_RIGHT className='eos-icons eos-18' />
80-
</span>
81-
</div>
83+
)
8284
)
8385
}
8486

src/components/ProfileImageUploader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import React, { useEffect, useState } from 'react'
22
import { useDropzone } from 'react-dropzone'
33
import Modal from './Modal'
44
import axios from 'axios'
5-
import * as config from '../config.json'
65
import LoadingIndicator from '../modules/LoadingIndicator'
76
import FormError from './FormError'
87
import { EOS_DELETE } from 'eos-icons-react'
9-
const { apiURL } = config
8+
const { apiURL } = require('../config.json')
109

1110
const ProfileImageUploader = ({
1211
userId,

src/components/Stories.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useRef, useCallback } from 'react'
1+
import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react'
22
import { trackPromise, usePromiseTracker } from 'react-promise-tracker'
33

44
import Button from './Button'
@@ -16,7 +16,7 @@ const Stories = ({ authorId, followerId }) => {
1616

1717
const [page, setPage] = useState(1)
1818

19-
const statusOptions = []
19+
const statusOptions = useMemo(() => [], [])
2020

2121
const [status, setStatus] = useState('Under consideration')
2222

src/components/UsersSuggestionDropdown.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React, { useEffect, useRef, useState } from 'react'
22
import axios from 'axios'
33
import { trackPromise, usePromiseTracker } from 'react-promise-tracker'
4-
import * as config from '../config.json'
54
import LoadingIndicator from '../modules/LoadingIndicator'
6-
const { apiURL } = config
5+
const { apiURL } = require('../config.json')
76

87
const UsersSuggestionDropdown = ({
98
isOpen,

src/hooks/useAuth.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import axios from 'axios'
2-
import * as config from '../config.json'
32
import Context from '../modules/Context'
43
import { useContext } from 'react'
5-
const { apiURL } = config
4+
const { apiURL } = require('../config.json')
65

76
const useAuth = () => {
87
const { dispatch } = useContext(Context)

src/modules/TitleSearch.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { useState, useEffect, useCallback } from 'react'
2-
import { debounce } from 'lodash'
1+
import React, { useState, useEffect } from 'react'
32
import userStory from '../services/user_story'
43
import { strip } from '../utils/filterText'
54
import { EOS_ARROW_FORWARD, EOS_THUMB_UP } from 'eos-icons-react'
@@ -9,20 +8,14 @@ const Search = (props) => {
98

109
const [searchResults, setSearchResults] = useState([])
1110

12-
const handleTitleChange = useCallback(
13-
debounce(async (title) => {
11+
useEffect(() => {
12+
if (!title) return
13+
14+
setTimeout(async () => {
1415
const response = await userStory.getStoriesByTitle(title)
1516
setSearchResults(response.data.data.userStories)
16-
}, 600),
17-
[]
18-
)
19-
20-
useEffect(() => {
21-
if (!title) {
22-
return
23-
}
24-
handleTitleChange(title)
25-
}, [title, handleTitleChange])
17+
}, 600)
18+
}, [title])
2619

2720
if (!title) {
2821
return ''

src/services/api.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import axios from 'axios'
2-
import * as CONFIG from '../config.json'
3-
const { apiURL, APP_ENV } = CONFIG
2+
const { apiURL, APP_ENV } = require('../config.json')
43

54
const config = {
65
baseURL: apiURL,

0 commit comments

Comments
 (0)