Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit c768c52

Browse files
committed
jsdoc updates
1 parent f37c252 commit c768c52

File tree

11 files changed

+111
-63
lines changed

11 files changed

+111
-63
lines changed

components/molecules/AlgoliaSearch/AlgoliaSearch.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
import cn from 'classnames'
1+
import {AlgoliaContext} from '@/components/common/AlgoliaProvider'
22
import parseQuerystring from '@/functions/parseQuerystring'
3+
import cn from 'classnames'
4+
import dynamic from 'next/dynamic'
35
import {useRouter} from 'next/router'
46
import PropTypes from 'prop-types'
57
import React, {useContext, useRef, useState} from 'react'
6-
import {AlgoliaContext} from '@/components/common/AlgoliaProvider'
78
import styles from './AlgoliaSearch.module.css'
8-
import dynamic from 'next/dynamic'
99
import SearchPlaceholder from './components/SearchPlaceholder'
1010

11-
/* eslint-disable */
1211
/**
1312
* This always throws an error: Component definition is missing display name.
1413
* Error also appears when using the NextJS example.
1514
*
1615
* @see https://nextjs.org/docs/advanced-features/dynamic-import#with-custom-loading-component
1716
*/
1817
const Search = dynamic(() => import('./components/Search'), {
19-
loading: () => <SearchPlaceholder />
18+
loading: () => <SearchPlaceholder /> // eslint-disable-line
2019
})
21-
/* eslint-enable */
2220

21+
/**
22+
* Render the AlgoliaSearch component.
23+
*
24+
* @author WebDevStudios
25+
* @param {object} props The component attributes as props.
26+
* @param {string} props.className The component class.
27+
* @param {boolean} props.useHistory Whether to display the history.
28+
* @param {boolean} props.usePlaceholder Whether to display the placeholder.
29+
* @return {Element} The AlgoliaSearch component.
30+
*/
2331
export default function AlgoliaSearch({useHistory, usePlaceholder, className}) {
2432
const router = useRouter()
2533
const path = router?.asPath // URL from router.
@@ -29,7 +37,10 @@ export default function AlgoliaSearch({useHistory, usePlaceholder, className}) {
2937
const {indexName} = useContext(AlgoliaContext)
3038

3139
/**
32-
* Set a min-height value on the search wrapper to avoid DOM movement during dynamic render.
40+
* Set a min-height value on the search wrapper
41+
* to avoid DOM movement during dynamic render.
42+
*
43+
* @return {object} A minimum height value.
3344
*/
3445
function setMinHeight() {
3546
const minHeight =
@@ -40,7 +51,8 @@ export default function AlgoliaSearch({useHistory, usePlaceholder, className}) {
4051
}
4152

4253
/**
43-
* Toggle the state of the Algolia `Search` and `SearchPlaceholder` components.
54+
* Toggle the state of the Algolia `Search`
55+
* and `SearchPlaceholder` components.
4456
*
4557
* @param {boolean} value Show/hide Algolia search input.
4658
*/
@@ -64,9 +76,9 @@ export default function AlgoliaSearch({useHistory, usePlaceholder, className}) {
6476
}
6577

6678
AlgoliaSearch.propTypes = {
79+
className: PropTypes.string,
6780
useHistory: PropTypes.bool,
68-
usePlaceholder: PropTypes.bool,
69-
className: PropTypes.string
81+
usePlaceholder: PropTypes.bool
7082
}
7183

7284
AlgoliaSearch.defaultProps = {

components/molecules/AlgoliaSearch/components/History.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
import PropTypes from 'prop-types'
2-
import styles from '../AlgoliaSearch.module.css'
31
import dayjs from 'dayjs'
42
import relativeTime from 'dayjs/plugin/relativeTime'
3+
import PropTypes from 'prop-types'
4+
import styles from '../AlgoliaSearch.module.css'
55

66
/**
7-
* Component for rendering search history.
7+
* Render the History component.
8+
*
9+
* @author WebDevStudios
10+
* @param {object} props The component attributes as props.
11+
* @param {Function} props.buildSearchUrl Construct Search URL and navigate user to results.
12+
* @param {Function} props.clearLocalStorage Delete the localStorage for search results.
13+
* @param {Array} props.history The history of searches.
14+
* @param {Function} props.searchClick Click Event for Search Results
15+
* @return {Element} The History component.
816
*/
917
export default function History({
10-
history,
11-
searchClick,
18+
buildSearchUrl,
1219
clearLocalStorage,
13-
buildSearchUrl
20+
history,
21+
searchClick
1422
}) {
1523
/**
1624
* Convert date and time to relative from now.
1725
*
18-
* @author WebDevStudios
1926
* @see https://day.js.org/docs/en/display/from-now
2027
* @see https://day.js.org/docs/en/plugin/relative-time
21-
* @param {string} time The time as a timestamp.
22-
* @return {string} newTime Returns the string of relative time from now.
28+
* @param {string} time The time as a timestamp.
29+
* @return {string} Returns the string of relative time from now.
2330
*/
2431
function convertDate(time) {
2532
dayjs.extend(relativeTime)
@@ -57,13 +64,13 @@ export default function History({
5764
}
5865

5966
History.propTypes = {
67+
buildSearchUrl: PropTypes.func,
68+
clearLocalStorage: PropTypes.func,
6069
history: PropTypes.arrayOf(
6170
PropTypes.shape({
62-
title: PropTypes.string,
63-
time: PropTypes.number
71+
time: PropTypes.number,
72+
title: PropTypes.string
6473
})
6574
),
66-
searchClick: PropTypes.func,
67-
clearLocalStorage: PropTypes.func,
68-
buildSearchUrl: PropTypes.func
75+
searchClick: PropTypes.func
6976
}

components/molecules/AlgoliaSearch/components/Hit.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import PropTypes from 'prop-types'
2-
import searchClick from '../functions/searchClick'
32
import {Highlight} from 'react-instantsearch-dom'
3+
import searchClick from '../functions/searchClick'
44

55
/**
6-
* Component for rendering individual search result (Hit).
6+
* Render the Hit component.
7+
*
8+
* @author WebDevStudios
9+
* @see https://www.algolia.com/doc/api-reference/widgets/hits/react/
10+
* @param {object} props The component attributes as props.
11+
* @param {object} props.hit Renders each hit from the results.
12+
* @return {Element} The Hit component.
713
*/
814
export default function Hit({hit}) {
915
return (
1016
<button
1117
type="button"
1218
data-url={hit?.permalink}
13-
data-title={hit.post_title}
19+
data-title={hit?.post_title}
1420
onClick={(e) => searchClick(e)}
1521
>
1622
<Highlight attribute="post_title" hit={hit} />

components/molecules/AlgoliaSearch/components/Results.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Hit from './Hit'
2-
import History from './History'
1+
import PropTypes from 'prop-types'
32
import {connectStateResults, Hits} from 'react-instantsearch-dom'
43
import styles from '../AlgoliaSearch.module.css'
5-
import searchClick from '../functions/searchClick'
64
import buildSearchUrl from '../functions/buildSearchUrl'
7-
import PropTypes from 'prop-types'
5+
import searchClick from '../functions/searchClick'
6+
import History from './History'
7+
import Hit from './Hit'
88

99
/**
1010
* Component for rendering Algolia `Hits` and search `History` components.

components/molecules/AlgoliaSearch/components/Search.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import {searchClient} from '@/api/algolia/connector'
2-
import searchSubmit from '../functions/searchSubmit'
32
import PropTypes from 'prop-types'
43
import React, {useCallback, useEffect, useState} from 'react'
54
import {Configure, InstantSearch, SearchBox} from 'react-instantsearch-dom'
5+
import styles from '../AlgoliaSearch.module.css'
66
import {deleteLocalStorage} from '../functions/localStorage'
7+
import searchSubmit from '../functions/searchSubmit'
78
import Results from './Results'
8-
import styles from '../AlgoliaSearch.module.css'
99
import SearchIcon from './SearchIcon'
1010

1111
// TODO: Create Storybook for this component.
1212

1313
/**
14-
* Component for rendering Algolia search with hits and history.
14+
* Render the Search component.
15+
*
16+
* @author WebDevStudios
17+
* @param {object} props The component attributes as props.
18+
* @param {string} props.indexName The search index name stored in Algolia.
19+
* @param {string} props.query The search query
20+
* @param {boolean} props.useHistory Whether to display search history.
21+
* @return {Element} The Search component.
1522
*/
16-
export default function Search({indexName, useHistory, query}) {
23+
export default function Search({indexName, query, useHistory}) {
1724
const storageName = indexName // Local Storage Name - set to algolia index.
1825
const historyLength = 6 // Max amount of history items to save to local storage.
1926
const hitsPerPage = 6 // Amount of hit to render in drop results.
@@ -50,8 +57,10 @@ export default function Search({indexName, useHistory, query}) {
5057
}
5158
}, [storageName, useHistory])
5259

53-
// Delete recent searches and clear history.
54-
const clearLocalStorage = () => {
60+
/**
61+
* Delete recent searches and clear history.
62+
*/
63+
function clearLocalStorage() {
5564
deleteLocalStorage(storageName)
5665
setSearchHistory([])
5766
}
@@ -100,8 +109,8 @@ export default function Search({indexName, useHistory, query}) {
100109

101110
Search.propTypes = {
102111
indexName: PropTypes.string.isRequired,
103-
useHistory: PropTypes.bool,
104-
query: PropTypes.string
112+
query: PropTypes.string,
113+
useHistory: PropTypes.bool
105114
}
106115

107116
Search.defaultProps = {

components/molecules/AlgoliaSearch/components/SearchIcon.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/**
2-
* The magnify glass icon.
2+
* Render the SearchIcon component.
3+
*
4+
* @author WebDevStudios
5+
* @return {Element} The SearchIcon component.
36
*/
47
export default function SearchIcon() {
58
return (

components/molecules/AlgoliaSearch/components/SearchPlaceholder.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import SearchIcon from './SearchIcon'
2-
import styles from '../AlgoliaSearch.module.css'
31
import PropTypes from 'prop-types'
2+
import styles from '../AlgoliaSearch.module.css'
3+
import SearchIcon from './SearchIcon'
44

55
/**
6-
* This component renders a placeholder for the Algolia `Search` component.
7-
* The `Search` component is loaded using Dynamic Imports in Next once initiated by the user.
6+
* Render the SearchPlaceholder component.
7+
*
8+
* Note: the `Search` component is loaded using Dynamic Imports.
9+
*
10+
* @author WebDevStudios
11+
* @param {object} props The component attributes as props.
12+
* @param {Function} props.toggleAlgolia Toggle the Search component.
13+
* @param {string} props.query The search query.
14+
* @return {Element} The SearchPlaceholder component.
815
*/
916
export default function SearchPlaceholder({toggleAlgolia, query}) {
1017
return (

components/molecules/AlgoliaSearch/functions/buildSearchUrl.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* Construct Search URL and navigate user to results.
33
*
4-
* @param {string} Query param.
5-
* @return {string} destination url.
4+
* @author WebDevStudios
5+
* @param {string} query The search query.
6+
* @return {string} The search URL with search query.
67
*/
78
export default function buildSearchUrl(query) {
89
if (!query) {

components/molecules/AlgoliaSearch/functions/localStorage.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @param {string} name Local Storage name.
66
* @param {string} value The value to store.
77
* @param {number} maxLength Maximum history items to store.
8+
* @return {Function} Sets the value of the pair identified by key to value
89
*/
910
export function setLocalStorage(name, value, maxLength) {
1011
if (!localStorage) {
@@ -34,7 +35,9 @@ export function setLocalStorage(name, value, maxLength) {
3435
/**
3536
* Delete the localStorage for search results.
3637
*
37-
* @param {*} name Local Storage name.
38+
* @author WebDevStudios
39+
* @param {any} name Local Storage name.
40+
* @return {Function} Removes the key/value pair with the given key
3841
*/
3942
export function deleteLocalStorage(name) {
4043
if (!name) {
@@ -46,8 +49,10 @@ export function deleteLocalStorage(name) {
4649
/**
4750
* Remove duplicate entries from local storage.
4851
*
49-
* @param {*} array
50-
* @param {*} value
52+
* @author WebDevStudios
53+
* @param {*} array Potential localStorage items.
54+
* @param {*} value Potential duplicate items.
55+
* @return {Array} The the potential storage.
5156
*/
5257
function removeStorageDuplicates(array = [], value = '') {
5358
if (!array || !value) {
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/**
2-
* Click Event for Search Results
2+
* Click event for search results
33
*
44
* @author WebDevStudios
5-
* @param {*} e
5+
* @param {object} e The click event.
6+
* @return {object} The routed URL.
67
*/
7-
const searchClick = (e) => {
8+
export default function searchClick(e) {
89
const target = e.currentTarget
910
if (!target) {
1011
return false
@@ -16,5 +17,3 @@ const searchClick = (e) => {
1617
window.location = url
1718
}
1819
}
19-
20-
export default searchClick

0 commit comments

Comments
 (0)