Use wikitree-js library for WikiTree API

This commit is contained in:
Przemek Więch
2022-08-17 11:18:17 +02:00
parent 7c6b1dd390
commit a92f06e43d
4 changed files with 1033 additions and 473 deletions

View File

@@ -3,10 +3,13 @@ import wikitreeLogo from './wikitree.png';
import {analyticsEvent} from '../util/analytics';
import {Button, Form, Header, Input, Modal} from 'semantic-ui-react';
import {FormattedMessage, useIntl} from 'react-intl';
import {getLoggedInUserName} from '../datasource/wikitree';
import {MenuItem, MenuType} from './menu_item';
import {useEffect, useRef, useState} from 'react';
import {useHistory, useLocation} from 'react-router';
import {
getLoggedInUserName,
navigateToLoginPage,
} from 'wikitree-js';
interface Props {
menuType: MenuType;
@@ -150,8 +153,6 @@ export function WikiTreeMenu(props: Props) {
/** Displays and handles the "Log in to WikiTree" menu. */
export function WikiTreeLoginMenu(props: Props) {
const formRef = useRef<HTMLFormElement>(null);
const returnUrlRef = useRef<HTMLInputElement>(null);
const intl = useIntl();
/**
@@ -163,8 +164,7 @@ export function WikiTreeLoginMenu(props: Props) {
'https://apps.wikitree.com/apps/wiech13/topola-viewer';
// TODO: remove authcode if it is in the current URL.
const returnUrl = `${wikiTreeTopolaUrl}${window.location.hash}`;
returnUrlRef.current!.value = returnUrl;
formRef.current!.submit();
navigateToLoginPage(returnUrl);
}
const username = getLoggedInUserName();
@@ -178,15 +178,6 @@ export function WikiTreeLoginMenu(props: Props) {
defaultMessage="Log in to WikiTree"
/>
</MenuItem>
<form
action="https://api.wikitree.com/api.php"
method="POST"
style={{display: 'hidden'}}
ref={formRef}
>
<input type="hidden" name="action" value="clientLogin" />
<input type="hidden" name="returnURL" ref={returnUrlRef} />
</form>
</>
);
}