Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/controls/RecipientSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
39 changes: 38 additions & 1 deletion src/pages/ComposePage/components/MailComposeMeta.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
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';
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<string, string | undefined> = {};
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() {
Expand Down Expand Up @@ -40,7 +77,7 @@ export class MailComposeMeta extends PureComponent {
<div className="mmp-row">
<label className="mmp-row-title">To:</label>
<div className="mmp-row-value" style={{ position: 'relative', zIndex: 2 }}>
<RecipientsSelect mutableValues={mailbox.to} />
{this.state.loaded && <RecipientsSelect mutableValues={mailbox.to} />}
</div>
</div>
<div className="mmp-row">
Expand Down
14 changes: 12 additions & 2 deletions src/pages/ContactsPage/ContactsPage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/stores/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ class Contacts {
};
}

generateNewContactFromParams(name: IContact['name'], address: IContact['address']) {
this.newContact = {
name,
address,
description: '',
tags: [],
};
}

resetNewContact() {
this.newContact = null;
}
Expand Down