Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #1113 - Merge menu bars #1117

Merged
merged 9 commits into from
Apr 23, 2020
Merged
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { makeStyles, Theme } from "@material-ui/core";
import classNames from "classnames";
import { Badge, Block, Typography } from "medulas-react-components";
import * as React from "react";

import { ProcessedTx } from "../../../../logic/transactions/types/BwParser";
import { history } from "../../../../routes";
import { ADDRESSES_ROUTE, BALANCE_ROUTE, TRANSACTIONS_ROUTE } from "../../../../routes/paths";
import {
ADDRESSES_ROUTE,
BALANCE_ROUTE,
IOVNAME_ROUTE,
STARNAME_ROUTE,
TRANSACTIONS_ROUTE,
} from "../../../../routes/paths";
import { getLastTx, TxMeta } from "../../../../utils/localstorage/transactions";

const useStyles = makeStyles((theme: Theme) => ({
Expand All @@ -21,13 +26,7 @@ const useStyles = makeStyles((theme: Theme) => ({
cursor: "pointer",
},
},
activated: {
"& $line": {
visibility: "visible",
},
},
line: {
visibility: "hidden",
height: "4px",
backgroundColor: theme.palette.primary.main,
borderRadius: "4px",
Expand All @@ -39,14 +38,22 @@ const onBalance = (): void => {
history.push(BALANCE_ROUTE);
};

const onAddresses = (): void => {
history.push(ADDRESSES_ROUTE);
const onStarnames = (): void => {
history.push(STARNAME_ROUTE);
};

const onIovnames = (): void => {
history.push(IOVNAME_ROUTE);
};

const onTransactions = (): void => {
history.push(TRANSACTIONS_ROUTE);
};

const onAddresses = (): void => {
history.push(ADDRESSES_ROUTE);
};

const lastTxNewer = (lastTx: TxMeta, lastStoredTx: TxMeta): boolean => {
return lastTx.time.getTime() > lastStoredTx.time.getTime();
};
Expand Down Expand Up @@ -75,9 +82,11 @@ const calcTxBadgeVisibilityState = (
return false;
};

const BALANCE_TEXT = "Balances";
export const ADDRESSES_TEXT = "Addresses";
export const TRANSACTIONS_TEXT = "Transactions";
export const BALANCES_TAB_TITLE = "Balances";
export const STARNAMES_TAB_TITLE = "Starnames";
export const IOVNAMES_TAB_TITLE = "iovnames";
export const TRANSACTIONS_TAB_TITLE = "Transactions";
export const ADDRESSES_TAB_TITLE = "Addresses";

interface MenuItemProps {
readonly showBadge?: boolean;
Expand Down Expand Up @@ -108,34 +117,41 @@ interface Props {

const LinksMenu = ({ path, lastTx }: Props): JSX.Element => {
const classes = useStyles();
const showBalance = path === BALANCE_ROUTE;

const showBalances = path === BALANCE_ROUTE;
const showStarnames = path === STARNAME_ROUTE;
const showIovnames = path === IOVNAME_ROUTE;
const showTransactions = path === TRANSACTIONS_ROUTE;
const showAddresses = path === ADDRESSES_ROUTE;

const balanceClasses = classNames(classes.item, showBalance ? classes.activated : undefined);
const addressesClasses = classNames(classes.item, showAddresses ? classes.activated : undefined);
const transactionsClasses = classNames(classes.item, showTransactions ? classes.activated : undefined);

const showBadge = calcTxBadgeVisibilityState(lastTx, getLastTx());

return (
<Block className={classes.root}>
<Block className={balanceClasses}>
<LinkMenuItem onClick={onBalance} itemTitle={BALANCE_TEXT} />
<Block className={classes.line} />
<Block className={classes.item}>
<LinkMenuItem onClick={onBalance} itemTitle={BALANCES_TAB_TITLE} />
{showBalances && <Block className={classes.line} />}
</Block>
<Block className={classes.item}>
<LinkMenuItem onClick={onStarnames} itemTitle={STARNAMES_TAB_TITLE} />
{showStarnames && <Block className={classes.line} />}
</Block>
<Block className={addressesClasses}>
<LinkMenuItem onClick={onAddresses} itemTitle={ADDRESSES_TEXT} />
<Block className={classes.line} />
<Block className={classes.item}>
<LinkMenuItem onClick={onIovnames} itemTitle={IOVNAMES_TAB_TITLE} />
{showIovnames && <Block className={classes.line} />}
</Block>
<Block className={transactionsClasses}>
<Block className={classes.item}>
<LinkMenuItem
onClick={onTransactions}
itemTitle={TRANSACTIONS_TEXT}
itemTitle={TRANSACTIONS_TAB_TITLE}
badgeText="new"
showBadge={showBadge}
/>
<Block className={classes.line} />
{showTransactions && <Block className={classes.line} />}
</Block>
<Block className={classes.item}>
<LinkMenuItem onClick={onAddresses} itemTitle={ADDRESSES_TAB_TITLE} />
{showAddresses && <Block className={classes.line} />}
</Block>
</Block>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const AssociatedNamesList: React.FunctionComponent<Props> = ({
setShow(show => !show);
};

const hasAssociatedNames = names.length > 0;

return (
<React.Fragment>
<Block width={650} display="flex" justifyContent="center" flexDirection="column">
Expand All @@ -74,55 +76,59 @@ const AssociatedNamesList: React.FunctionComponent<Props> = ({
</Block>
</Paper>

<Block marginTop={4} display="flex" justifyContent="center">
<Block onClick={toggleShowAccounts} data-test={ACCOUNT_MANAGE_TOGGLE_SHOW_NAMES}>
<Block display="inline" marginRight={1}>
<Typography variant="subtitle2" weight="semibold" align="center" inline link>
Names associated with this starname
</Typography>
{hasAssociatedNames && (
<React.Fragment>
<Block marginTop={4} display="flex" justifyContent="center">
<Block onClick={toggleShowAccounts} data-test={ACCOUNT_MANAGE_TOGGLE_SHOW_NAMES}>
<Block display="inline" marginRight={1}>
<Typography variant="subtitle2" weight="semibold" align="center" inline link>
Names associated with this starname
</Typography>
</Block>
<Image src={showIcon} alt="arrow" />
</Block>
</Block>
<Image src={showIcon} alt="arrow" />
</Block>
</Block>
<Collapse in={show}>
{names
.slice()
.sort((a, b) =>
`${a.name}*${a.domain}`.localeCompare(`${b.name}*${b.domain}`, undefined, {
sensitivity: "base",
}),
)
.map(name => {
const onEdit = (): void => {
history.push(NAME_EDIT_ROUTE, name);
};
<Collapse in={show}>
{names
.slice()
.sort((a, b) =>
`${a.name}*${a.domain}`.localeCompare(`${b.name}*${b.domain}`, undefined, {
sensitivity: "base",
}),
)
.map(name => {
const onEdit = (): void => {
history.push(NAME_EDIT_ROUTE, name);
};

const accountState: AccountLocationState = {
domain: domain,
account: name,
};
const accountState: AccountLocationState = {
domain: domain,
account: name,
};

const menuItems: readonly ActionMenuItem[] = [
{ title: "Transfer name", action: () => history.push(NAME_TRANSFER_ROUTE, accountState) },
{
title: "Transfer it back to me",
action: () => history.push(NAME_TRANSFER_BACK_ROUTE, accountState),
},
{ title: "Delete name", action: () => history.push(NAME_DELETE_ROUTE, accountState) },
];
const menuItems: readonly ActionMenuItem[] = [
{ title: "Transfer name", action: () => history.push(NAME_TRANSFER_ROUTE, accountState) },
{
title: "Transfer it back to me",
action: () => history.push(NAME_TRANSFER_BACK_ROUTE, accountState),
},
{ title: "Delete name", action: () => history.push(NAME_DELETE_ROUTE, accountState) },
];

return (
<AccountManage
key={`${name.name}*${name.domain}`}
menuItems={menuItems}
onEdit={onEdit}
account={name}
hideExpiration={true}
transferedTo={domain.owner !== name.owner ? name.owner : undefined}
/>
);
})}
</Collapse>
return (
<AccountManage
key={`${name.name}*${name.domain}`}
menuItems={menuItems}
onEdit={onEdit}
account={name}
hideExpiration={true}
transferedTo={domain.owner !== name.owner ? name.owner : undefined}
/>
);
})}
</Collapse>
</React.Fragment>
)}
</Block>
</React.Fragment>
);
Expand Down

This file was deleted.

This file was deleted.

Loading