This commit is contained in:
2020-08-22 22:28:50 +02:00
parent 8cc811fa3f
commit de3570e0f1
3 changed files with 36 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { hot } from 'react-hot-loader/root'; import { hot } from 'react-hot-loader/root';
import { Layout } from 'antd'; import { Layout, Menu } from 'antd';
import { GithubProvider } from './contexts/Github'; import { GithubProvider } from './contexts/Github';
import { EncryptionProvider } from './contexts/Encryption'; import { EncryptionProvider } from './contexts/Encryption';
import { DecryptionProvider } from './contexts/Decryption'; import { DecryptionProvider } from './contexts/Decryption';
@@ -11,6 +11,8 @@ const App: React.FC = () => (
<EncryptionProvider> <EncryptionProvider>
<DecryptionProvider> <DecryptionProvider>
<Layout style={{minHeight:"100vh"}}> <Layout style={{minHeight:"100vh"}}>
<Layout.Header>
</Layout.Header>
<Layout.Content style={{ padding: '25px', maxWidth: '800px', width: '100%', margin: 'auto' }}> <Layout.Content style={{ padding: '25px', maxWidth: '800px', width: '100%', margin: 'auto' }}>
<AppRouter/> <AppRouter/>
</Layout.Content> </Layout.Content>

View File

@@ -8,6 +8,7 @@ interface DecryptionContextType {
publicKey: string | undefined; publicKey: string | undefined;
privateKey: string | undefined; privateKey: string | undefined;
createKey: (name: string, email: string) => void; createKey: (name: string, email: string) => void;
deleteKey: () => void;
files: {[id: string]: FileType}; files: {[id: string]: FileType};
addFile: (file: File) => Promise<void>; addFile: (file: File) => Promise<void>;
deleteFile: (id: string) => void; deleteFile: (id: string) => void;
@@ -24,6 +25,7 @@ const DecryptionContext = createContext<DecryptionContextType>({
privateKey: undefined, privateKey: undefined,
files: {}, files: {},
createKey: async () => { throw new Error('Not using provider'); }, createKey: async () => { throw new Error('Not using provider'); },
deleteKey: async () => { throw new Error('Not using provider'); },
addFile: async () => { throw new Error('Not using provider'); }, addFile: async () => { throw new Error('Not using provider'); },
deleteFile: async () => { throw new Error('Not using provider'); }, deleteFile: async () => { throw new Error('Not using provider'); },
}); });
@@ -71,6 +73,12 @@ const DecryptionProvider: React.FC = ({
run(); run();
}, []); }, []);
const deleteKey = () => {
setPublicKey(undefined);
setPrivateKey(undefined);
localStorage.removeItem('key');
};
const createKey = async () => { const createKey = async () => {
const key = await openpgp.generateKey({ const key = await openpgp.generateKey({
userIds: [{ name: 'unknown unknown', email: 'unknown@unknown.foo'}], userIds: [{ name: 'unknown unknown', email: 'unknown@unknown.foo'}],
@@ -103,6 +111,7 @@ const DecryptionProvider: React.FC = ({
publicKey, publicKey,
privateKey, privateKey,
createKey, createKey,
deleteKey,
files, files,
addFile, addFile,
deleteFile, deleteFile,

View File

@@ -1,5 +1,5 @@
import React, { useContext, useState, useCallback } from 'react'; import React, { useContext, useState, useCallback } from 'react';
import { Space, Typography, Input, Button, Form } from 'antd'; import { Popconfirm, Space, Typography, Input, Button, Form } from 'antd';
import DecryptionContext from '../contexts/Decryption'; import DecryptionContext from '../contexts/Decryption';
import { downloadLink } from '../helpers/files'; import { downloadLink } from '../helpers/files';
import { import {
@@ -12,6 +12,7 @@ import {
const SetupKey: React.FC = () => { const SetupKey: React.FC = () => {
const { const {
createKey, createKey,
deleteKey,
publicKey, publicKey,
} = useContext(DecryptionContext); } = useContext(DecryptionContext);
@@ -86,7 +87,7 @@ const SetupKey: React.FC = () => {
<p> <p>
Remember that you need to go to this website on this device to decrypt the files after receiving them Remember that you need to go to this website on this device to decrypt the files after receiving them
</p> </p>
<Space direction="vertical" size="large">
<Button <Button
onClick={downloadPublicKey} onClick={downloadPublicKey}
type="primary" type="primary"
@@ -95,6 +96,19 @@ const SetupKey: React.FC = () => {
> >
Download sharing key Download sharing key
</Button> </Button>
<Popconfirm
title="Are you sure?"
onConfirm={deleteKey}
>
<Button
danger
size="small"
type="link"
>
Delete sharing key
</Button>
</Popconfirm>
</Space>
</div> </div>
); );
} }