-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat: HashTag API(#37)
- Loading branch information
Showing
10 changed files
with
160 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import axios from 'axios'; | ||
import { useLocation } from 'react-router-dom'; | ||
import HashTagClub from './hashTagClub'; | ||
import styles from '../../../menu/central_club/branch/branchCentral.module.css'; | ||
|
||
function BranchHashTag() { | ||
const [loading, setLoading] = useState(true); | ||
const [clubs, setClubs] = useState([]); | ||
const [error, setError] = useState(null); | ||
const location = useLocation(); | ||
const hashtag = location.state?.hashtag; | ||
|
||
const getHashTagClubs = async () => { | ||
try { | ||
setLoading(true); | ||
const response = await axios.get(`http://15.164.211.56:8080/v1/clubs?hashtag=${hashtag}`); | ||
setClubs(response.data.data.clubs); | ||
setError(null); | ||
} catch (error) { | ||
setError(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (hashtag) { | ||
getHashTagClubs(); | ||
} | ||
}, [hashtag]); // hashtag 값이 변경될 때마다 호출 | ||
|
||
if (loading) return <div>Loading...</div>; | ||
//if (error) return <div>Error: {error.message}</div>; | ||
|
||
const renderDataInRows = (data) => { | ||
const rows = []; | ||
for (let i = 0; i < data.length; i += 4) { | ||
const rowItems = data.slice(i, i + 4); | ||
rows.push( | ||
<div className={styles.container} key={i}> | ||
{rowItems.map((club) => ( | ||
<HashTagClub | ||
key={club.clubId} | ||
clubId={club.clubId} | ||
imageUrl={club.imageUrl} | ||
clubName={club.clubName} | ||
introduction={club.introduction} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} | ||
return rows; | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className={styles.wrap}> | ||
<div className={styles.header}> | ||
<h2 className={styles.header_title}># {hashtag}</h2> | ||
</div> | ||
{renderDataInRows(clubs)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default BranchHashTag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '../../../menu/central_club/branch/component/centralClub.module.css'; | ||
import { LinkItem } from '../../../menu/central_club/central_club'; | ||
|
||
function HashTagClub({ clubId, imageUrl, clubName, introduction }) { | ||
return ( | ||
<div className={styles.rectangle}> | ||
<LinkItem to={`/menu/small_club/detail_page/${clubId}`}> | ||
<img className={styles.image} alt={clubName} src={imageUrl} /> | ||
<h3 className={styles.title}>{clubName}</h3> | ||
<p className={styles.content}>{introduction}</p> | ||
</LinkItem> | ||
</div> | ||
); | ||
} | ||
|
||
HashTagClub.propTypes = { | ||
clubId: PropTypes.number.isRequired, | ||
imageUrl: PropTypes.string.isRequired, | ||
clubName: PropTypes.string.isRequired, | ||
introduction: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default HashTagClub; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters