diff --git a/src/controls/RecipientSelect/index.tsx b/src/controls/RecipientSelect/index.tsx index 39a3f265..4130aa70 100644 --- a/src/controls/RecipientSelect/index.tsx +++ b/src/controls/RecipientSelect/index.tsx @@ -1,10 +1,9 @@ -import React from 'react'; -import { Select, Tag, Spin, Tooltip, Menu, RefSelectProps } from 'antd'; +import { Menu, RefSelectProps, Select, Spin, Tag, Tooltip } from 'antd'; +import cn from 'classnames'; import { autobind } from 'core-decorators'; -import { observable, makeObservable, action } from 'mobx'; +import { action, makeObservable, observable } from 'mobx'; import { observer } from 'mobx-react'; -import { PureComponent } from 'react'; -import cn from 'classnames'; +import React, { PureComponent } from 'react'; import contacts from '../../stores/Contacts'; import domain from '../../stores/Domain'; import { IRecipient } from '../../stores/Mailbox'; diff --git a/src/pages/ComposePage/components/MailComposeMeta.tsx b/src/pages/ComposePage/components/MailComposeMeta.tsx index b1096e7c..770debed 100644 --- a/src/pages/ComposePage/components/MailComposeMeta.tsx +++ b/src/pages/ComposePage/components/MailComposeMeta.tsx @@ -1,6 +1,7 @@ import { Input, Select } from 'antd'; import { observer } from 'mobx-react'; import { PureComponent } from 'react'; +import { getNameOfJSDocTypedef } from 'typescript'; import { RecipientsSelect } from '../../../controls/RecipientSelect'; import domain from '../../../stores/Domain'; import mailbox from '../../../stores/Mailbox'; @@ -8,10 +9,46 @@ import { shrinkAddress } from '../../../utils/shrinkAddress'; @observer export class MailComposeMeta extends PureComponent { + state = { + loaded: false, + }; + componentDidMount(): void { if (!mailbox.from && domain.accounts.activeAccounts.length) { mailbox.from = domain.accounts.activeAccounts[0]; } + + const queryParams = () => { + const result: Record = {}; + new URLSearchParams(window.location.search).forEach((value, key) => { + result[key] = value; + }); + return result; + }; + + const searchParams = queryParams(); + + const input = searchParams.input; + const type = searchParams.type as 'address' | 'contact' | 'ns' | 'invalid'; + const address = searchParams.address; + const subject = searchParams.subject; + + if ((type === 'address' && address !== undefined) || (type === 'ns' && address !== undefined)) { + mailbox.to = [ + { + loading: true, + input: input || '', + type: type, + address: address || '', + isAchievable: null, + comment: '', + }, + ]; + } + + mailbox.subject = subject || ''; + + this.setState(state => ({ loaded: true })); } render() { @@ -40,7 +77,7 @@ export class MailComposeMeta extends PureComponent {
- + {this.state.loaded && }
diff --git a/src/pages/ContactsPage/ContactsPage.tsx b/src/pages/ContactsPage/ContactsPage.tsx index 65462b00..8155da69 100644 --- a/src/pages/ContactsPage/ContactsPage.tsx +++ b/src/pages/ContactsPage/ContactsPage.tsx @@ -1,9 +1,9 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import GenericLayout from '../../layouts/GenericLayout'; import contacts from '../../stores/Contacts'; import tags from '../../stores/Tags'; import { observer } from 'mobx-react'; -import { Outlet, useLocation } from 'react-router-dom'; +import { Outlet, useLocation, useSearchParams } from 'react-router-dom'; import ContactsSearcher from './components/ContactsSearcher'; import { useNav } from '../../utils/navigate'; import { Button, Tabs } from 'antd'; @@ -16,6 +16,16 @@ const ContactsPage = observer(() => { const nav = useNav(); const { windowWidth } = useWindowSize(); + const [searchParams] = useSearchParams(); + + useEffect(() => { + const name = searchParams.get('name'); + const address = searchParams.get('address'); + if (address) { + contacts.generateNewContactFromParams(name || '', address); + } + }, []); + const addHandler = () => { if (location.pathname === '/contacts') { contacts.generateNewContact(); diff --git a/src/stores/Contacts.ts b/src/stores/Contacts.ts index 5789e74e..789a893e 100644 --- a/src/stores/Contacts.ts +++ b/src/stores/Contacts.ts @@ -84,6 +84,15 @@ class Contacts { }; } + generateNewContactFromParams(name: IContact['name'], address: IContact['address']) { + this.newContact = { + name, + address, + description: '', + tags: [], + }; + } + resetNewContact() { this.newContact = null; }