diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index 0f1a7311..c3e3085e 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -1212,7 +1212,8 @@ ui: title: "History for" show_votes: "Show votes" n_or_a: N/A - title_for: "Timeline for" + title_for_question: "Timeline for" + title_for_answer: "Timeline for answers to {{ title }} by {{ author }}" title_for_tag: "Title for tag" datetime: Datetime type: Type diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts index 4d6de991..e5d711f5 100644 --- a/ui/src/common/interface.ts +++ b/ui/src/common/interface.ts @@ -406,6 +406,7 @@ export interface TimelineObject { question_id: string; answer_id: string; main_tag_slug_name?: string; + username?: string; } export interface TimelineRes { diff --git a/ui/src/components/DiffContent/index.tsx b/ui/src/components/DiffContent/index.tsx index 36f87de2..336f71a8 100644 --- a/ui/src/components/DiffContent/index.tsx +++ b/ui/src/components/DiffContent/index.tsx @@ -102,7 +102,7 @@ const Index: FC = ({ dangerouslySetInnerHTML={{ __html: diffText(newData.original_text, oldData?.original_text), }} - className="pre-line text-break font-monospace" + className="pre-line text-break font-monospace fs-14" /> ); diff --git a/ui/src/pages/Timeline/components/Item/index.tsx b/ui/src/pages/Timeline/components/Item/index.tsx index bdc637f3..657f4708 100644 --- a/ui/src/pages/Timeline/components/Item/index.tsx +++ b/ui/src/pages/Timeline/components/Item/index.tsx @@ -70,7 +70,8 @@ const Index: FC = ({ data, isAdmin, objectInfo, revisionList }) => { )} {data.activity_type === 'accept' && ( - + {t(data.activity_type)} )} diff --git a/ui/src/pages/Timeline/index.tsx b/ui/src/pages/Timeline/index.tsx index 8c592a56..933eebd2 100644 --- a/ui/src/pages/Timeline/index.tsx +++ b/ui/src/pages/Timeline/index.tsx @@ -1,11 +1,12 @@ -import { FC, useState } from 'react'; +import { FC, useState, useEffect } from 'react'; import { Container, Row, Col, Form, Table } from 'react-bootstrap'; import { Link, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { loggedUserInfoStore } from '@/stores'; -import { useTimelineData } from '@/services'; +import { getTimelineData } from '@/services'; import { PageTitle, Empty } from '@/components'; +import * as Type from '@/common/interface'; import HistoryItem from './components/Item'; @@ -14,23 +15,45 @@ const Index: FC = () => { const { qid = '', aid = '', tid = '' } = useParams(); const { is_admin } = loggedUserInfoStore((state) => state.user); const [showVotes, setShowVotes] = useState(false); + const [isLoading, setLoading] = useState(false); + const [timelineData, setTimelineData] = useState(); - const { data: timelineData, isLoading } = useTimelineData({ - object_id: tid || aid || qid, - show_vote: showVotes, - }); + const getPageData = () => { + setLoading(true); + getTimelineData({ + object_id: tid || aid || qid, + show_vote: showVotes, + }) + .then((res) => { + setTimelineData(res); + }) + .finally(() => { + setLoading(false); + }); + }; const handleSwitch = (bol: boolean) => { setShowVotes(bol); + getPageData(); }; + useEffect(() => { + getPageData(); + }, []); + let linkUrl = ''; + let pageTitle = ''; if (timelineData?.object_info.object_type === 'question') { linkUrl = `/questions/${timelineData?.object_info.question_id}`; + pageTitle = `${t('title_for_question')} ${timelineData?.object_info.title}`; } if (timelineData?.object_info.object_type === 'answer') { linkUrl = `/questions/${timelineData?.object_info.question_id}/${timelineData?.object_info.answer_id}`; + pageTitle = `${t('title_for_answer', { + title: timelineData?.object_info.title, + author: timelineData?.object_info.username, + })}`; } if (timelineData?.object_info.object_type === 'tag') { @@ -38,6 +61,7 @@ const Index: FC = () => { timelineData?.object_info.main_tag_slug_name || timelineData?.object_info.title }`; + pageTitle = `${t('title_for_tag')} ${timelineData?.object_info.title}`; } const revisionList = @@ -45,13 +69,7 @@ const Index: FC = () => { return ( - +
diff --git a/ui/src/services/client/timeline.ts b/ui/src/services/client/timeline.ts index 2c6efed7..d77b2548 100644 --- a/ui/src/services/client/timeline.ts +++ b/ui/src/services/client/timeline.ts @@ -1,21 +1,28 @@ -import useSWR from 'swr'; import qs from 'qs'; import request from '@/utils/request'; import type * as Type from '@/common/interface'; -export const useTimelineData = (params: Type.TimelineReq) => { - const apiUrl = '/answer/api/v1/activity/timeline'; - const { data, error, mutate } = useSWR( - `${apiUrl}?${qs.stringify(params, { skipNulls: true })}`, - request.instance.get, +// export const useTimelineData = (params: Type.TimelineReq) => { +// const apiUrl = '/answer/api/v1/activity/timeline'; +// const { data, error, mutate } = useSWR( +// `${apiUrl}?${qs.stringify(params, { skipNulls: true })}`, +// request.instance.get, +// ); +// return { +// data, +// isLoading: !data && !error, +// error, +// mutate, +// }; +// }; + +export const getTimelineData = (params: Type.TimelineReq) => { + return request.get( + `/answer/api/v1/activity/timeline?${qs.stringify(params, { + skipNulls: true, + })}`, ); - return { - data, - isLoading: !data && !error, - error, - mutate, - }; }; export const getTimelineDetail = (params: {