From bc86a5347277294d7c7f0641d51d1b7a9ae13239 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:49:39 +0900 Subject: [PATCH 01/27] =?UTF-8?q?user-activity-counts.vue=E3=82=92React?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/UserActivityCounts.jsx | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app/javascript/components/UserActivityCounts.jsx diff --git a/app/javascript/components/UserActivityCounts.jsx b/app/javascript/components/UserActivityCounts.jsx new file mode 100644 index 00000000000..8fdf7157f96 --- /dev/null +++ b/app/javascript/components/UserActivityCounts.jsx @@ -0,0 +1,69 @@ +import React from 'react' + +export default function UserActivityCounts({ user }) { + if (!user.student_or_trainee) { + return null + } + + return ( +
+
+
+
+
日報
+
+ {user.report_count} +
+
+
+
+
+
提出物
+
+ {user.product_count} +
+
+
+
+
+
コメント
+
+ {user.comment_count} +
+
+
+
+
+
質問
+
+ {user.question_count} +
+
+
+
+
+
回答
+
+ {user.answer_count} +
+
+
+
+
+ ) +} From e73162ac5e8eb7bbe4f9880e70af1a29552973c9 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:09:50 +0900 Subject: [PATCH 02/27] =?UTF-8?q?user-sns.vue=E3=82=92React=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/UserSns.jsx | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 app/javascript/components/UserSns.jsx diff --git a/app/javascript/components/UserSns.jsx b/app/javascript/components/UserSns.jsx new file mode 100644 index 00000000000..c62cae0c9af --- /dev/null +++ b/app/javascript/components/UserSns.jsx @@ -0,0 +1,78 @@ +import React from 'react' + +export default function UserSns({ user }) { + const githubUrl = `https://github.com/${user.github_account}` + const twitterUrl = `https://twitter.com/${user.twitter_account}` + + return ( +
+ +
+ ) +} From 632de7ceddf025cdc0cac4f92683fb7b0ed4e2c1 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:15:21 +0900 Subject: [PATCH 03/27] =?UTF-8?q?user-tags.vue=E3=82=92React=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/UserTags.jsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/javascript/components/UserTags.jsx diff --git a/app/javascript/components/UserTags.jsx b/app/javascript/components/UserTags.jsx new file mode 100644 index 00000000000..6556a7d19cc --- /dev/null +++ b/app/javascript/components/UserTags.jsx @@ -0,0 +1,25 @@ +import React from 'react' + +export default function UserTags({ user }) { + const tags = user.tag_list + + if (tags.length === 0) { + return null + } + + return ( +
+ +
+ ) +} From e975cdca6aa3d78d0539adda7552b68d80ad69db Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:19:55 +0900 Subject: [PATCH 04/27] =?UTF-8?q?user-practice-progress.vue=E3=82=92React?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/UserPracticeProgress.jsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/javascript/components/UserPracticeProgress.jsx diff --git a/app/javascript/components/UserPracticeProgress.jsx b/app/javascript/components/UserPracticeProgress.jsx new file mode 100644 index 00000000000..d0c2cce21c1 --- /dev/null +++ b/app/javascript/components/UserPracticeProgress.jsx @@ -0,0 +1,32 @@ +import React from 'react' + +export default function UserPracticeProgress({ user }) { + const percentage = user.cached_completed_percentage + const fraction = user.completed_fraction + + const roundedPercentage = user.graduated_on + ? '100%' + : Math.round(percentage) + '%' + + const ariaValuenow = user.graduated_on ? 100 : percentage + + const completedPracticesProgressNumber = user.graduated_on ? '卒業' : fraction + + return ( +
+
+
+
+
+
+ {completedPracticesProgressNumber} +
+
+ ) +} From ae4a1b504650df661345c22c4c9e6a6d907a1da1 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:43:12 +0900 Subject: [PATCH 05/27] =?UTF-8?q?following.vue=E3=82=92React=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Following.jsx | 149 ++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 app/javascript/components/Following.jsx diff --git a/app/javascript/components/Following.jsx b/app/javascript/components/Following.jsx new file mode 100644 index 00000000000..aaedf47e3fb --- /dev/null +++ b/app/javascript/components/Following.jsx @@ -0,0 +1,149 @@ +import React, { useState, useRef } from 'react' +import CSRF from '../csrf.js' + +export default function Following({ isFollowing, userId, isWatching }) { + const [following, setFollowing] = useState(isFollowing) + const [watching, setWatching] = useState(isWatching) + const followingDetailsRef = useRef(null) + + const url = () => `/api/users/${userId}/followings` + + const followOrChangeFollow = (watch) => { + const params = { watch: watch } + fetch(url(), { + method: following ? 'PATCH' : 'POST', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRF-Token': CSRF.getToken() + }, + credentials: 'same-origin', + redirect: 'manual', + body: JSON.stringify(params) + }) + .then((response) => { + if (response.ok) { + setFollowing(true) + setWatching(watch) + } else { + alert('エラーが発生しました。') + } + }) + .catch((error) => { + console.warn(error) + }) + .finally(() => { + followingDetailsRef.current.open = false + }) + } + + const unfollow = () => { + const params = { watch: watching } + fetch(url(), { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRF-Token': CSRF.getToken() + }, + credentials: 'same-origin', + redirect: 'manual', + body: JSON.stringify(params) + }) + .then((response) => { + if (response.ok) { + setFollowing(false) + setWatching(false) + } else { + alert('エラーが発生しました。') + } + }) + .catch((error) => { + console.warn(error) + }) + .finally(() => { + followingDetailsRef.current.open = false + }) + } + + return ( +
+ + {following && watching ? ( + + + コメントあり + + ) : following && !watching ? ( + + + コメントなし + + ) : ( + + フォローする + + )} + +
+ +
+
+ ) +} From d615ebf83ed75454ec648941312cd42726f36fdb Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:16:42 +0900 Subject: [PATCH 06/27] =?UTF-8?q?user.vue=E3=82=92React=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/User.jsx | 89 ++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 app/javascript/components/User.jsx diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx new file mode 100644 index 00000000000..0c47cf4f0db --- /dev/null +++ b/app/javascript/components/User.jsx @@ -0,0 +1,89 @@ +import React from 'react' +import UserSns from './UserSns.jsx' +import UserActivityCounts from './UserActivityCounts.jsx' +import UserTags from './UserTags.jsx' +import UserPracticeProgress from './UserPracticeProgress.jsx' +import Following from './Following.jsx' + +export default function User({ user, currentUser }) { + const userDescParagraphs = () => { + let description = user.description + description = + description.length <= 200 + ? description + : description.substring(0, 200) + '...' + const paragraphs = description.split(/\n|\r\n/).map((text, i) => { + return { + id: i, + text: text + } + }) + return paragraphs + } + + const roleClass = () => { + return `is-${user.primary_role}` + } + + return ( +
+
+
+ {currentUser.id !== user.id && + currentUser.mentor && + user.student_or_trainee && + !user.active && ( +
+ 1ヶ月以上ログインがありません +
+ )} +
+
+
+ +
+
+
+
+ +
+
+
+
+
+ + +
+
+ {userDescParagraphs().map((paragraph) => ( +

{paragraph.text}

+ ))} +
+
+ +
+
+ + +
+
+
+ ) +} From a01e3aeb266e640ce1570ce59f4635d3ae95bad4 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Tue, 2 Jan 2024 22:27:37 +0900 Subject: [PATCH 07/27] =?UTF-8?q?react-paginate=E3=82=92=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + yarn.lock | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 333c8a16cc8..d99356898e6 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "query-string": "^7.1.1", "react": "^17.0.0", "react-dom": "^17.0.0", + "react-paginate": "^8.2.0", "react-router-dom": "^6.4.1", "react_ujs": "^2.6.2", "select2": "^4.0.7-rc.0", diff --git a/yarn.lock b/yarn.lock index fe5b37d562c..09526265bb0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7486,7 +7486,7 @@ promise@^7.0.1: dependencies: asap "~2.0.3" -prop-types@^15.8.1: +prop-types@^15, prop-types@^15.8.1: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== @@ -7766,6 +7766,13 @@ react-is@^16.13.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== +react-paginate@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/react-paginate/-/react-paginate-8.2.0.tgz#947c3dcb444a6c16c1bcf8361871aa135baa3dcd" + integrity sha512-sJCz1PW+9PNIjUSn919nlcRVuleN2YPoFBOvL+6TPgrH/3lwphqiSOgdrLafLdyLDxsgK+oSgviqacF4hxsDIw== + dependencies: + prop-types "^15" + react-router-dom@^6.4.1: version "6.18.0" resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.18.0.tgz#0a50c167209d6e7bd2ed9de200a6579ea4fb1dca" From 3f9cf98bb4150932f5d18fcbdff5e61e22f4e670 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Tue, 2 Jan 2024 22:29:32 +0900 Subject: [PATCH 08/27] =?UTF-8?q?pager.vue=E3=82=92React=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Pager.jsx | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/javascript/components/Pager.jsx diff --git a/app/javascript/components/Pager.jsx b/app/javascript/components/Pager.jsx new file mode 100644 index 00000000000..c5a385e8ec8 --- /dev/null +++ b/app/javascript/components/Pager.jsx @@ -0,0 +1,36 @@ +import React from 'react' +import ReactPaginate from 'react-paginate' + +export default function Pager({ + initialPageNumber, + pageCount, + pageRange, + clickHandle +}) { + const makeITag = (iconName) => { + return `` + } + + return ( + + ) +} From b7ce9e72f784600da1847eee94baf0a8f0fbeac7 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 6 Jan 2024 22:38:03 +0900 Subject: [PATCH 09/27] =?UTF-8?q?User=E3=82=B3=E3=83=B3=E3=83=9D=E3=83=BC?= =?UTF-8?q?=E3=83=8D=E3=83=B3=E3=83=88=E3=81=AE=E6=9D=A1=E4=BB=B6=E3=81=A8?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E5=90=8D=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/User.jsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx index 0c47cf4f0db..211bffc6121 100644 --- a/app/javascript/components/User.jsx +++ b/app/javascript/components/User.jsx @@ -29,14 +29,11 @@ export default function User({ user, currentUser }) {
- {currentUser.id !== user.id && - currentUser.mentor && - user.student_or_trainee && - !user.active && ( -
- 1ヶ月以上ログインがありません -
- )} + {currentUser.mentor && user.student_or_trainee && !user.active && ( +
+ 1ヶ月以上ログインがありません +
+ )}
@@ -57,7 +54,11 @@ export default function User({ user, currentUser }) { From a22c33acc35f6869ecbd7bcc7cb3aed4bd7d48e7 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Mon, 8 Jan 2024 00:09:07 +0900 Subject: [PATCH 10/27] =?UTF-8?q?=E9=96=A2=E6=95=B0=E3=80=81=E3=83=97?= =?UTF-8?q?=E3=83=AD=E3=83=91=E3=83=86=E3=82=A3=E3=80=81=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=92Vue=E7=89=88=E3=81=AB=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=81=A6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Pager.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/javascript/components/Pager.jsx b/app/javascript/components/Pager.jsx index c5a385e8ec8..67188c8928c 100644 --- a/app/javascript/components/Pager.jsx +++ b/app/javascript/components/Pager.jsx @@ -8,15 +8,15 @@ export default function Pager({ clickHandle }) { const makeITag = (iconName) => { - return `` + return } return ( clickHandle(event.selected + 1)} previousLabel={makeITag('left')} nextLabel={makeITag('right')} breakLabel={'...'} From 986b0b3a54334e1eb3fb6498f4a98e4c6937847d Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 18 Jan 2024 00:18:34 +0900 Subject: [PATCH 11/27] =?UTF-8?q?generation-users.vue=E3=82=92React?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/GenerationUsers.jsx | 139 ++++++++++++++++++ app/javascript/components/User.jsx | 2 +- app/javascript/packs/application.js | 1 - app/views/generations/show.html.slim | 2 +- 4 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 app/javascript/components/GenerationUsers.jsx diff --git a/app/javascript/components/GenerationUsers.jsx b/app/javascript/components/GenerationUsers.jsx new file mode 100644 index 00000000000..c1d6d1541c3 --- /dev/null +++ b/app/javascript/components/GenerationUsers.jsx @@ -0,0 +1,139 @@ +import React, { useState, useEffect, useMemo } from 'react' +import User from './User.jsx' +import Pager from './Pager.jsx' +import CSRF from 'csrf' + +const getParams = () => { + const params = new URLSearchParams(location.search) + const result = {} + for (const [key, value] of params) { + result[key] = value + } + if (location.pathname.match(/tags/)) { + const tag = location.pathname.split('/').pop() + result.tag = tag + } + return result +} + +export default function GenerationUsers({ generationID }) { + const [users, setUsers] = useState(null) + const [currentUser, setCurrentUser] = useState(null) + const [currentTarget, setCurrentTarget] = useState(null) + const [currentTag, setCurrentTag] = useState(null) + const [currentPage, setCurrentPage] = useState(Number(getParams().page) || 1) + const [totalPages, setTotalPages] = useState(0) + const [params] = useState(getParams()) + + const targetName = useMemo( + () => currentTag || currentTarget, + [currentTag, currentTarget] + ) + + useEffect(() => { + window.onpopstate = () => { + location.replace(location.href) + } + getUsers() + }, []) + + useEffect(() => { + getUsers() + }, [currentPage, params]) + + const getUsers = () => { + const url = + `/api/generations/${generationID}.json` + + (params.tag ? `tags/${params.tag}` : '') + + `?page=${currentPage}` + + (params.target ? `&target=${params.target}` : '') + + (params.watch ? `&watch=${params.watch}` : '') + fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRF-Token': CSRF.getToken() + }, + credentials: 'same-origin', + redirect: 'manual' + }) + .then((response) => response.json()) + .then((json) => { + setUsers(json.users) + setCurrentUser(json.currentUser) + setCurrentTarget(json.target) + setCurrentTag(json.tag) + setTotalPages(json.totalPages) + }) + .catch((error) => { + console.warn(error) + }) + } + + const paginateClickCallback = (pageNumber) => { + setCurrentPage(pageNumber) + history.pushState(null, null, newUrl(pageNumber)) + window.scrollTo(0, 0) + } + + const newUrl = (pageNumber) => { + let url = location.pathname + url += params.target ? `?target=${params.target}` : '' + url += pageNumber === 1 ? '' : `&page=${pageNumber}` + return url + } + + const pagerProps = { + initialPageNumber: currentPage, + pageCount: totalPages, + pageRange: 5, + clickHandle: paginateClickCallback + } + + return ( +
+ {totalPages > 1 && ( + + )} +
+
+ {users === null ? ( +
+
+ + ロード中 +
+
+ ) : users.length !== 0 ? ( + users.map((user) => ( + + )) + ) : ( +
+
+
+ +
+

+ {generationID}期のユーザー一覧はありません +

+
+
+ )} +
+
+ {totalPages > 1 && ( + + )} +
+ ) +} diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx index 211bffc6121..8820eec3281 100644 --- a/app/javascript/components/User.jsx +++ b/app/javascript/components/User.jsx @@ -29,7 +29,7 @@ export default function User({ user, currentUser }) {
- {currentUser.mentor && user.student_or_trainee && !user.active && ( + {currentUser?.mentor && user.student_or_trainee && !user.active && (
1ヶ月以上ログインがありません
diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 030de2e9e03..0a07e55d1c1 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -40,7 +40,6 @@ import '../book-select.js' import '../subscription-status.js' import '../new-event-date-set.js' import '../company-users.js' -import '../generation-users.js' import '../learning-completion-message.js' import '../choices-ui.js' import '../training-info-toggler.js' diff --git a/app/views/generations/show.html.slim b/app/views/generations/show.html.slim index 574b39d26bc..b00cf72db9b 100644 --- a/app/views/generations/show.html.slim +++ b/app/views/generations/show.html.slim @@ -27,4 +27,4 @@ main.page-main = link_to generations_path, class: 'a-button is-sm is-block is-secondary is-back' do | 期一覧 hr.a-border - #js-generation-users(generation-id="#{@generation}") + = react_component 'GenerationUsers', generationID: @generation From 085b718bfa988e82ba511afd4e85430759d4019c Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:30:42 +0900 Subject: [PATCH 12/27] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E8=A8=98?= =?UTF-8?q?=E8=BF=B0=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/GenerationUsers.jsx | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/app/javascript/components/GenerationUsers.jsx b/app/javascript/components/GenerationUsers.jsx index c1d6d1541c3..47e3e97e637 100644 --- a/app/javascript/components/GenerationUsers.jsx +++ b/app/javascript/components/GenerationUsers.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useMemo } from 'react' +import React, { useState, useEffect } from 'react' import User from './User.jsx' import Pager from './Pager.jsx' import CSRF from 'csrf' @@ -19,17 +19,10 @@ const getParams = () => { export default function GenerationUsers({ generationID }) { const [users, setUsers] = useState(null) const [currentUser, setCurrentUser] = useState(null) - const [currentTarget, setCurrentTarget] = useState(null) - const [currentTag, setCurrentTag] = useState(null) const [currentPage, setCurrentPage] = useState(Number(getParams().page) || 1) const [totalPages, setTotalPages] = useState(0) const [params] = useState(getParams()) - const targetName = useMemo( - () => currentTag || currentTarget, - [currentTag, currentTarget] - ) - useEffect(() => { window.onpopstate = () => { location.replace(location.href) @@ -62,8 +55,6 @@ export default function GenerationUsers({ generationID }) { .then((json) => { setUsers(json.users) setCurrentUser(json.currentUser) - setCurrentTarget(json.target) - setCurrentTag(json.tag) setTotalPages(json.totalPages) }) .catch((error) => { @@ -101,13 +92,11 @@ export default function GenerationUsers({ generationID }) { )}
-
+
{users === null ? ( -
-
- - ロード中 -
+
+ + ロード中
) : users.length !== 0 ? ( users.map((user) => ( From 6bfe5c90580b3c75fe8b588d0756ecd4b58c25a4 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:36:36 +0900 Subject: [PATCH 13/27] =?UTF-8?q?User.jsx=E3=81=AE=E4=B8=8D=E8=B6=B3?= =?UTF-8?q?=E9=83=A8=E5=88=86=E3=82=92=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/User.jsx | 100 ++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx index 8820eec3281..554c5512eb9 100644 --- a/app/javascript/components/User.jsx +++ b/app/javascript/components/User.jsx @@ -29,11 +29,28 @@ export default function User({ user, currentUser }) {
- {currentUser?.mentor && user.student_or_trainee && !user.active && ( -
- 1ヶ月以上ログインがありません -
- )} + {currentUser && + (currentUser.mentor || currentUser.admin) && + user.student_or_trainee && ( +
+ {user.roles.includes('retired') && ( +
+ 退会しました +
+ )} + {user.roles.includes('hibernationed') && ( +
+ 休会中: {user.hibernated_at}〜( + {user.hibernation_elapsed_days}日経過) +
+ )} + {!user.active && ( +
+ 1ヶ月以上ログインがありません +
+ )} +
+ )}
@@ -59,6 +76,38 @@ export default function User({ user, currentUser }) { href={user.url}> {user.login_name} + {user.company && user.company.logo_url && ( + + + + )} +
+
+
+
+
+
+
{user.name}
+
+
+ {user.discord_profile.times_url ? ( + + + {user.discord_profile.account_name} + + ) : ( +
+ + {user.discord_profile.account_name} +
+ )} +
+
@@ -78,11 +127,42 @@ export default function User({ user, currentUser }) {
- +
+
+
+
    + {currentUser.id !== user.id && + currentUser.adviser && + user.company && + currentUser.company_id === user.company.id && ( +
  • +
    + + 自社研修生 +
    +
  • + )} + {currentUser.id !== user.id && ( +
  • + +
  • + )} + {currentUser.admin && user.talkUrl && ( +
  • + + 相談部屋 + +
  • + )} +
+
+
From 9c714201d42758c2288c2e4a038d5f1a9c9cfe6c Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 15 Feb 2024 22:26:04 +0900 Subject: [PATCH 14/27] =?UTF-8?q?=E6=9C=9F=E7=94=9F=E5=88=A5=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E3=82=92=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/GenerationUsers.jsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/javascript/components/GenerationUsers.jsx b/app/javascript/components/GenerationUsers.jsx index 47e3e97e637..fd9018a301c 100644 --- a/app/javascript/components/GenerationUsers.jsx +++ b/app/javascript/components/GenerationUsers.jsx @@ -28,6 +28,7 @@ export default function GenerationUsers({ generationID }) { location.replace(location.href) } getUsers() + getCurrentUser() }, []) useEffect(() => { @@ -62,6 +63,22 @@ export default function GenerationUsers({ generationID }) { }) } + const getCurrentUser = () => { + fetch('/api/generations/&{generationID}', { + method: 'GET', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRF-Token': CSRF.getToken() + }, + credentials: 'same-origin', + redirect: 'manual' + }) + .then((response) => response.json()) + .then((data) => setCurrentUser(data)) + .catch((error) => console.error('Error fetching current user:', error)) + } + const paginateClickCallback = (pageNumber) => { setCurrentPage(pageNumber) history.pushState(null, null, newUrl(pageNumber)) From fb2802b8ea99596c3b3af3c3eb9345e1dc0a719c Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 15 Feb 2024 23:17:45 +0900 Subject: [PATCH 15/27] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/generations/show.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/generations/show.html.slim b/app/views/generations/show.html.slim index b00cf72db9b..c600b802004 100644 --- a/app/views/generations/show.html.slim +++ b/app/views/generations/show.html.slim @@ -27,4 +27,4 @@ main.page-main = link_to generations_path, class: 'a-button is-sm is-block is-secondary is-back' do | 期一覧 hr.a-border - = react_component 'GenerationUsers', generationID: @generation + = react_component 'GenerationUsers', generationID: @generation From fe8402fc964ce74dd1c36bb4dadf58c4b5f40592 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 18 Feb 2024 23:39:55 +0900 Subject: [PATCH 16/27] =?UTF-8?q?UserActivityCounts.jsx=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/UserActivityCounts.jsx | 84 +++++++------------ 1 file changed, 29 insertions(+), 55 deletions(-) diff --git a/app/javascript/components/UserActivityCounts.jsx b/app/javascript/components/UserActivityCounts.jsx index 8fdf7157f96..adec0da2d90 100644 --- a/app/javascript/components/UserActivityCounts.jsx +++ b/app/javascript/components/UserActivityCounts.jsx @@ -5,64 +5,38 @@ export default function UserActivityCounts({ user }) { return null } + const activities = [ + { name: '日報', count: user.report_count, url: `${user.url}/reports` }, + { name: '提出物', count: user.product_count, url: `${user.url}/products` }, + { + name: 'コメント', + count: user.comment_count, + url: `${user.url}/comments` + }, + { name: '質問', count: user.question_count, url: `${user.url}/questions` }, + { name: '回答', count: user.answer_count, url: `${user.url}/answers` } + ] + return ( -
+
-
-
-
日報
-
- {user.report_count} -
-
-
-
-
-
提出物
-
- {user.product_count} -
-
-
-
-
-
コメント
-
- {user.comment_count} -
-
-
-
-
-
質問
-
- {user.question_count} -
-
-
-
-
-
回答
-
- {user.answer_count} -
+ {activities.map((activity) => ( +
+
+
{activity.name}
+
+ {activity.count === 0 ? ( + {activity.count} + ) : ( + {activity.count} + )} +
+
-
+ ))}
) From 96a550e8002c79726c6eedddeb85c2963ba4f2b8 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:22:21 +0900 Subject: [PATCH 17/27] =?UTF-8?q?Following.jsx=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Following.jsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/javascript/components/Following.jsx b/app/javascript/components/Following.jsx index aaedf47e3fb..75af76323a2 100644 --- a/app/javascript/components/Following.jsx +++ b/app/javascript/components/Following.jsx @@ -134,13 +134,21 @@ export default function Following({ isFollowing, userId, isWatching }) { )}
  • - + {!following && !watching ? ( + + ) : ( + + )}
  • From e4bacff19c2a15dad459d916aa7c9cd46d55d587 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:23:59 +0900 Subject: [PATCH 18/27] =?UTF-8?q?User.jsx=E3=81=AE=E5=BE=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/User.jsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx index 554c5512eb9..1197a916c6b 100644 --- a/app/javascript/components/User.jsx +++ b/app/javascript/components/User.jsx @@ -1,9 +1,9 @@ import React from 'react' -import UserSns from './UserSns.jsx' +import Following from './Following.jsx' import UserActivityCounts from './UserActivityCounts.jsx' +import UserSns from './UserSns.jsx' import UserTags from './UserTags.jsx' import UserPracticeProgress from './UserPracticeProgress.jsx' -import Following from './Following.jsx' export default function User({ user, currentUser }) { const userDescParagraphs = () => { @@ -21,9 +21,7 @@ export default function User({ user, currentUser }) { return paragraphs } - const roleClass = () => { - return `is-${user.primary_role}` - } + const roleClass = () => `is-${user.primary_role}` return (
    From 4afe96a331eabffd1ccf021d583bed80125d2d54 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 25 Feb 2024 13:16:37 +0900 Subject: [PATCH 19/27] =?UTF-8?q?5=E6=9C=9F=E7=94=9F=E3=81=AE=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=8D=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=92=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Pager.jsx | 54 +++++++++++++++++------------ db/fixtures/discord_profiles.yml | 10 ++++++ db/fixtures/users.yml | 34 ++++++++++++++++++ test/fixtures/discord_profiles.yml | 10 ++++++ test/fixtures/talks.yml | 8 +++++ test/fixtures/users.yml | 34 ++++++++++++++++++ 6 files changed, 127 insertions(+), 23 deletions(-) diff --git a/app/javascript/components/Pager.jsx b/app/javascript/components/Pager.jsx index 67188c8928c..4b375847060 100644 --- a/app/javascript/components/Pager.jsx +++ b/app/javascript/components/Pager.jsx @@ -7,30 +7,38 @@ export default function Pager({ pageRange, clickHandle }) { - const makeITag = (iconName) => { - return - } + const makeITag = (iconName) => return ( - clickHandle(event.selected + 1)} - previousLabel={makeITag('left')} - nextLabel={makeITag('right')} - breakLabel={'...'} - breakClassName={'break-me'} - marginPagesDisplayed={0} - containerClassName={'pagination__items'} - pageClassName={'pagination__item'} - pageLinkClassName={'pagination__item-link'} - previousClassName={'pagination__item is-prev'} - previousLinkClassName={'pagination__item-link is-prev'} - nextClassName={'pagination__item is-next'} - nextLinkClassName={'pagination__item-link is-next'} - activeClassName={'is-active'} - disabledClassName={'is-disabled'} - /> +
    + + + clickHandle(e.selected + 1)} + containerClassName="pagination__items" + pageClassName="pagination__item" + pageLinkClassName="pagination__item-link" + previousClassName="pagination__item is-prev" + previousLinkClassName="pagination__item-link is-prev" + nextClassName="pagination__item is-next" + nextLinkClassName="pagination__item-link is-next" + activeClassName="is-active" + disabledClassName="is-disabled" + /> + + +
    ) } diff --git a/db/fixtures/discord_profiles.yml b/db/fixtures/discord_profiles.yml index 260e2fbca4f..8ae58483bca 100644 --- a/db/fixtures/discord_profiles.yml +++ b/db/fixtures/discord_profiles.yml @@ -290,6 +290,16 @@ discord_profire_pjord: account_name: times_url: +discord_profile_paginataion-taro: + user: paginataion-taro + account_name: + times_url: + +discord_profile_paginataion-jirou: + user: paginataion-jirou + account_name: + times_url: + discord_profile_nippou199: # ステージング環境で日報200回目のお祝いメッセージの動作確認が終わり次第、削除します user: nippou199 account_name: diff --git a/db/fixtures/users.yml b/db/fixtures/users.yml index 483d22b57f1..9c137421688 100644 --- a/db/fixtures/users.yml +++ b/db/fixtures/users.yml @@ -1367,6 +1367,40 @@ nagai-kyuukai: sent_student_followup_message: true last_activity_at: "2014-01-01 00:00:04" +paginataion-taro: + login_name: paginataion-taro + email: paginataion-taro@fjord.jp + crypted_password: $2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k.lCm0frPK. # testtest + salt: zW3kQ9ubsxQQtzzzs4ap + name: ページネーション 太郎 + name_kana: ページネーション タロウ + description: "ページネーションを確認するため追加したユーザーです。" + course: course1 + job: office_worker + os: mac + experience: inexperienced + updated_at: "2014-01-01 00:00:07" + created_at: "2014-01-01 00:00:07" + sent_student_followup_message: true + last_activity_at: "2014-01-01 00:00:07" + +paginataion-jirou: + login_name: paginataion-jirou + email: paginataion-jirou@example.com + crypted_password: $2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k.lCm0frPK. # testtest + salt: zW3kQ9ubsxQQtzzzs4ap + name: ページネーション 次郎 + name_kana: ページネーション ジロウ + description: "ページネーションを確認するため追加したユーザーです。" + course: course1 + job: office_worker + os: mac + experience: inexperienced + updated_at: "2014-01-01 00:00:07" + created_at: "2014-01-01 00:00:07" + sent_student_followup_message: true + last_activity_at: "2014-01-01 00:00:07" + pjord: login_name: pjord email: diff --git a/test/fixtures/discord_profiles.yml b/test/fixtures/discord_profiles.yml index 5777fc15a30..fb60146a874 100644 --- a/test/fixtures/discord_profiles.yml +++ b/test/fixtures/discord_profiles.yml @@ -188,6 +188,16 @@ discord_profile_tom: account_name: times_url: +discord_profile_paginataion-taro: + user: paginataion-taro + account_name: + times_url: + +discord_profile_paginataion-jirou: + user: paginataion-jirou + account_name: + times_url: + discord_profile_pjord: user: pjord account_name: diff --git a/test/fixtures/talks.yml b/test/fixtures/talks.yml index 6c6cbfc310d..c860e5d5e74 100644 --- a/test/fixtures/talks.yml +++ b/test/fixtures/talks.yml @@ -133,6 +133,14 @@ talk34: user: kyuukai action_completed: true +tal35: + user: paginataion-taro + action_completed: true + +talk36: + user: paginataion-jirou + action_completed: true + talk_advisernocolleguetrainee: user: advisernocolleguetrainee action_completed: true diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 9eb74b51342..47c8760c8cf 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -913,6 +913,40 @@ tom: #アメリカ在住のユーザー created_at: "2023-05-08 00:00:00" last_activity_at: "2023-05-08 00:00:00" +paginataion-taro: + login_name: paginataion-taro + email: paginataion-taro@fjord.jp + crypted_password: $2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k.lCm0frPK. # testtest + salt: zW3kQ9ubsxQQtzzzs4ap + name: ページネーション 太郎 + name_kana: ページネーション タロウ + description: "ページネーションを確認するため追加したユーザーです。" + course: course1 + job: office_worker + os: mac + experience: inexperienced + updated_at: "2014-01-01 00:00:07" + created_at: "2014-01-01 00:00:07" + sent_student_followup_message: true + last_activity_at: "2014-01-01 00:00:07" + +paginataion-jirou: + login_name: paginataion-jirou + email: paginataion-jirou@example.com + crypted_password: $2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k.lCm0frPK. # testtest + salt: zW3kQ9ubsxQQtzzzs4ap + name: ページネーション 次郎 + name_kana: ページネーション ジロウ + description: "ページネーションを確認するため追加したユーザーです。" + course: course1 + job: office_worker + os: mac + experience: inexperienced + updated_at: "2014-01-01 00:00:07" + created_at: "2014-01-01 00:00:07" + sent_student_followup_message: true + last_activity_at: "2014-01-01 00:00:07" + pjord: login_name: pjord email: From 7e221df7174e0ffaf75f525af5a5431a92ee876f Mon Sep 17 00:00:00 2001 From: machida Date: Tue, 5 Mar 2024 15:35:43 +0900 Subject: [PATCH 20/27] =?UTF-8?q?=E3=83=87=E3=82=B6=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E5=B4=A9=E3=82=8C=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Pager.jsx | 2 +- app/javascript/components/User.jsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/javascript/components/Pager.jsx b/app/javascript/components/Pager.jsx index 4b375847060..ecef93f1ed7 100644 --- a/app/javascript/components/Pager.jsx +++ b/app/javascript/components/Pager.jsx @@ -10,7 +10,7 @@ export default function Pager({ const makeITag = (iconName) => return ( -
    +
    diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx index 1197a916c6b..d3f7e427af8 100644 --- a/app/javascript/components/User.jsx +++ b/app/javascript/components/User.jsx @@ -109,11 +109,11 @@ export default function User({ user, currentUser }) {
    +
    +
    - -
    {userDescParagraphs().map((paragraph) => ( From acf95f664d193e15131a96e1239eeac4b5a44f1d Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 8 Mar 2024 19:53:22 +0900 Subject: [PATCH 21/27] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/generation-users.js | 18 ---- app/javascript/generation-users.vue | 146 ---------------------------- 2 files changed, 164 deletions(-) delete mode 100644 app/javascript/generation-users.js delete mode 100644 app/javascript/generation-users.vue diff --git a/app/javascript/generation-users.js b/app/javascript/generation-users.js deleted file mode 100644 index 1b1fd6f1644..00000000000 --- a/app/javascript/generation-users.js +++ /dev/null @@ -1,18 +0,0 @@ -import Vue from 'vue' -import GenerationUsers from 'generation-users.vue' - -document.addEventListener('DOMContentLoaded', () => { - const selector = '#js-generation-users' - const users = document.querySelector(selector) - if (users) { - const generationID = users.getAttribute('generation-id') - new Vue({ - render: (h) => - h(GenerationUsers, { - props: { - generationID: generationID - } - }) - }).$mount(selector) - } -}) diff --git a/app/javascript/generation-users.vue b/app/javascript/generation-users.vue deleted file mode 100644 index 5c5b4130fa9..00000000000 --- a/app/javascript/generation-users.vue +++ /dev/null @@ -1,146 +0,0 @@ - - From abadef43ee54107f1b3ebecb66c7dcffd0d9daa1 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 9 Mar 2024 15:01:20 +0900 Subject: [PATCH 22/27] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC/?= =?UTF-8?q?=E3=82=A2=E3=83=B3=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Following.jsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/javascript/components/Following.jsx b/app/javascript/components/Following.jsx index 75af76323a2..b5f65acb891 100644 --- a/app/javascript/components/Following.jsx +++ b/app/javascript/components/Following.jsx @@ -6,12 +6,12 @@ export default function Following({ isFollowing, userId, isWatching }) { const [watching, setWatching] = useState(isWatching) const followingDetailsRef = useRef(null) - const url = () => `/api/users/${userId}/followings` - const followOrChangeFollow = (watch) => { - const params = { watch: watch } - fetch(url(), { - method: following ? 'PATCH' : 'POST', + const params = { id: userId, watch: watch } + const method = following ? 'PATCH' : 'POST' + const url = following ? `/api/followings/${userId}` : `/api/followings` + fetch(url, { + method: method, headers: { 'Content-Type': 'application/json; charset=utf-8', 'X-Requested-With': 'XMLHttpRequest', @@ -26,7 +26,7 @@ export default function Following({ isFollowing, userId, isWatching }) { setFollowing(true) setWatching(watch) } else { - alert('エラーが発生しました。') + alert('フォロー処理に失敗しました') } }) .catch((error) => { @@ -38,8 +38,8 @@ export default function Following({ isFollowing, userId, isWatching }) { } const unfollow = () => { - const params = { watch: watching } - fetch(url(), { + const params = { id: userId } + fetch(`/api/followings/${userId}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json; charset=utf-8', @@ -55,7 +55,7 @@ export default function Following({ isFollowing, userId, isWatching }) { setFollowing(false) setWatching(false) } else { - alert('エラーが発生しました。') + alert('フォロー処理に失敗しました') } }) .catch((error) => { From a7aa0509fca304dcae71da28b7b38b13feed3476 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 10 Mar 2024 20:02:39 +0900 Subject: [PATCH 23/27] =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8=E3=83=8D?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AEURL=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/GenerationUsers.jsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/javascript/components/GenerationUsers.jsx b/app/javascript/components/GenerationUsers.jsx index fd9018a301c..26691c698b0 100644 --- a/app/javascript/components/GenerationUsers.jsx +++ b/app/javascript/components/GenerationUsers.jsx @@ -86,12 +86,16 @@ export default function GenerationUsers({ generationID }) { } const newUrl = (pageNumber) => { - let url = location.pathname - url += params.target ? `?target=${params.target}` : '' - url += pageNumber === 1 ? '' : `&page=${pageNumber}` - return url + const url = new URL(location) + url.searchParams.set('page', pageNumber) + return url.toString() } + useEffect(() => { + const page = new URLSearchParams(location.search).get('page') + if (page) setCurrentPage(Number(page)) + }, []) + const pagerProps = { initialPageNumber: currentPage, pageCount: totalPages, From b1c632b52c019a5d686b30d95d4b1cd4cbb54c94 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:53:38 +0900 Subject: [PATCH 24/27] =?UTF-8?q?react-paginate=E3=81=AE=E3=82=A2=E3=83=B3?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - yarn.lock | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/package.json b/package.json index d99356898e6..333c8a16cc8 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "query-string": "^7.1.1", "react": "^17.0.0", "react-dom": "^17.0.0", - "react-paginate": "^8.2.0", "react-router-dom": "^6.4.1", "react_ujs": "^2.6.2", "select2": "^4.0.7-rc.0", diff --git a/yarn.lock b/yarn.lock index 09526265bb0..fe5b37d562c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7486,7 +7486,7 @@ promise@^7.0.1: dependencies: asap "~2.0.3" -prop-types@^15, prop-types@^15.8.1: +prop-types@^15.8.1: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== @@ -7766,13 +7766,6 @@ react-is@^16.13.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== -react-paginate@^8.2.0: - version "8.2.0" - resolved "https://registry.yarnpkg.com/react-paginate/-/react-paginate-8.2.0.tgz#947c3dcb444a6c16c1bcf8361871aa135baa3dcd" - integrity sha512-sJCz1PW+9PNIjUSn919nlcRVuleN2YPoFBOvL+6TPgrH/3lwphqiSOgdrLafLdyLDxsgK+oSgviqacF4hxsDIw== - dependencies: - prop-types "^15" - react-router-dom@^6.4.1: version "6.18.0" resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.18.0.tgz#0a50c167209d6e7bd2ed9de200a6579ea4fb1dca" From 9151a9acee6016677b0d4b23b9cb9735934b63fb Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 29 Mar 2024 00:09:00 +0900 Subject: [PATCH 25/27] =?UTF-8?q?Pager.jsx=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/Pager.jsx | 44 ----------------------------- 1 file changed, 44 deletions(-) delete mode 100644 app/javascript/components/Pager.jsx diff --git a/app/javascript/components/Pager.jsx b/app/javascript/components/Pager.jsx deleted file mode 100644 index ecef93f1ed7..00000000000 --- a/app/javascript/components/Pager.jsx +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react' -import ReactPaginate from 'react-paginate' - -export default function Pager({ - initialPageNumber, - pageCount, - pageRange, - clickHandle -}) { - const makeITag = (iconName) => - - return ( -
    - - - clickHandle(e.selected + 1)} - containerClassName="pagination__items" - pageClassName="pagination__item" - pageLinkClassName="pagination__item-link" - previousClassName="pagination__item is-prev" - previousLinkClassName="pagination__item-link is-prev" - nextClassName="pagination__item is-next" - nextLinkClassName="pagination__item-link is-next" - activeClassName="is-active" - disabledClassName="is-disabled" - /> - - -
    - ) -} From 6edb9c8790a22c63740303021c01d6b0c1797a0f Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 30 Mar 2024 10:37:30 +0900 Subject: [PATCH 26/27] =?UTF-8?q?useState=E3=81=A8useEffect=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=9F=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E3=81=8B=E3=82=89useSWR=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E7=A7=BB=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/GenerationUsers.jsx | 147 ++++-------------- 1 file changed, 31 insertions(+), 116 deletions(-) diff --git a/app/javascript/components/GenerationUsers.jsx b/app/javascript/components/GenerationUsers.jsx index 26691c698b0..8e6eda48d4c 100644 --- a/app/javascript/components/GenerationUsers.jsx +++ b/app/javascript/components/GenerationUsers.jsx @@ -1,127 +1,41 @@ -import React, { useState, useEffect } from 'react' +import React from 'react' +import useSWR from 'swr' import User from './User.jsx' -import Pager from './Pager.jsx' -import CSRF from 'csrf' - -const getParams = () => { - const params = new URLSearchParams(location.search) - const result = {} - for (const [key, value] of params) { - result[key] = value - } - if (location.pathname.match(/tags/)) { - const tag = location.pathname.split('/').pop() - result.tag = tag - } - return result -} +import Pagination from './Pagination' +import usePage from './hooks/usePage' +import fetcher from '../fetcher' export default function GenerationUsers({ generationID }) { - const [users, setUsers] = useState(null) - const [currentUser, setCurrentUser] = useState(null) - const [currentPage, setCurrentPage] = useState(Number(getParams().page) || 1) - const [totalPages, setTotalPages] = useState(0) - const [params] = useState(getParams()) - - useEffect(() => { - window.onpopstate = () => { - location.replace(location.href) - } - getUsers() - getCurrentUser() - }, []) - - useEffect(() => { - getUsers() - }, [currentPage, params]) - - const getUsers = () => { - const url = - `/api/generations/${generationID}.json` + - (params.tag ? `tags/${params.tag}` : '') + - `?page=${currentPage}` + - (params.target ? `&target=${params.target}` : '') + - (params.watch ? `&watch=${params.watch}` : '') - fetch(url, { - method: 'GET', - headers: { - 'Content-Type': 'application/json; charset=utf-8', - 'X-Requested-With': 'XMLHttpRequest', - 'X-CSRF-Token': CSRF.getToken() - }, - credentials: 'same-origin', - redirect: 'manual' - }) - .then((response) => response.json()) - .then((json) => { - setUsers(json.users) - setCurrentUser(json.currentUser) - setTotalPages(json.totalPages) - }) - .catch((error) => { - console.warn(error) - }) - } - - const getCurrentUser = () => { - fetch('/api/generations/&{generationID}', { - method: 'GET', - headers: { - 'Content-Type': 'application/json; charset=utf-8', - 'X-Requested-With': 'XMLHttpRequest', - 'X-CSRF-Token': CSRF.getToken() - }, - credentials: 'same-origin', - redirect: 'manual' - }) - .then((response) => response.json()) - .then((data) => setCurrentUser(data)) - .catch((error) => console.error('Error fetching current user:', error)) - } - - const paginateClickCallback = (pageNumber) => { - setCurrentPage(pageNumber) - history.pushState(null, null, newUrl(pageNumber)) - window.scrollTo(0, 0) - } - - const newUrl = (pageNumber) => { - const url = new URL(location) - url.searchParams.set('page', pageNumber) - return url.toString() - } - - useEffect(() => { - const page = new URLSearchParams(location.search).get('page') - if (page) setCurrentPage(Number(page)) - }, []) + const itemsPerPage = 24 + const { page, setPage } = usePage() + const { data, error } = useSWR( + `/api/generations/${generationID}.json?page=${page}&per=${itemsPerPage}`, + fetcher + ) - const pagerProps = { - initialPageNumber: currentPage, - pageCount: totalPages, - pageRange: 5, - clickHandle: paginateClickCallback - } + if (error) return <>An error has occurred. + if (!data) return <>Loading... return (
    - {totalPages > 1 && ( - + {data.totalPages > 1 && ( + )}
    - {users === null ? ( + {data.users === null ? (
    ロード中
    - ) : users.length !== 0 ? ( - users.map((user) => ( - + ) : data.users.length !== 0 ? ( + data.users.map((user) => ( + )) ) : (
    @@ -137,12 +51,13 @@ export default function GenerationUsers({ generationID }) { )}
    - {totalPages > 1 && ( - + {data.totalPages > 1 && ( + )}
    ) From bf53c765afeea6373ff6f7b87fb55d02e3682f5b Mon Sep 17 00:00:00 2001 From: machida Date: Wed, 10 Apr 2024 22:41:51 +0900 Subject: [PATCH 27/27] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E9=81=B8=E6=8A=9E=E3=81=8C=E4=B8=8B=E3=81=AE=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE=E3=82=AB=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=81=AB=E3=81=8B=E3=81=B6=E3=81=A3=E3=81=A6=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=86=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/components/User.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/components/User.jsx b/app/javascript/components/User.jsx index d3f7e427af8..58b755c93a5 100644 --- a/app/javascript/components/User.jsx +++ b/app/javascript/components/User.jsx @@ -126,7 +126,7 @@ export default function User({ user, currentUser }) {

    -