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

Implement main menu and re-authentication. #17

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@blueprintjs/core": "^4.9.3",
"@blueprintjs/datetime2": "^0.5.5",
"@blueprintjs/icons": "^4.4.1",
"@blueprintjs/popover2": "^1.12.0",
"@notionhq/client": "^2.1.1",
"@tauri-apps/api": "^1.0.2",
"react": "^18.2.0",
Expand Down
11 changes: 7 additions & 4 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"distDir": "../dist"
},
"package": {
"productName": "daily-notion",
"productName": "Daily Notion",
"version": "../package.json"
},
"tauri": {
Expand All @@ -26,7 +26,8 @@
"bundle": {
"active": true,
"category": "Productivity",
"copyright": "Copyright (c) 2022 hi_go",
"publisher": "hi_go",
"copyright": "Copyright (c) 2023 hi_go",
"deb": {
"depends": []
},
Expand All @@ -47,7 +48,7 @@
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"shortDescription": "A simple daily notes application using Notion API.",
"targets": "all",
"windows": {
"certificateThumbprint": null,
Expand All @@ -65,9 +66,11 @@
{
"fullscreen": false,
"height": 600,
"minHeight": 300,
"resizable": true,
"title": "Daily Notion",
"width": 800
"width": 800,
"minWidth": 400
}
]
}
Expand Down
8 changes: 7 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ div#root,
.Notepad {
height: 100%;
box-sizing: border-box;
}
}

.App{
display: flex;
flex-direction: column;
justify-content: start;
}
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { format } from "date-fns";

import { Navigation } from './Components/Navigation';
import { Notepad } from './Components/Notepad';
import { Classes } from '@blueprintjs/core';

export class App extends React.Component<any, { dateStr: string, syncStatus: SyncStatus }> {
constructor(props: any) {
Expand All @@ -21,7 +22,7 @@ export class App extends React.Component<any, { dateStr: string, syncStatus: Syn

render() {
return (
<div className="App">
<div className={"App"}>
<Navigation onDateChange={this.handleDateChange} syncStatus={this.state.syncStatus}/>
<Notepad dateStr={this.state.dateStr} onChangeStatus={this.handleSyncStatusChange}/>
</div>
Expand Down
36 changes: 36 additions & 0 deletions src/Auth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react";
import { Navigate } from "react-router-dom";
import { AuthInput } from "./Components/AuthInput";
import { Navigation } from "./Components/Navigation";

export class Auth extends React.Component<any, {
isAuthSucceeded: boolean,
}> {
constructor(props: any) {
super(props);
this.state = {
isAuthSucceeded: false,
};
}

render() {
if(this.state.isAuthSucceeded){
return(<Navigate to="/"/>);
}

return (
<div className={"Auth"}>
<Navigation
onDateChange={()=>{}}
syncStatus="OK"
/>
<AuthInput
token={localStorage.getItem('token') ?? ''}
dbId={localStorage.getItem('dbId') ?? ''}
onClosed={() => {
this.setState({isAuthSucceeded:true});
}} />
</div>
);
}
}
4 changes: 4 additions & 0 deletions src/Components/DateSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { AnchorButton, NavbarGroup } from "@blueprintjs/core";
import { DateInput2 } from "@blueprintjs/datetime2";
import { format, parse } from "date-fns";
import React from "react";
import "@blueprintjs/datetime2/lib/css/blueprint-datetime2.css";
import "@blueprintjs/datetime/lib/css/blueprint-datetime.css";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
import "@blueprintjs/select/lib/css/blueprint-select.css";

export class DateSelector extends React.Component<
{ onDateChange: (dateValue: Date) => void },
Expand Down
46 changes: 46 additions & 0 deletions src/Components/MainMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { AnchorButton, Menu, MenuDivider, MenuItem, Position } from "@blueprintjs/core";
import { MenuItem2, PlacementOptions, Popover2 } from "@blueprintjs/popover2";
import React from "react";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";

export class MainMenu extends React.Component<
{
}, {
}> {
constructor(props: any) {
super(props);
this.state = {
};
}

render() {
return (
<Popover2
content={this.getContent()}
placement={"bottom"}
interactionKind="click"
modifiers= {{
arrow: { enabled: true },
flip: { enabled: true },
preventOverflow: { enabled: true },
}}
>
<AnchorButton icon='menu' />
</Popover2>
);
}

getContent() {
return (
<Menu>
<MenuItem2 icon="cog" text="Settings">
<MenuItem2 icon="key" text={"Authentication"} href="/auth"/>
<MenuItem2 icon="settings" text={"Preferenses"} href="/preferenses" disabled/>
</MenuItem2>
<MenuItem2 icon="blank" text="About" href="/about" disabled/>
<MenuDivider />
<MenuItem2 icon="small-cross" text="Exit" onClick={()=>{window.close()}}/>
</Menu>
);
}
}
57 changes: 41 additions & 16 deletions src/Components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,64 @@ import {
} from "@blueprintjs/core";
import { DateSelector } from "./DateSelector";
import { SyncStatus } from "../App";
import { MainMenu } from "./MainMenu";

export class Navigation extends React.Component<{ onDateChange: (dateValue: Date) => void , syncStatus: SyncStatus}> {
export class Navigation extends React.Component<
{
onDateChange: (dateValue: Date) => void,
syncStatus: SyncStatus
},
{
isMenuOpen: boolean,
}> {

constructor(props: any) {
super(props);
this.state = {
isMenuOpen: false,
};
}
render() {
let icon : IconName = 'updated';
let intent : Intent = 'success';
let icon: IconName = 'updated';
let intent: Intent = 'success';
let loading = true;
if(this.props.syncStatus === 'Uploading' || this.props.syncStatus === 'Downloading'){
if (this.props.syncStatus === 'Uploading' || this.props.syncStatus === 'Downloading') {
loading = true;
intent = 'none';
}else if(this.props.syncStatus === 'OK'){
} else if (this.props.syncStatus === 'OK') {
loading = false;
icon = 'updated';
intent = 'success';
}else{
} else {
loading = true;
icon = 'error';
intent = 'danger';
}
return (
<Navbar className={Classes.DARK}>
<NavbarGroup align={Alignment.LEFT}>
<AnchorButton icon='menu' />
<NavbarDivider />
<DateSelector onDateChange={this.handleDateChange}/>
</NavbarGroup>
<NavbarGroup align={Alignment.RIGHT}>
<AnchorButton minimal icon= {icon} loading={loading} intent={intent}/>
</NavbarGroup>
</Navbar>
<div id="navigation">
<Navbar className={Classes.DARK}>
<NavbarGroup align={Alignment.LEFT}>
<MainMenu />
<NavbarDivider />
<DateSelector onDateChange={this.handleDateChange} />
</NavbarGroup>
<NavbarGroup align={Alignment.RIGHT}>
<AnchorButton minimal icon={icon} loading={loading} intent={intent} />
</NavbarGroup>
</Navbar>
</div>
);
}

handleDateChange = (dateValue: Date) => {
this.props.onDateChange(dateValue);
}

handleClickMenuButton = () => {
if(this.state.isMenuOpen){
this.setState({isMenuOpen:false});
}else{
this.setState({isMenuOpen:true});
}
}
};
5 changes: 5 additions & 0 deletions src/Components/Notepad.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#notepadText{
flex-grow: 100;
flex-shrink: 100;
resize: none;
}
20 changes: 5 additions & 15 deletions src/Components/Notepad.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TextArea, NonIdealState, Spinner } from "@blueprintjs/core";
import React from "react";
import { Navigate } from "react-router-dom";
import { SyncStatus } from "../App";
import { NotionHandler } from "../Data/NotionHandler";
import { AuthInput } from "./AuthInput";

import './Notepad.css';
export class Notepad extends React.Component<{
dateStr: string,
onChangeStatus: (syncStatus: SyncStatus) => void,
Expand Down Expand Up @@ -38,27 +38,17 @@ export class Notepad extends React.Component<{
/>);
}

if (!this.state.isConnectivityVerified) {
return (
<AuthInput
token={localStorage.getItem('token') ?? ''}
dbId={localStorage.getItem('dbId') ?? ''}
onClosed={() => {
this.setState({ isConnectivityVerified: true });
this.notionHandler = new NotionHandler(localStorage.getItem('token') ?? '', localStorage.getItem('dbId') ?? '');
this.loadFromNotion(this.props.dateStr);
}}
/>
);
if(!this.state.isConnectivityVerified){
return(<Navigate to="/auth"/>);
}

return (
<TextArea
id="notepadText"
fill
placeholder='Enter some text here...'
onChange={this.handleChange}
className={'mainText'}
style={{ height: "100%" }}
value={this.state.text}
/>
);
Expand Down
13 changes: 9 additions & 4 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import React from "react";
import { Classes } from "@blueprintjs/core";
import ReactDOM from "react-dom/client";
import {
createBrowserRouter,
RouterProvider,
} from "react-router-dom";

import { App } from "./App";
import { Auth } from "./Auth";
import "./style.css";

const router = createBrowserRouter([
{
path: "/",
element: <App />,
element: <App className={Classes.DARK}/>,
},
{
path: "/auth",
element: <Auth className={Classes.DARK}/>,
},
]);

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
//<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>
//</React.StrictMode>
);