diff --git a/src/ui/root/DeputyContributionSurveyRevision.tsx b/src/ui/root/DeputyContributionSurveyRevision.tsx index da8d43bf..8588c189 100644 --- a/src/ui/root/DeputyContributionSurveyRevision.tsx +++ b/src/ui/root/DeputyContributionSurveyRevision.tsx @@ -5,14 +5,8 @@ import unwrapWidget from '../../util/unwrapWidget'; import { DeputyMessageEvent, DeputyRevisionStatusUpdateMessage } from '../../DeputyCommunications'; import type DeputyContributionSurveyRow from './DeputyContributionSurveyRow'; import { - ChangesListBytes, ChangesListDate, - ChangesListDiff, - ChangesListLinks, - ChangesListTags, ChangesListTime, - ChangesListUser, - NewPageIndicator + ChangesListLinks, ChangesListMissingRow, ChangesListRow } from '../shared/ChangesList'; -import unwrapElement from '../../util/unwrapElement'; import DeputyLoadingDots from './DeputyLoadingDots'; import MwApi from '../../MwApi'; import classMix from '../../util/classMix'; @@ -327,64 +321,6 @@ export default class DeputyContributionSurveyRevision } } - /** - * Renders revision info. This is only called if the revision exists. - */ - renderRevisionInfo(): HTMLElement { - const commentElement = ; - const tagMessages = ( this.revision.tags ?? [] ).map( - // eslint-disable-next-line mediawiki/msg-doc - ( v ) => [ v, mw.message( `tag-${ v }` ).parse() ] as [string, string] - ).filter( v => v[ 1 ] !== '-' ); - - return - { - !this.revision.parentid && - } { - window.deputy.config.cci.showUsername.get() && - } { - ( this.revision.parsedcomment || - tagMessages.length > 0 ) && - - } { - this.revision.parsedcomment && - commentElement - } { - tagMessages.length > 0 && - - } - as HTMLElement; - } - - /** - * Renders a placeholder for missing revisions. - */ - renderMissingRevisionInfo(): HTMLElement { - return - {' '} - as HTMLElement; - } - /** * @inheritDoc */ @@ -404,15 +340,11 @@ export default class DeputyContributionSurveyRevision > {unwrapWidget( this.completedCheckbox )} {unwrapWidget( this.diffToggle )} - {unwrapElement( + { ( this.revision as any ).missing ? - this.renderMissingRevisionInfo() : - this.renderRevisionInfo() - )}{this.diff} + : + + }{this.diff} as HTMLElement; } diff --git a/src/ui/shared/ChangesList.tsx b/src/ui/shared/ChangesList.tsx index 75d5a7d2..15594595 100644 --- a/src/ui/shared/ChangesList.tsx +++ b/src/ui/shared/ChangesList.tsx @@ -3,8 +3,10 @@ import getRevisionURL from '../../wiki/util/getRevisionURL'; import getRevisionDiffURL from '../../wiki/util/getRevisionDiffURL'; import nsId from '../../wiki/util/nsId'; import type { ExpandedRevisionData } from '../../api/ExpandedRevisionData'; -import { h } from 'tsx-dom'; +import { ComponentChild, h } from 'tsx-dom'; import unwrapJQ from '../../util/unwrapJQ'; +import msgEval from '../../wiki/util/msgEval'; +import classMix from '../../util/classMix'; import { USER_LOCALE } from '../../wiki/Locale'; /** @@ -111,12 +113,18 @@ export function ChangesListTime( */ export function ChangesListDate( { revision, link }: { revision: ExpandedRevisionData, link?: boolean } | - { revision: { timestamp: string }, link: false } + { revision: { timestamp: string, texthidden?: true }, link: false } ): JSX.Element { + // `texthidden` would be indeterminate if the `{timestamp}` type was used + if ( revision.texthidden ) { + // Don't give out a link if the revision was deleted + link = false; + } + const time = new Date( revision.timestamp ); let now = window.moment( time ); - if ( window.deputy.config.cci.forceUtc.get() ) { + if ( window.deputy && window.deputy.config.cci.forceUtc.get() ) { now = now.utc(); } const formattedTime = time.toLocaleTimeString( USER_LOCALE, { @@ -137,15 +145,30 @@ export function ChangesListDate( { formattedTime }{ comma }{ formattedDate } : - { formattedTime }{ comma }{ formattedDate }; + { formattedTime }{ comma }{ formattedDate }; } /** * @param root0 - * @param root0.user + * @param root0.revision * @return HTML element */ -export function ChangesListUser( { user }: { user: string } ) { +export function ChangesListUser( { revision }: { revision: ExpandedRevisionData } ) { + const { user, userhidden } = revision; + + if ( userhidden ) { + return + { + mw.msg( 'deputy.revision.removed.user' ) + } + ; + } + const userPage = new mw.Title( user, nsId( 'user' ) ); const userTalkPage = new mw.Title( user, nsId( 'user_talk' ) ); const userContribsPage = new mw.Title( 'Special:Contributions/' + user ); @@ -244,12 +267,32 @@ export function ChangesListDiff( ; } +/** + * @param root0 + * @param root0.page + * @param root0.page.title + * @param root0.page.ns + * @return HTML element + */ +export function ChangesListPage( + { page }: { page: { title: string, ns: number } } +): JSX.Element { + const pageTitle = + new mw.Title( page.title, page.ns ).getPrefixedText(); + + return {pageTitle}; +} + /** * @param root0 * @param root0.tags * @return HTML element */ -export function ChangesListTags( { tags }: { tags: [string, string][] } ): JSX.Element { +export function ChangesListTags( { tags }: { tags: string[] } ): JSX.Element { return ; } + +/** + * + * @param root0 + * @param root0.revision + */ +export function ChangesListMissingRow( + { revision }: { + revision: ExpandedRevisionData + } +): JSX.Element { + return + {' '} + ; +} + +/** + * @param root0 + * @param root0.revision + * @param root0.format + * @return A changes list row. + */ +export function ChangesListRow( + { revision, format }: { + revision: ExpandedRevisionData, + format?: 'history' | 'contribs' + } +): JSX.Element { + if ( !format ) { + format = 'history'; + } + + let commentElement: ComponentChild = ''; + if ( revision.commenthidden ) { + commentElement = { + mw.msg( 'deputy.revision.removed.comment' ) + }; + } else if ( revision.parsedcomment ) { + commentElement = ; + } else if ( revision.comment ) { + const comment = revision.comment + // Insert Word-Joiner to avoid parsing "templates". + .replace( /{/g, '{\u2060' ) + .replace( /}/g, '\u2060}' ); + + commentElement = unwrapJQ( , msgEval( comment ).parseDom() ); + } + + return + { + !revision.parentid && + } { format === 'history' && } { format === 'history' && } { format === 'contribs' && } { commentElement } { + ( revision.tags?.length ?? -1 ) > 0 && + + } + ; +}