Skip to content

Commit

Permalink
Better layout
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Feb 24, 2024
1 parent 1ef7f6c commit a6e1e06
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 30 deletions.
23 changes: 4 additions & 19 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { createRoot } from 'react-dom/client';
import { RouterProvider, createMemoryRouter } from 'react-router';
import { styled } from 'styled-components';
import React, { PureComponent } from 'react';
import Root from './routes/root';
import ErrorPage from './error-page';
import { Home } from './routes/home';
import ConnectionPage from './component/Connection/ConnectionPage';
import TableLayout from './component/TableLayout';
import ConnectionForm from './component/Connection/ConnectionForm';
import { Tables } from './routes/tables';
import Connect from './routes/connect';
import Create from './routes/connect/create';

const root = createRoot(document.getElementById('App'));

Expand All @@ -17,12 +16,6 @@ const root = createRoot(document.getElementById('App'));
// export const history = createMemoryHistory();
// <Router history={history}>

const ModalLike = styled.div`
width: 50%;
min-width: 400px;
align-self: center;
`;

const router = createMemoryRouter([
{
path: '/',
Expand All @@ -38,19 +31,11 @@ const router = createMemoryRouter([
children: [
{
index: true,
element: (
<ModalLike>
<ConnectionPage />
</ModalLike>
),
element: <Connect />,
},
{
path: 'create',
element: (
<ModalLike>
<ConnectionForm />
</ModalLike>
),
element: <Create />,
},
],
},
Expand Down
13 changes: 13 additions & 0 deletions src/component/Connection/ConnectionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from '../../Contexts';
import { ConnectionObject } from './types';
import { PureComponent, useContext } from 'react';
import { NavigateFunction, useNavigate } from 'react-router';

interface ConnectionFormProps {
connectTo: ConnectToFunc;
addConnectionToConfig: (connection: ConnectionObject) => void;
navigate: NavigateFunction;
}
type ConnectionFormType = ConnectionObject & {
save: boolean;
Expand All @@ -34,6 +36,8 @@ class ConnectionForm extends PureComponent<ConnectionFormProps> {
}

render() {
const { navigate } = this.props;

const initialValues = {
name: '',
host: 'localhost',
Expand Down Expand Up @@ -86,6 +90,13 @@ class ConnectionForm extends PureComponent<ConnectionFormProps> {
</Form.Item>

<Form.Item<ConnectionFormType>>
<Button
onClick={() => {
navigate(-1);
}}
>
Cancel
</Button>
<Button type="primary" htmlType="submit">
Connect
</Button>
Expand All @@ -98,9 +109,11 @@ class ConnectionForm extends PureComponent<ConnectionFormProps> {
function ConnectionFormWithContext() {
const { connectTo } = useContext(ConnectionContext);
const { addConnectionToConfig } = useConfiguration();
const navigate = useNavigate();

return (
<ConnectionForm
navigate={navigate}
connectTo={connectTo}
addConnectionToConfig={addConnectionToConfig}
/>
Expand Down
23 changes: 23 additions & 0 deletions src/component/Style/ModalLike.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { styled } from 'styled-components';

const Container = styled.div`
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`;

const Content = styled.div`
width: 50%;
min-width: 400px;
align-self: center;
`;

export default function ModalLike({ children }: { children: React.ReactNode }) {
return (
<Container>
<Content>{children}</Content>
</Container>
);
}
1 change: 1 addition & 0 deletions src/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EncryptedConfiguration,
} from './type';

// TODO use app.getPath('userData') to store the configuration file instead of env-paths
const envPath = envPaths('TianaTables', { suffix: '' });
const dataFilePath = resolve(envPath.config, 'config.json');

Expand Down
10 changes: 10 additions & 0 deletions src/routes/connect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ModalLike from '../component/Style/ModalLike';
import ConnectionPage from '../component/Connection/ConnectionPage';

export default function Connect() {
return (
<ModalLike>
<ConnectionPage />
</ModalLike>
);
}
10 changes: 10 additions & 0 deletions src/routes/connect/create.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ModalLike from '../../component/Style/ModalLike';
import ConnectionFormWithContext from '../../component/Connection/ConnectionForm';

export default function Create() {
return (
<ModalLike>
<ConnectionFormWithContext />
</ModalLike>
);
}
2 changes: 1 addition & 1 deletion src/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button } from 'antd';
export function Home() {
return (
<div>
<p>Welcome to Tiana Tables ! </p>
<p>Tiana Tables ! </p>

<Button type="primary">
<Link to="/connect">Please connect</Link>
Expand Down
32 changes: 22 additions & 10 deletions src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,40 @@ import {
import { styled } from 'styled-components';
import Debug from '../component/Debug';
import ThemeSelector from '../component/ThemeSelector';
import { Layout } from 'antd';
import { getSetting } from '../theme';

const HeaderDiv = styled.header`
const Header = styled(Layout.Header)`
display: flex;
justify-content: space-between;
align-items: center;
min-height: 46px;
background-color: ${({ theme }) => getSetting(theme, 'background')};
`;

const Content = styled(Layout.Content)`
padding: 16px;
display: flex;
flex-direction: column;
`;

export default function Root() {
return (
<ConfigurationContextProvider>
<ThemeContextProvider>
<ConnectionStack>
<Debug />
<Layout>
<Debug />
<Header>
<h2>Tiana Tables</h2>
<div>
Theme: <ThemeSelector />
</div>
</Header>

<HeaderDiv>
<h2>Welcome to Tiana Tables !</h2>
<div>
Theme: <ThemeSelector />
</div>
</HeaderDiv>
<Outlet />
<Content>
<Outlet />
</Content>
</Layout>
</ConnectionStack>
</ThemeContextProvider>
</ConfigurationContextProvider>
Expand Down

0 comments on commit a6e1e06

Please sign in to comment.