|
@@ -8,14 +8,9 @@
|
|
|
<jsp:include page="/WEB-INF/jsp/include/head.jsp"></jsp:include>
|
|
|
<script>
|
|
|
let targetFeed = null;
|
|
|
- let params = {
|
|
|
- articleId: -1,
|
|
|
- feed: 'your-feed'
|
|
|
- };
|
|
|
- let query = Object.keys(params)
|
|
|
- .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(params[key]))
|
|
|
- .join('&');
|
|
|
- let url = '/article/page/users/${user.id}?' + query;
|
|
|
+ let params = {};
|
|
|
+ let query = null;
|
|
|
+ let url = null;
|
|
|
let loadingArticles = null;
|
|
|
let articleList = null;
|
|
|
const tagSet = new Set();
|
|
@@ -23,22 +18,6 @@
|
|
|
const follow = 'Follow ' + "${user.username}";
|
|
|
const unfollow = 'Unfollow ' + "${user.username}";
|
|
|
|
|
|
- // feed를 바꾼 경우
|
|
|
- const filterArticle = (option) => {
|
|
|
- const { clickedFeed } = option;
|
|
|
- const articles = document.querySelectorAll('.article-preview');
|
|
|
-
|
|
|
- articles.forEach(article => {
|
|
|
- let display = 'none';
|
|
|
-
|
|
|
- // display 기본 값은 none이고 값이 block으로 변경되는 경우만 조건으로 건다.
|
|
|
- if(clickedFeed === 'favorite-feed') {
|
|
|
- display = 'block';
|
|
|
- } else if(clickedFeed === 'your-feed') {
|
|
|
- display = 'block';
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
// 게시글 목록 로딩
|
|
|
const setLoading = (type) => {
|
|
|
let loadingDisplay = null;
|
|
@@ -56,7 +35,7 @@
|
|
|
articleList.style.display = contentDisplay;
|
|
|
}
|
|
|
|
|
|
- // 자신의 게시글이 없는 경우
|
|
|
+ // 게시글이 없는 경우
|
|
|
const noContent = () => {
|
|
|
if(articleList.firstChild === null) {
|
|
|
const p = document.createElement('p');
|
|
@@ -82,7 +61,8 @@
|
|
|
// targetFeed 초기화
|
|
|
targetFeed = currentFeed;
|
|
|
setLoading('on');
|
|
|
-
|
|
|
+ console.log(targetFeed)
|
|
|
+ console.log(articleList.firstChild)
|
|
|
// 게시글 초기화
|
|
|
while(articleList.firstChild) {
|
|
|
articleList.firstChild.remove();
|
|
@@ -91,7 +71,7 @@
|
|
|
params = {
|
|
|
articleId: -1,
|
|
|
feed: targetFeed.id
|
|
|
- }
|
|
|
+ };
|
|
|
query = Object.keys(params)
|
|
|
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(params[key]))
|
|
|
.join('&');
|
|
@@ -105,12 +85,14 @@
|
|
|
|
|
|
displayArticles(articles);
|
|
|
nextPageLoad(articles, paging);
|
|
|
+ console.log(articleList.firstChild)
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ setLoading('off');
|
|
|
+ noContent();
|
|
|
+ }, 1000)
|
|
|
})
|
|
|
- filterArticle({ 'clickedFeed': currentFeed.id });
|
|
|
- setTimeout(() => {
|
|
|
- setLoading('off');
|
|
|
- noContent();
|
|
|
- }, 1000);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 좋아요 버튼
|
|
@@ -161,15 +143,16 @@
|
|
|
// 사용자 팔로우
|
|
|
const userFollow = () => {
|
|
|
const followBtn = document.querySelector('.follow-btn');
|
|
|
+ const req = {
|
|
|
+ fromUser: "${ssId}",
|
|
|
+ toUser: "${user.id}"
|
|
|
+ };
|
|
|
|
|
|
if("${ssIsLogin}" === "true") { // 로그인한 경우에만 팔로우 기능 사용 가능
|
|
|
if(followBtn.classList.contains('active')) { // 팔로우 취소
|
|
|
followBtn.querySelector('.follow').textContent = follow;
|
|
|
fetch("/user/unfollow", {
|
|
|
- body: JSON.stringify({
|
|
|
- fromUser: "${ssId}",
|
|
|
- toUser: "${user.id}"
|
|
|
- }),
|
|
|
+ body: JSON.stringify(req),
|
|
|
method: 'DELETE',
|
|
|
headers: {
|
|
|
"Content-Type": "application/json"
|
|
@@ -183,10 +166,7 @@
|
|
|
} else { // 팔로우하기
|
|
|
followBtn.querySelector('.follow').textContent = unfollow;
|
|
|
fetch("/user/follow", {
|
|
|
- body: JSON.stringify({
|
|
|
- fromUser: "${ssId}",
|
|
|
- toUser: "${user.id}"
|
|
|
- }),
|
|
|
+ body: JSON.stringify(req),
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
"Content-Type": 'application/json'
|
|
@@ -271,7 +251,6 @@
|
|
|
const articlePreview = document.createElement('article');
|
|
|
articlePreview.classList.add('article-preview');
|
|
|
articlePreview.append(divArticleMeta, aPreviewLink);
|
|
|
- articlePreview.style.display = 'block';
|
|
|
articleList.appendChild(articlePreview);
|
|
|
})
|
|
|
}
|
|
@@ -280,7 +259,6 @@
|
|
|
// 더 조회될 수 있는 게시글이 있는지 여부
|
|
|
if(paging.isNext) {
|
|
|
const moreButton = document.createElement('button');
|
|
|
- const articleList = document.querySelector('#article-list');
|
|
|
const loading = document.createElement('div');
|
|
|
|
|
|
moreButton.textContent = '더보기';
|
|
@@ -294,7 +272,7 @@
|
|
|
articleList.appendChild(loading); // 로딩 생성
|
|
|
|
|
|
// 현재 페이지의 마지막 게시글 id
|
|
|
- params['articleId'] = articles[articles.length - 1].id;
|
|
|
+ params.articleId = articles[articles.length - 1].id;
|
|
|
query = Object.keys(params)
|
|
|
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(params[key]))
|
|
|
.join('&');
|
|
@@ -317,11 +295,21 @@
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
window.onload = () => {
|
|
|
targetFeed = document.querySelector('.nav-item.active');
|
|
|
loadingArticles = window.document.querySelector('#article-loading');
|
|
|
articleList = document.querySelector('#article-list');
|
|
|
+ params = {
|
|
|
+ articleId: -1,
|
|
|
+ feed: 'your-feed'
|
|
|
+ };
|
|
|
+ query = Object.keys(params)
|
|
|
+ .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(params[key]))
|
|
|
+ .join('&');
|
|
|
+ url = '/article/page/users/${user.id}?' + query;
|
|
|
|
|
|
+ // 팔로우 하고 있는 경우
|
|
|
const followString = document.querySelector('.follow-btn');
|
|
|
if("${isFollow}" === "true"){
|
|
|
followString.classList.add('active');
|