Skip to content

Commit

Permalink
refactor: Library architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola authored Jun 29, 2023
2 parents 54aee58 + 632b642 commit 4bd3dd5
Show file tree
Hide file tree
Showing 47 changed files with 1,421 additions and 1,052 deletions.
119 changes: 64 additions & 55 deletions cypress/e2e/front/landing.cy.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
describe('Good front for Landing', () => {
it('Go to landing', () => {
cy.visit('');
});

it ('Good text', () => {
cy.get('#ipc-landing-navigation-name').should('contain', 'Inter Planetary Cloud');
cy.get("#ipc-landing-headline").should('contain', 'The first distributed cloud unsealing your data.');
cy.get("#ipc-landing-subHeadline").should('contain', 'Build on top of Aleph, the next generation network of distributed big data applications.');
cy.get("#ipc-landing-services-title").should('contain', 'Inter Planetary Cloud offers two services');
cy.get("#ipc-landing-features-title").should('contain', 'Our Features');
})

it('Good text for features cards', () => {
cy.get("#ipc-landing-feature-upload-files").should('contain', 'Upload & Download Files');
cy.get("#ipc-landing-folder-management").should('contain', 'Folder Management');
cy.get("#ipc-landing-share-files").should('contain', 'Share Files');
cy.get("#ipc-landing-programs").should('contain', 'Upload & Run Programs');
cy.get("#ipc-landing-contact-management").should('contain', 'Contact Management');
})

it('Good text for services cards', () => {
cy.get("#ipc-landing-services-cloud-storage-title").should('contain', 'Cloud Storage');
cy.get("#ipc-landing-services-cloud-storage-description").should('contain', 'A distributed personal file storage and management system platform, protecting your data.');
cy.get('#ipc-landing-services-cloud-computing-title').should('contain', 'Cloud Computing');
cy.get('#ipc-landing-services-cloud-computing-description').should('contain', 'A distributed personal cloud computing platform for HTTP servers.');
});

it('Good text for start buttons', () => {
cy.get("#ipc-landing-heading-start-button").should('contain', 'Start the experiment');
cy.get("#ipc-landing-features-start-button").should('contain', 'Start the experiment');
})

it('Good number of elements', () => {
cy.get("button").should('have.length', 2);
cy.get('img').should('have.length', 7);
cy.get('svg').should('have.length', 14);
cy.get('#ipc-landing-services-cloud-storage').should('have.length', 1);
cy.get('#ipc-landing-services-cloud-computing').should('have.length', 1);
})
});

describe('Good redirect for Landing', () => {
beforeEach(() => {
cy.visit('');
});

it('Good redirection for heading button', () => {
cy.get("#ipc-landing-heading-start-button").click().url().should('eq', `${Cypress.config().baseUrl}/connection`);
});

it('Good redirection for features button', () => {
cy.get("#ipc-landing-features-start-button").click().url().should('eq', `${Cypress.config().baseUrl}/connection`);
});
});
describe('Good front for Landing', () => {
it('Go to landing', () => {
cy.visit('');
});

it('Good text', () => {
cy.get('#ipc-landing-navigation-name').should('contain', 'Inter Planetary Cloud');
cy.get('#ipc-landing-headline').should('contain', 'The first distributed cloud unsealing your data.');
cy.get('#ipc-landing-subHeadline').should(
'contain',
'Build on top of Aleph, the next generation network of distributed big data applications.',
);
cy.get('#ipc-landing-services-title').should('contain', 'Inter Planetary Cloud offers two services');
cy.get('#ipc-landing-features-title').should('contain', 'Our Features');
});

it('Good text for features cards', () => {
cy.get('#ipc-landing-feature-upload-files').should('contain', 'Upload & Download Files');
cy.get('#ipc-landing-folder-management').should('contain', 'Folder Management');
cy.get('#ipc-landing-share-files').should('contain', 'Share Files');
cy.get('#ipc-landing-programs').should('contain', 'Upload & Run Programs');
cy.get('#ipc-landing-contact-management').should('contain', 'Contact Management');
});

it('Good text for services cards', () => {
cy.get('#ipc-landing-services-cloud-storage-title').should('contain', 'Cloud Storage');
cy.get('#ipc-landing-services-cloud-storage-description').should(
'contain',
'A distributed personal file storage and management system platform, protecting your data.',
);
cy.get('#ipc-landing-services-cloud-computing-title').should('contain', 'Cloud Computing');
cy.get('#ipc-landing-services-cloud-computing-description').should(
'contain',
'A distributed personal cloud computing platform for HTTP servers.',
);
});

it('Good text for start buttons', () => {
cy.get('#ipc-landing-heading-start-button').should('contain', 'Start the experiment');
cy.get('#ipc-landing-features-start-button').should('contain', 'Start the experiment');
});

it('Good number of elements', () => {
cy.get('button').should('have.length', 2);
cy.get('img').should('have.length', 7);
cy.get('svg').should('have.length', 14);
cy.get('#ipc-landing-services-cloud-storage').should('have.length', 1);
cy.get('#ipc-landing-services-cloud-computing').should('have.length', 1);
});
});

describe('Good redirect for Landing', () => {
beforeEach(() => {
cy.visit('');
});

it('Good redirection for heading button', () => {
cy.get('#ipc-landing-heading-start-button').click().url().should('eq', `${Cypress.config().baseUrl}/connection`);
});

it('Good redirection for features button', () => {
cy.get('#ipc-landing-features-start-button').click().url().should('eq', `${Cypress.config().baseUrl}/connection`);
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/front/signup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Good front for Signup', () => {

it('Good name for go to dashboard button', () => {
cy.get('#ipc-signup-go-to-dashboard-button').should('contain', 'Go to my dashboard');
})
});
});

describe('Signup with credentials Button for Signup', () => {
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/core": "^7.21.8",
"@babel/core": "^7.22.5",
"@chakra-ui/icons": "^2.0.19",
"@chakra-ui/react": "^2.6.1",
"@chakra-ui/styled-system": "^2.9.0",
"@chakra-ui/system": "^2.5.7",
"@chakra-ui/theme-tools": "^2.0.16",
"@emotion/react": "^11.11.0",
"@chakra-ui/react": "^2.7.1",
"@chakra-ui/styled-system": "^2.9.1",
"@chakra-ui/system": "^2.5.8",
"@chakra-ui/theme-tools": "^2.0.18",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"aleph-sdk-ts": "^3.2.0",
"axios": "^1.4.0",
"boring-avatars": "^1.7.0",
"boring-avatars": "^1.10.1",
"crypto-js": "^4.1.1",
"eth-crypto": "^2.6.0",
"ethers": "^5.7.2",
"framer-motion": "^10.12.12",
"framer-motion": "^10.12.17",
"git-clone": "^0.2.0",
"js-file-download": "^0.4.12",
"next": "^12.3.4",
"next-auth": "4.10.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0",
"typescript": "^5.0.4",
"react-icons": "^4.10.1",
"typescript": "^5.1.3",
"zod": "^3.21.4"
},
"scripts": {
Expand Down Expand Up @@ -54,13 +54,13 @@
"@types/crypto-js": "^4.1.1",
"@types/git-clone": "^0.2.0",
"@types/node": "^16.18.31",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"cypress": "^11.2.0",
"cypress-file-upload": "^5.0.8",
"eslint": "^8.40.0",
"eslint": "^8.43.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.8.0",
Expand Down
3 changes: 3 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const App = ({
const [sharedFiles, setSharedFiles] = useState<IPCFile[]>([]);
const [folders, setFolders] = useState<IPCFolder[]>([]);
const [programs, setPrograms] = useState<IPCProgram[]>([]);
const [sharedPrograms, setSharedPrograms] = useState<IPCProgram[]>([]);
const [contacts, setContacts] = useState<IPCContact[]>([]);
const [path, setPath] = useState('/');
const toast = useToast();
Expand Down Expand Up @@ -89,6 +90,8 @@ const App = ({
setSharedFiles,
folders,
setFolders,
sharedPrograms,
setSharedPrograms,
programs,
setPrograms,
contacts,
Expand Down
14 changes: 8 additions & 6 deletions pages/drive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const Dashboard = (): JSX.Element => {
const { setConfig } = useConfigContext();
const { colorMode, toggleColorMode } = useColorMode();

const { path, folders, files, setFiles, setFolders, setContacts, setPrograms, setSharedFiles } = useDriveContext();
const { path, folders, files, setFiles, setFolders, setContacts, setPrograms, setSharedFiles, setSharedPrograms } =
useDriveContext();

useEffect(() => {
(async () => {
Expand All @@ -27,22 +28,23 @@ const Dashboard = (): JSX.Element => {
}, []);

const loadContact = async () => {
const load = await user.contact.load();
const load = await user.fullContact.contact.load();

toast({ title: load.message, status: load.success ? 'success' : 'error' });
setContacts(user.contact.contacts);
setContacts(user.fullContact.contact.contacts);
};

const loadUserContents = async () => {
const loadShared = await user.drive.loadShared(user.contact.contacts);
const loadShared = await user.drive.loadShared(user.fullContact.contact.contacts);
toast({ title: loadShared.message, status: loadShared.success ? 'success' : 'error' });
setFiles(user.drive.files);
setFolders(user.drive.folders);
setSharedFiles(user.drive.sharedFiles);
setSharedPrograms(user.drive.sharedPrograms);

const loadedPrograms = await user.computing.load();
const loadedPrograms = await user.fullContact.computing.load();
toast({ title: loadedPrograms.message, status: loadedPrograms.success ? 'success' : 'error' });
setPrograms(user.computing.programs);
setPrograms(user.fullContact.computing.programs);

const loadedConfig = await user.loadConfig();
setConfig(user.config);
Expand Down
3 changes: 2 additions & 1 deletion pages/drive/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { useDriveContext } from 'contexts/drive';

const Shared = (): JSX.Element => {
const { sharedFiles } = useDriveContext();
const { sharedPrograms } = useDriveContext();

return (
<Navigation>
<VStack w="100%" spacing="48px" align="start">
<LabelBadge label="Share with me" />
<DriveCards files={sharedFiles.filter((elem) => !elem.deletedAt)} />
<DriveCards files={sharedFiles.filter((elem) => !elem.deletedAt)} programs={sharedPrograms} />
</VStack>
</Navigation>
);
Expand Down
7 changes: 3 additions & 4 deletions src/components/account/AccountCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import Avatar from 'boring-avatars';
import { ChangeEvent, useState } from 'react';
import { BsClipboard } from 'react-icons/bs';

import Card from 'components/cards/Card';

import { useUserContext } from 'contexts/user';
Expand All @@ -29,15 +28,15 @@ import Modal from '../Modal';
const AccountCard = (): JSX.Element => {
const { user } = useUserContext();
const [isOpen, setIsOpen] = useState<boolean>(false);
const [input, setInput] = useState<string>(user.contact.username || '');
const [input, setInput] = useState<string>(user.fullContact.contact.username || '');
const [isLoading, setIsLoading] = useState<boolean>(false);

const toast = useToast({ duration: 2000, isClosable: true });

const changeName = async () => {
setIsLoading(true);
try {
const config1 = await user.contact.update(user.account.address, input);
const config1 = await user.fullContact.manage.update(user.account.address, input);
setIsOpen(false);
toast({ title: config1.message, status: config1.success ? 'success' : 'error' });
} catch (error) {
Expand Down Expand Up @@ -92,7 +91,7 @@ const AccountCard = (): JSX.Element => {
]}
/>
<Text color={textColor} size="xl">
{user.contact.username}
{user.fullContact.contact.username}
</Text>
</HStack>
<HStack spacing="16px">
Expand Down
2 changes: 1 addition & 1 deletion src/components/account/ConfigCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ConfigCard = (): JSX.Element => {
const changeConfig = async (key: string, value: string) => {
setIsLoading(true);
try {
const config1 = await user.contact.updateConfig(key, value);
const config1 = await user.fullContact.manage.updateConfig(key, value);
setConfig({
...user.config,
[key]: {
Expand Down
5 changes: 3 additions & 2 deletions src/components/cards/FileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const FileCard = ({ file }: { file: IPCFile }): JSX.Element => {
const { files } = useDriveContext();
const {
user: {
contact: { username },
fullContact: {
contact: { username },
},
},
} = useUserContext();

Expand All @@ -33,7 +35,6 @@ const FileCard = ({ file }: { file: IPCFile }): JSX.Element => {

const isDrawer = useBreakpointValue({ base: true, sm: false }) || false;
const textColor = useColorModeValue(textColorMode.light, textColorMode.dark);

return (
<>
<Card
Expand Down
4 changes: 3 additions & 1 deletion src/components/cards/FolderCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const FolderCard = ({ folder }: { folder: IPCFolder }): JSX.Element => {
const { path, setPath } = useDriveContext();
const {
user: {
contact: { username },
fullContact: {
contact: { username },
},
},
} = useUserContext();

Expand Down
4 changes: 3 additions & 1 deletion src/components/cards/ProgramCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import Card from './Card';
const ProgramCard = ({ program }: { program: IPCProgram }): JSX.Element => {
const {
user: {
contact: { username },
fullContact: {
contact: { username },
},
},
} = useUserContext();
const { isOpen: isOpenFile, onOpen: onOpenFile, onClose: onCloseFile } = useDisclosure();
Expand Down
8 changes: 5 additions & 3 deletions src/components/computing/github/GithubModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ const GithubModal = ({ isOpen, onClose }: { isOpen: boolean; onClose: () => void
hash: result.data.item_hash,
createdAt: Date.now(),
entrypoint: result.data.entrypoint,
permission: 'owner',
size: 0,
logs: [
{
action: 'Program created',
date: Date.now(),
},
],
hashFile: '',
};
user.computing.programs.push(newProgram);
await user.computing.publishAggregate();
setPrograms(user.computing.programs);
user.fullContact.computing.programs.push(newProgram);
await user.fullContact.computing.publishAggregate();
setPrograms(user.fullContact.computing.programs);
toast({ title: 'Upload succeeded', status: 'success' });
onClose();
} catch (err) {
Expand Down
Loading

0 comments on commit 4bd3dd5

Please sign in to comment.