From 0f07c2d337f869b70c30796d4e70ee7481635947 Mon Sep 17 00:00:00 2001 From: useruseruse Date: Wed, 18 Sep 2024 14:24:01 -0400 Subject: [PATCH 1/2] fix: change base to latest origin migration --- src/pages/MainPage.jsx | 303 ----------------------------------------- src/pages/MainPage.tsx | 167 +++++++++++++++++++++++ src/queries/main.ts | 55 ++++++++ 3 files changed, 222 insertions(+), 303 deletions(-) delete mode 100644 src/pages/MainPage.jsx create mode 100644 src/pages/MainPage.tsx create mode 100644 src/queries/main.ts diff --git a/src/pages/MainPage.jsx b/src/pages/MainPage.jsx deleted file mode 100644 index ee087d7..0000000 --- a/src/pages/MainPage.jsx +++ /dev/null @@ -1,303 +0,0 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; -import { withTranslation } from 'react-i18next'; -import PropTypes, { bool } from 'prop-types'; -import axios from 'axios'; -import { range } from 'lodash'; - -import { ZaboEmbed } from 'zabo-embed'; - -import { appBoundClassNames as classNames } from '../common/boundClassNames'; - -import Footer from '../common/guideline/components/Footer'; -import TodaysTimetableSection from '../components/sections/main/TodaysTimetableSection'; -import AcademicScheduleSection from '../components/sections/main/AcademicScheduleSection'; -import RelatedCourseFeedSection from '../components/sections/main/RelatedCourseFeedSection'; -import LatestReviewSection from '../components/sections/main/LatestReviewSection'; -import FamousMajorReviewFeedSection from '../components/sections/main/FamousMajorReviewFeedSection'; -import FamousHumanityReviewFeedSection from '../components/sections/main/FamousHumanityReviewFeedSection'; -import RankedReviewFeedSection from '../components/sections/main/RankedReviewFeedSection'; -import ReviewWriteFeedSection from '../components/sections/main/ReviewWriteFeedSection'; -import MainSearchSection from '../components/sections/main/MainSearchSection'; -import userShape from '../shapes/model/session/UserShape'; -import NoticeSection from '../components/sections/main/NoticeSection'; -import RateFeedSection from '../components/sections/main/RateFeedSection'; - -class MainPage extends Component { - constructor(props) { - super(props); - - this.state = { - feedDays: [], - notices: null, - isLoading: false, - }; - - this.contentRef = React.createRef(); - } - - componentDidMount() { - const { user } = this.props; - - window.addEventListener('scroll', this.handleScroll); - - const today = new Date(); - if (user) { - this._fetchFeeds(today); - } - this._fetchNotices(); - } - - componentDidUpdate(prevProps, prevState, snapshot) { - const { user } = this.props; - - const today = new Date(); - if (user && !prevProps.user) { - this._fetchFeeds(today); - } - } - - componentWillUnmount() { - window.removeEventListener('scroll', this.handleScroll); - } - - handleScroll = (e) => { - this._checkAndLoadFeeds(); - }; - - _checkAndLoadFeeds = () => { - const { isLoading } = this.state; - const { user } = this.props; - const SCROLL_BOTTOM_PADDING = 100; - - if (isLoading) { - return; - } - if (!user) { - return; - } - - const columns = Array.from( - this.contentRef.current.querySelectorAll(`.${classNames('page-grid--main')} > div`), - ); - - const isBottomReached = columns.some( - (cl) => cl.lastChild.getBoundingClientRect().top < window.innerHeight + SCROLL_BOTTOM_PADDING, - ); - if (isBottomReached) { - this._fetchFeeds(this._getPrevDate()); - } - }; - - _getPrevDate = () => { - const { feedDays } = this.state; - const targetDate = new Date(feedDays[feedDays.length - 1].date); - targetDate.setDate(targetDate.getDate() - 1); - return targetDate; - }; - - _fetchFeeds = (date) => { - const { feedDays, isLoading } = this.state; - const { user } = this.props; - - if (isLoading) { - return; - } - if (!user) { - return; - } - if (this._getDateDifference(date) >= 14) { - return; - } - - this.setState({ - isLoading: true, - }); - - const dateString = date.toJSON().slice(0, 10); - - axios - .get(`/api/users/${user.id}/feeds`, { - params: { - date: dateString, - }, - metadata: { - gaCategory: 'Feed', - gaVariable: 'GET / List', - }, - }) - .then((response) => { - this.setState({ - isLoading: false, - feedDays: [ - ...feedDays, - { - date: dateString, - feeds: response.data, - }, - ], - }); - this._checkAndLoadFeeds(); - }) - .catch((error) => {}); - }; - - _fetchNotices = () => { - const now = new Date(); - axios - .get('/api/notices', { - params: { - time: now.toJSON(), - order: ['start_time', 'id'], - }, - metadata: { - gaCategory: 'Notice', - gaVariable: 'GET / List', - }, - }) - .then((response) => { - this.setState({ - notices: response.data, - }); - }) - .catch((error) => {}); - }; - - _getDateDifference = (date) => { - const copiedDate = new Date(date); - const todayDate = new Date(); - copiedDate.setHours(0, 0, 0, 0); - todayDate.setHours(0, 0, 0, 0); - const timeDiff = todayDate - copiedDate; - return timeDiff / (24 * 60 * 60 * 1000); - }; - - render() { - const { t } = this.props; - const { feedDays, notices } = this.state; - const { user, isPortrait } = this.props; - - const mapFeedToSection = (feed, date) => { - if (feed.type === 'REVIEW_WRITE') { - return ( - r.lecture.id === feed.lecture.id)} - key={`${date.date}-${feed.type}-${feed.lecture.id}`} - /> - ); - } - if (feed.type === 'RELATED_COURSE') { - return ( - - ); - } - if (feed.type === 'FAMOUS_MAJOR_REVIEW') { - return ( - - ); - } - if (feed.type === 'FAMOUS_HUMANITY_REVIEW') { - return ( - - ); - } - if (feed.type === 'RANKED_REVIEW') { - return ( - - ); - } - if (feed.type === 'RATE') { - return ; - } - return null; - }; - - const columnNum = isPortrait ? 1 : 3; - - const feeds = [ - , - , - , - notices - ? notices.map((n) => ( - - )) - : [], - , - !user ? [] : feedDays.map((d) => d.feeds.map((f) => mapFeedToSection(f, d))), - ].flat(3); - - return ( - <> -
- -
-
-
- {range(columnNum).map((i) => ( -
- {feeds.filter((v, i2) => i2 % columnNum === i)} -
- {range(10).map((j) => ( -
- ))} -
-
- ))} -
- {user ? ( - this._fetchFeeds(this._getPrevDate())}> - {t('ui.button.loadMore')} - - ) : ( - <> - - {t('ui.button.signInWithSso')} - -
{t('ui.message.signInForMore')}
- - )} -
-
-
-