Skip to content

Commit d602520

Browse files
authored
fix(EasyArchive, PagePatroller): children node missing (qiuwenbaike#1709)
* fix(EasyArchive, PagePatroller): children node missing
1 parent 7b3cb2b commit d602520

File tree

10 files changed

+261
-240
lines changed

10 files changed

+261
-240
lines changed

dist/EasyArchive/EasyArchive.js

Lines changed: 53 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/PagePatroller/PagePatroller.js

Lines changed: 35 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EasyArchive/modules/addLinks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {ArchiveAndDeleteSectionLink} from './components/sectionLink';
2-
import {EditConflictNotice} from './components/react';
2+
import {EditConflictNotice} from './components/editConflictNotice';
33
import React from 'ext.gadget.JSX';
44
import {getSections} from './util/getSection';
55
import {refresh} from './util/refreshPage';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'ext.gadget.JSX';
2+
import {getMessage} from '../i18n';
3+
4+
interface EditConflictNoticeProps {
5+
onClick: () => void;
6+
}
7+
8+
const EditConflictNotice = ({onClick}: EditConflictNoticeProps) => (
9+
<span>
10+
{getMessage('Edit Confilict Notice')}
11+
<a onClick={onClick}>{getMessage('Refresh')}</a>
12+
</span>
13+
);
14+
15+
export {EditConflictNotice};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as OPTIONS from '../../options.json';
2+
import React, {ReactElement} from 'ext.gadget.JSX';
3+
import {footerNotice} from './EasyArchive.module.less';
4+
import {getMessage} from '../i18n';
5+
import {sanitize} from '../util/sanitize';
6+
7+
interface FooterNoticeProps {
8+
children: ReactElement;
9+
}
10+
11+
interface ArcLocProps {
12+
arcLoc: string;
13+
}
14+
15+
const FooterNotice = ({children = <></>}: FooterNoticeProps) => {
16+
const {skin} = mw.config.get();
17+
18+
return (
19+
<>
20+
{skin === 'citizen' ? (
21+
<section
22+
id={OPTIONS.elementId}
23+
className={[footerNotice, 'page-info__item', 'citizen-footer__pageinfo-item', 'noprint']}
24+
>
25+
{children}
26+
</section>
27+
) : ['vector', 'vector-2022', 'gongbi'].includes(skin) || document.querySelector('ul#footer-info') ? (
28+
<li id={OPTIONS.elementId} className={[footerNotice, 'noprint']}>
29+
{children}
30+
</li>
31+
) : (
32+
<div id={OPTIONS.elementId} className={[footerNotice, 'noprint']}>
33+
{children}
34+
</div>
35+
)}
36+
</>
37+
);
38+
};
39+
40+
const InBlackList = () => (
41+
<FooterNotice>
42+
<>
43+
{getMessage('Easy Archive not supported')}
44+
<br />
45+
{getMessage('Easy Archive not supported details')}
46+
</>
47+
</FooterNotice>
48+
);
49+
50+
const NotAllowed = () => (
51+
<FooterNotice>
52+
<>{getMessage('Easy Archive not allowed')}</>
53+
</FooterNotice>
54+
);
55+
56+
const ArcLocNotAllowed = ({arcLoc}: ArcLocProps) => (
57+
<FooterNotice>
58+
<>
59+
{getMessage('Archive Location not allowed').replace('$1', sanitize(arcLoc))}
60+
<br />
61+
{getMessage('Archive Location not allowed details')}
62+
</>
63+
</FooterNotice>
64+
);
65+
66+
const NoArcLoc = () => (
67+
<FooterNotice>
68+
<>{getMessage('No Archive Location')}</>
69+
</FooterNotice>
70+
);
71+
72+
const Enabled = ({arcLoc}: ArcLocProps) => (
73+
<FooterNotice>
74+
<>
75+
{getMessage('Easy Archive enabled')}
76+
{getMessage('(')}
77+
{getMessage('Archive location')}
78+
<a title={sanitize(arcLoc)} href={`/wiki/${sanitize(arcLoc)}`}>
79+
{arcLoc}
80+
</a>
81+
{getMessage(')')}
82+
{getMessage('.')}
83+
</>
84+
</FooterNotice>
85+
);
86+
87+
export {FooterNotice, Enabled, InBlackList, NotAllowed, ArcLocNotAllowed, NoArcLoc};

src/EasyArchive/modules/components/react.tsx

Lines changed: 0 additions & 122 deletions
This file was deleted.

src/EasyArchive/modules/components/sectionLink.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1-
import {OnClick, Pipe, SectionID} from './react';
1+
import React, {ReactElement} from 'ext.gadget.JSX';
22
import {archiveOnClick, removeOnClick} from '../util/onClick';
3-
import React from 'ext.gadget.JSX';
43
import {getMessage} from '../i18n';
4+
import {sectionIdSpan} from './EasyArchive.module.less';
5+
6+
interface OnClickProps {
7+
textContent: string;
8+
className: string;
9+
onClick?: (event: Event) => void;
10+
}
11+
12+
interface SectionIDProps {
13+
children?: ReactElement;
14+
}
15+
16+
const OnClick = ({textContent, className, onClick}: OnClickProps) => (
17+
<a
18+
className={['gadget-easy_archive__link', `gadget-easy_archive__link-${className}`]}
19+
onClick={onClick || (() => {})}
20+
textContent={textContent}
21+
/>
22+
);
23+
24+
const SectionID = ({children = <></>}: SectionIDProps) => <span className={sectionIdSpan}>{children}</span>;
25+
26+
const Pipe = () => <span className="mw-editsection-divider" textContent={'|'} />;
527

628
interface ArchiveSectionLinkProps {
729
sectionIdSpans: Element[];

src/EasyArchive/modules/loadEasyArcive.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as OPTIONS from '../options.json';
2-
import {ArcLocNotAllowed, Enabled, FooterNotice, InBlackList, NoArcLoc, NotAllowed} from './components/react';
2+
import {ArcLocNotAllowed, Enabled, InBlackList, NoArcLoc, NotAllowed} from './components/footerNotices';
33
import {getSettings, ifArcLocNotAllowed, isInBlacklist, isNotAllowed, isNotSupported} from './util/getSettings';
44
import React from 'ext.gadget.JSX';
55
import {addLinks} from './addLinks';
@@ -15,40 +15,37 @@ const loadEasyArcive = () => {
1515
return;
1616
}
1717

18-
const footerElement = <FooterNotice />;
19-
mountPoint.prepend(footerElement);
20-
2118
const inBlacklist = isInBlacklist();
2219
if (inBlacklist) {
23-
footerElement.append(<InBlackList />);
20+
mountPoint.prepend(<InBlackList />);
2421
return;
2522
}
2623

2724
const notAllowed = isNotAllowed();
2825
if (notAllowed) {
29-
footerElement.append(<NotAllowed />);
26+
mountPoint.prepend(<NotAllowed />);
3027
return;
3128
}
3229

3330
const settings = getSettings();
3431
if (!settings) {
35-
footerElement.append(<NoArcLoc />);
32+
mountPoint.prepend(<NoArcLoc />);
3633
return;
3734
}
3835

3936
const {arcLoc} = settings;
4037
if (!arcLoc) {
41-
footerElement.append(<NoArcLoc />);
38+
mountPoint.prepend(<NoArcLoc />);
4239
return;
4340
}
4441

4542
const arcLocNotAllowed = ifArcLocNotAllowed(arcLoc);
4643
if (arcLocNotAllowed) {
47-
footerElement.append(<ArcLocNotAllowed arcLoc={arcLoc} />);
44+
mountPoint.prepend(<ArcLocNotAllowed arcLoc={arcLoc} />);
4845
return;
4946
}
5047

51-
footerElement.append(<Enabled arcLoc={arcLoc} />);
48+
mountPoint.prepend(<Enabled arcLoc={arcLoc} />);
5249

5350
void addLinks(settings);
5451
};

src/PagePatroller/modules/components/react.tsx renamed to src/PagePatroller/modules/components/footerNotices.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,49 @@ const FooterNotice = ({id = OPTIONS.elementId, children = <></>}: FooterNoticePr
3030
};
3131

3232
const NotPatrolledYet = () => (
33-
<span id="page_patroller__not-patrolled" textContent={getMessage('This page has not been patrolled yet')} />
33+
<FooterNotice>
34+
<span id="page_patroller__not-patrolled" textContent={getMessage('This page has not been patrolled yet')} />
35+
</FooterNotice>
3436
);
3537

36-
const Loading = () => <span id="page_patroller__loading" textContent={getMessage('Loading...')} />;
38+
const Loading = () => (
39+
<FooterNotice>
40+
<span id="page_patroller__loading" textContent={getMessage('Loading...')} />
41+
</FooterNotice>
42+
);
3743

3844
interface PatrolledProps {
39-
timestamp?: string;
40-
user?: string;
45+
timestamp: string;
46+
user: string;
4147
}
4248

43-
const Patrolled = ({timestamp, user}: PatrolledProps) => (
44-
<>
45-
{timestamp && user ? (
46-
<span id="page_patroller__patrolled-by">
47-
{getMessage('This page was patrolled at by').replace('$1', timestamp)}
48-
<a href={mw.util.getUrl(`User:${user}`)}>{user}</a>
49-
{getMessage('period')}
50-
</span>
51-
) : (
49+
const Patrolled = ({timestamp, user}: PatrolledProps) => {
50+
if (timestamp && user) {
51+
return (
52+
<FooterNotice>
53+
<span id="page_patroller__patrolled-by">
54+
{getMessage('This page was patrolled at by').replace('$1', timestamp)}
55+
<a href={mw.util.getUrl(`User:${user}`)}>{user}</a>
56+
{getMessage('period')}
57+
</span>
58+
</FooterNotice>
59+
);
60+
}
61+
62+
return (
63+
<FooterNotice>
5264
<span
5365
id="page_patroller__patrolled"
5466
textContent={getMessage('This page has been patrolled, or has been marked as auto-patrolled')}
5567
/>
56-
)}
57-
</>
58-
);
68+
</FooterNotice>
69+
);
70+
};
5971

6072
const ErrorMessage = () => (
61-
<span id="page_patroller__error" textContent={getMessage('Error occurs when finding patroller')} />
73+
<FooterNotice>
74+
<span id="page_patroller__error" textContent={getMessage('Error occurs when finding patroller')} />
75+
</FooterNotice>
6276
);
6377

6478
export {FooterNotice, NotPatrolledYet, Loading, Patrolled, ErrorMessage};

0 commit comments

Comments
 (0)