Skip to content

Commit bfbc5a0

Browse files
author
k.golikov
committed
Add history to UuidGeneratorPage
1 parent 437675c commit bfbc5a0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/pages/uuidGeneratorPage/UuidGeneratorPage.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import React, { useState } from 'react';
1+
import React, { useCallback, useMemo, useState } from 'react';
22
import PageContainer from '../../layouts/pages/pageContainer/PageContainer';
33
import { Button, Col, Row, Space } from 'antd';
44
import { v4 } from 'uuid';
55
import Text from 'antd/lib/typography/Text';
66
import ExternalLink from '../../components/ExternalLink';
77
import CopyButton from '../../components/copyButton/CopyButton';
88
import getNpmPackageLink from '../../utils/getNpmPackageLink';
9+
import useStateProducer from '../../hooks/useStateProducer';
10+
import TextArea from 'antd/lib/input/TextArea';
11+
import { useDidMount } from 'rooks';
912

1013
const titleExtra = (
1114
<Text type="secondary">
@@ -14,13 +17,26 @@ const titleExtra = (
1417
);
1518

1619
const UuidGeneratorPage = () => {
17-
const [uuid, setUuid] = useState<string>(v4());
20+
const [uuid, setUuid] = useState<string>();
21+
const [history, setHistory] = useState<string[]>([]);
22+
const produceHistory = useStateProducer(setHistory);
1823

19-
const generate = () => {
24+
const historyString = useMemo<string>(() => {
25+
return history.join('\n');
26+
}, [history]);
27+
28+
const generate = useCallback(() => {
2029
const newUuid = v4();
2130
setUuid(newUuid);
31+
produceHistory((history) => {
32+
history.unshift(newUuid);
33+
});
2234
return newUuid;
23-
};
35+
}, []);
36+
37+
useDidMount(() => {
38+
generate();
39+
});
2440

2541
return (
2642
<PageContainer title="UUID Generator" titleExtra={titleExtra}>
@@ -32,12 +48,13 @@ const UuidGeneratorPage = () => {
3248
</Text>
3349
</Space>
3450
</Row>
35-
<Space>
51+
<Space className="mb-2">
3652
<Button onClick={generate}>Generate</Button>
3753
<CopyButton value={uuid} onClick={generate}>
3854
Generate and copy
3955
</CopyButton>
4056
</Space>
57+
<TextArea value={historyString} rows={6} />
4158
</Col>
4259
</PageContainer>
4360
);

0 commit comments

Comments
 (0)