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

Redesign + Identities #77

Merged
merged 21 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
6 changes: 5 additions & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/react": "^2.8.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"dash": "^3.24.15",
"express": "^4.18.2",
"framer-motion": "^10.16.4",
"node-fetch": "^3.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-paginate": "^8.2.0",
"react-router-dom": "^6.12.1",
"react-scripts": "5.0.1",
"react-tabs": "^6.0.2",
"sass": "^1.69.2",
"web-vitals": "^2.1.4"
},
Expand Down
19 changes: 19 additions & 0 deletions packages/frontend/src/components/Identifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

pshenmic marked this conversation as resolved.
Show resolved Hide resolved
function Identifier ({value, maxSymbols = -1}) {

if (maxSymbols > 0 && maxSymbols < value.length) {
return (
<>
{value.slice(0, maxSymbols)}...{value.slice(value.length - maxSymbols, value.length)}
pshenmic marked this conversation as resolved.
Show resolved Hide resolved
</>
);
} else {
return (
<>
{value}
</>
);
}
}

export default Identifier;
80 changes: 11 additions & 69 deletions packages/frontend/src/components/RootComponent.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,21 @@
import {Outlet, Link} from "react-router-dom";
import "./root.css";
import React, {useState} from 'react';
import * as Api from '../util/Api'
import {useNavigate} from "react-router-dom";
import ModalWindow from "./ModalWindow";
import Navbar from "../components/navbar/Navbar";
import theme from "../styles/theme";
import "../styles/theme.scss";
import { ChakraProvider} from '@chakra-ui/react'

export default function RootComponent() {
let navigate = useNavigate();

const [showModal, setShowModal] = useState(false)
const [modalText, setModalText] = useState("false")

const showModalWindow = (text, timeout) => {
setShowModal(true)
setModalText(text)

if (timeout) {
setTimeout(() => {
setShowModal(false)
setModalText("")
}, timeout)
}
}

const handleKeyPress = async (event) => {
if (event.key === 'Enter') {
try {
const searchResult = await Api.search(searchQuery)

if (searchResult?.block) {
// redirect to blocks
console.log(searchResult?.block.header.hash)
setSearchQuery("")
return navigate(`/block/${searchResult?.block.header.hash}`)
}

if (searchResult?.transaction) {
setSearchQuery("")
return navigate(`/transaction/${searchResult?.transaction.hash}`)
}

if (searchResult?.dataContract) {
setSearchQuery("")
return navigate(`/dataContract/${searchResult?.dataContract.identifier}`)
}

if (searchResult?.document) {
setSearchQuery("")
return navigate(`/document/${searchResult?.document.identifier}`)
}

showModalWindow('Not found', 6000)
} catch (e) {
showModalWindow('Not found', 6000)
}
}
}

const handleSearchInput = (event) => {
setSearchQuery(event.target.value)
}

const [searchQuery, setSearchQuery] = useState("");
export default function RootComponent({cookies}) {
pshenmic marked this conversation as resolved.
Show resolved Hide resolved

return (
<div>
<div className="topnav">
<Link to="/">Home</Link>
<Link to="/blocks">Blocks</Link>
<Link to="/dataContracts">Data Contracts</Link>
<input value={searchQuery} type="text" placeholder="Search..." onChange={handleSearchInput}
onKeyPress={handleKeyPress}/>
<ModalWindow open={showModal} text={modalText} setShowModal={setShowModal}/>
</div>
<ChakraProvider theme={theme}>

<Navbar/>

<Outlet/>
</div>

</ChakraProvider>
);
}
32 changes: 32 additions & 0 deletions packages/frontend/src/components/blocks/BlocksList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {Link} from "react-router-dom";
import BlocksListItem from './BlocksListItem'
import './BlocksList.scss'


function BlocksList ({items = [], columnsCount = -1, size = 'l'}) {
pshenmic marked this conversation as resolved.
Show resolved Hide resolved
return(
<div
className='BlocksList'
style={{
columnCount: items.length > 1 ? columnsCount : 1,
}}
>
{items.map((block) =>
<BlocksListItem
key={block.hash}
hash={block.header.hash}
height={block.header.height}
timestamp={block.header.timestamp}
txsLength={block.txs.length}
size={size}
/>
)}

{items.length === 0 &&
<div className='documents_list__empty_message'>There are no documents created yet.</div>
}
</div>
)
}

export default BlocksList;
3 changes: 3 additions & 0 deletions packages/frontend/src/components/blocks/BlocksList.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.BlocksList {

}
47 changes: 47 additions & 0 deletions packages/frontend/src/components/blocks/BlocksListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {Link} from "react-router-dom";
import './BlocksListItem.scss'
import Identifier from '../Identifier'


function BlocksListItem ({ hash, height = '', timestamp, txsLength, size = 'l' }) {
let hashMaxSymbols = -1;

switch (size) {
case 'm':
hashMaxSymbols = 6;
break;
case 's':
hashMaxSymbols = 6;
break;
}

return(
<Link to={`/block/${hash}`} className={"BlocksListItem"}>
{(size === 'l' &&
<span className={"BlocksListItem__Height"}>{height}</span>
)}

{typeof timestamp === 'string' &&
<span className={"BlocksListItem__Timestamp"}>
{new Date(timestamp).toLocaleString()}
</span>
}


{typeof hash === 'string' &&
<span className={"BlocksListItem__Hash"}>
<Identifier value={hash} maxSymbols={hashMaxSymbols}/>
</span>
}

{(typeof txsLength === 'number' || typeof txsLength === 'string') &&
<span className={"BlocksListItem__Txs"}>
({txsLength} txs)
</span>
}

</Link>
)
}

export default BlocksListItem;
68 changes: 68 additions & 0 deletions packages/frontend/src/components/blocks/BlocksListItem.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@use '../../styles/mixins.scss';

.BlocksListItem {
@include mixins.def_list_item;

&:last-child {
border-bottom: none;
}

&__Hash {
color: var(--chakra-colors-gray-200);
flex-grow: 1;

text-overflow: ellipsis;
overflow: hidden;
line-height: 24px;
white-space: nowrap;
}

&__Height {
font-weight: bold;
margin-right: 8px;
word-break: keep-all;
}

&__Timestamp {
margin-right: 16px;
text-wrap: nowrap;
}

&__Txs {
margin-left: 12px;
text-wrap: nowrap;
}


@media screen and (max-width: 620px) {
flex-wrap: wrap;

&__Height {
order: 1;
margin-right: 4px;
}

&__Txs {
order: 2;
margin-left: 0;
margin-right: 6px;
}

&__Timestamp {
order: 3;
}

&__Hash {
order: 4;
flex-grow: unset;
margin-top: 2px;
}
}

@media screen and (max-width: 400px) {
&__Timestamp {
text-wrap: wrap;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import DataContractsListItem from './DataContractsListItem'


function DataContractsList ({items = [], size = 'l'}) {
return (

<div className='DataContractsList'>

{items.map((dataContract, key) =>
<DataContractsListItem
key={key}
identifier={dataContract.identifier}
size={size}
/>
)}

{items.length === 0 &&
<div className='DataContractsList__EmptyMessage'>There are no data contracts created yet.</div>
}

</div>

);
}

export default DataContractsList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {Link} from "react-router-dom";
import Identifier from '../Identifier'
import './DataContractsListItem.scss'


function DataContractsListItem ({identifier, size = 'l'}) {
let maxSymbols = -1;

switch (size) {
case 'm':
maxSymbols = 6;
break;
case 's':
maxSymbols = 3;
break;
}

return (
<>
{typeof identifier === 'string' &&
pshenmic marked this conversation as resolved.
Show resolved Hide resolved
<Link to={`/dataContract/${identifier}`} className="DataContractsListItem">
<div className="DataContractsListItem__Identifier">
<Identifier value={identifier} maxSymbols={maxSymbols}/>
</div>
</Link>
}
</>
);
}

export default DataContractsListItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@use '../../styles/mixins.scss';

.DataContractsListItem {

@include mixins.def_list_item;

&__Identifier {
text-overflow: ellipsis;
overflow: hidden;
line-height: 24px;
white-space: nowrap;
}
}
24 changes: 24 additions & 0 deletions packages/frontend/src/components/documents/DocumentsList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import DocumentsListItem from "./DocumentsListItem";
import './DocumentsList.scss'

export default function DocumentsList({items = [], columnsCount = 1}) {
return (
<div
className='DocumentsList'
style={{
columnCount: items.length > 1 ? columnsCount : 1,
}}
>
{items.map((document, key) =>
<DocumentsListItem
key={key}
identifier={document.identifier}
/>
)}

{items.length === 0 &&
<div className='DocumentsList__EmptyMessage'>There are no documents created yet.</div>
}
</div>
);
}
Loading