Skip to content
Snippets Groups Projects
Commit 21c5f223 authored by Gwangbin's avatar Gwangbin
Browse files

Fix: some Article page errors

parent 528c5eda
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"express": "^4.18.2", "express": "^4.18.2",
"http-proxy-middleware": "^2.0.6", "http-proxy-middleware": "^2.0.6",
"jwt-decode": "^4.0.0", "jwt-decode": "^4.0.0",
"luxon": "^3.4.4",
"moment": "^2.29.4", "moment": "^2.29.4",
"react": "^18.2.0", "react": "^18.2.0",
"react-cookie": "^6.1.1", "react-cookie": "^6.1.1",
...@@ -13168,6 +13169,14 @@ ...@@ -13168,6 +13169,14 @@
"yallist": "^3.0.2" "yallist": "^3.0.2"
} }
}, },
"node_modules/luxon": {
"version": "3.4.4",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz",
"integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==",
"engines": {
"node": ">=12"
}
},
"node_modules/lz-string": { "node_modules/lz-string": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"express": "^4.18.2", "express": "^4.18.2",
"http-proxy-middleware": "^2.0.6", "http-proxy-middleware": "^2.0.6",
"jwt-decode": "^4.0.0", "jwt-decode": "^4.0.0",
"luxon": "^3.4.4",
"moment": "^2.29.4", "moment": "^2.29.4",
"react": "^18.2.0", "react": "^18.2.0",
"react-cookie": "^6.1.1", "react-cookie": "^6.1.1",
......
...@@ -3,32 +3,36 @@ import "../css/Article.css" ...@@ -3,32 +3,36 @@ import "../css/Article.css"
import { Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom'; import { Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { DateTime } from 'luxon';
function Article({ data }) { function Article({ data }) {
const [ const {
_id, title, content, images, author, _id, title, content, imageUrls, author,
keyword, latitude, longitude, keyword, latitude, longitude,
comments, likes, createdAt] = data; comments, likes, createdAt} = data;
const navigate = useNavigate(); const navigate = useNavigate();
function MoveTo(link) { function MoveTo(link) {
navigate(link) navigate(link)
} }
let listItem = [] let listItem = []
listItem = images.map((el)=>{ listItem = imageUrls.map((el) => {
// http://localhost:8080/uploads/21701487062905.png // http://localhost:8080/uploads/21701487062905.png
return ( return (
<img <img
src={`http://localhost:8080/${el.replaceAll("\\", "/").substring(7)}`} src={`http://localhost:8080/${el.replaceAll("\\", "/").substring(7)}`}
alt={`http://localhost:8080/${el.replaceAll("\\", "/").substring(7)}`} alt={`http://localhost:8080/${el.replaceAll("\\", "/").substring(7)}`}
style={{ width: "100px", height: "100px" }} /> style={{ width: "100px", height: "100px" }} />
)}); )
});
const date = DateTime.fromISO(createdAt).toFormat('yyyy년 MM월 dd일 HH:mm');
return ( return (
<div class="article" onClick={()=>{console.log(_id); MoveTo(`/post/${_id}`)}}> <div className="article" onClick={() => { console.log(_id); MoveTo(`/post/${_id}`) }}>
<h1>{title}</h1> <h1>{title}</h1>
<h2>{keyword}</h2> <h2>{keyword}</h2>
<h3>{author.nickname} {createdAt}</h3> <h3>{author.nickname} {date}</h3>
<p>{content}</p> <p>{content}</p>
<p>{listItem}</p> <p>{listItem}</p>
<p>댓글: {comments.length} // 조와요: {likes.length}</p> <p>댓글: {comments.length} // 조와요: {likes.length}</p>
......
...@@ -3,29 +3,24 @@ import "../css/Article.css" ...@@ -3,29 +3,24 @@ import "../css/Article.css"
import {Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom'; import {Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { DateTime } from 'luxon';
function Comments({data}) { function Comments({data}) {
const [ const {
_id, title, content, images, author, _id, content, author, createdAt} = data;
keyword, latitude, longitude,
comments, likes, createdAt] = data;
const navigate = useNavigate(); const navigate = useNavigate();
function MoveTo(link){ function MoveTo(link){
navigate(link) navigate(link)
} }
let listItem = []
listItem = comments.map((el)=>{ const date = DateTime.fromISO(createdAt).toFormat('yyyy년 MM월 dd일 HH:mm');
// http://localhost:8080/uploads/21701487062905.png
return(
<p>코맨트 테스트</p>
)});
return ( return (
<div class="comment"> <div class="comment">
<p>{'코맨트 테스트{'}</p> <p>{author.nickname}</p>
<p>{listItem}</p> <p>{content}</p>
<p>{'}코맨트 테스트'}</p> <p>{date}</p>
</div> </div>
); );
} }
......
...@@ -52,7 +52,9 @@ function SearchMapByKeyword({ loc, setLoc }) { ...@@ -52,7 +52,9 @@ function SearchMapByKeyword({ loc, setLoc }) {
const displayPagination = (pagination) => { const displayPagination = (pagination) => {
const links = []; const links = [];
for (let i = 1; i <= pagination.last; i++) { for (let i = 1; i <= pagination.last; i++) {
links.push(<a href="#" onClick={() => pagination.gotoPage(i)}>{i}</a>); links.push(<a href="#" key={i}
style={{ textDecoration: "none", color: "black" }}
onClick={() => pagination.gotoPage(i)}>{i}</a>);
} }
return links; return links;
...@@ -107,11 +109,14 @@ function SearchMapByKeyword({ loc, setLoc }) { ...@@ -107,11 +109,14 @@ function SearchMapByKeyword({ loc, setLoc }) {
</Map> </Map>
<div> <div>
<ul> <ul>
{markers.map((marker) => ( {markers.map((marker, index) => (
<li key={`marker-${marker.content}-${marker.position.lat},${marker.position.lng}`} <li key={`marker-${marker.content}-${marker.position.lat},${marker.position.lng}`}
onMouseOver={() => { setInfo(marker) }} onMouseOver={() => { setInfo(marker) }}
onMouseOut={() => { setInfo({ position: marker.position }) }}> onMouseOut={() => { setInfo({ position: marker.position }) }}>
<a href="#" style={{textDecoration:"none", color:"black"}} onClick={() => { <a href="#"
key={index}
style={{ textDecoration: "none", color: "black" }}
onClick={() => {
setLoc({ setLoc({
keyword: marker.content, keyword: marker.content,
center: { lat: marker.position.lat, lng: marker.position.lng } center: { lat: marker.position.lat, lng: marker.position.lng }
......
...@@ -24,7 +24,8 @@ function Main() { ...@@ -24,7 +24,8 @@ function Main() {
listItem = articleList.map((article)=>{ listItem = articleList.map((article)=>{
return( return(
<Article <Article
data={Object.values(article)} key={article._id}
data={article}
></Article> ></Article>
) )
} }
......
...@@ -4,7 +4,7 @@ import React, { useEffect, useState, useContext} from 'react'; ...@@ -4,7 +4,7 @@ import React, { useEffect, useState, useContext} from 'react';
import Article from '../components/Article.js'; import Article from '../components/Article.js';
import { UserContext } from '../Context.js'; import { UserContext } from '../Context.js';
import MapLocator from '../components/MapForLoaction.js'; import MapLocator from '../components/MapForLoaction.js';
import Comments from '../components/Comments.js'; import Comment from '../components/Comment.js';
import axios from 'axios'; import axios from 'axios';
axios.defaults.withCredentials = true; axios.defaults.withCredentials = true;
...@@ -48,7 +48,7 @@ function PostRead() { ...@@ -48,7 +48,7 @@ function PostRead() {
<div className="introduction" style={{display: 'flex'}}> <div className="introduction" style={{display: 'flex'}}>
<MapLocator loc={{lat: article.latitude, lng: article.longitude}} keyword={article.keyword}></MapLocator> <MapLocator loc={{lat: article.latitude, lng: article.longitude}} keyword={article.keyword}></MapLocator>
<div> <div>
<Article data={Object.values(article)}></Article> <Article data={article}></Article>
<button>조와요</button> <button>조와요</button>
</div> </div>
</div> </div>
...@@ -58,7 +58,13 @@ function PostRead() { ...@@ -58,7 +58,13 @@ function PostRead() {
<input type="text"></input> <input type="text"></input>
</div> </div>
</form> </form>
<Comments data={Object.values(article)}></Comments> {
article.comments.map((el)=>{
return(
<Comment key={el._id} data={el}></Comment>
)
})
}
</> </>
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment