Skip to content

Commit

Permalink
Rough tree structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Sep 14, 2020
1 parent 9652a77 commit 25b0939
Show file tree
Hide file tree
Showing 25 changed files with 1,332 additions and 2,872 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_size = 2
indent_style = space
insert_final_newline = false
max_line_length = 120
tab_width = 4
tab_width = 2

[*.sass]
indent_size = 2
Expand Down
23 changes: 16 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ReTypeTron App</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet"
/>
<style>
html, body, #root {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
html,
body,
#root {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}

.bp3-button {
outline: none;
}
</style>
</head>
<body>
Expand Down
23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
"@atlaskit/smart-card": "^14.3.0",
"@atlaskit/spinner": "^15.0.3",
"@atlaskit/tree": "^8.1.1",
"@blueprintjs/core": "^3.31.0",
"@blueprintjs/icons": "^3.20.1",
"@emotion/core": "^10.0.35",
"@emotion/css": "^10.0.27",
"@types/cxs": "^6.2.1",
"@types/palx": "^1.0.1",
"@types/color": "^3.0.1",
"color": "^3.1.2",
"cxs": "^6.2.0",
"palx": "^1.0.3",
Expand All @@ -47,27 +48,43 @@
"react-router-dom": "^5.2.0",
"remirror": "^0.13.1",
"rxjs-compat": "^6.6.3",
"sancho": "^3.5.6",
"styled-components": "3.4.6"
},
"devDependencies": {
"@types/cxs": "^6.2.1",
"@types/node": "^14.6.4",
"@types/palx": "^1.0.1",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"@types/webpack": "^4.41.22",
"@types/webpack-dev-server": "^3.11.0",
"concurrently": "^5.3.0",
"cross-env": "^7.0.2",
"css-loader": "^4.3.0",
"electron": "^10.1.1",
"electron-builder": "^22.8.0",
"file-loader": "^6.1.0",
"html-webpack-plugin": "^4.4.1",
"nodemon": "^2.0.4",
"prettier": "^2.1.1",
"style-loader": "^1.2.1",
"ts-loader": "^8.0.3",
"ts-node": "^9.0.0",
"typescript": "^4.0.2",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"resolutions": {
"react-spring": "9.0.0-beta.34",
"@react-spring/core": "9.0.0-beta.33",
"@react-spring/native": "9.0.0-beta.33",
"@react-spring/web": "9.0.0-beta.34",
"@react-spring/addons": "9.0.0-beta.33",
"@react-spring/konva": "9.0.0-beta.33",
"@react-spring/three": "9.0.0-beta.33",
"@react-spring/zdog": "9.0.0-beta.33",
"@react-spring/animated": "9.0.0-beta.33",
"@react-spring/shared": "9.0.0-beta.33"
}
}
98 changes: 54 additions & 44 deletions src/appdata/AppDataProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,70 +1,80 @@
import * as React from 'react';
import { useContext, useState } from 'react';
import { AppData } from '../types';
import { app } from "electron";
import path from "path";
import { AppData, WorkSpace } from '../types';
import { remote } from 'electron';
import path from 'path';
import { useAsyncEffect } from '../utils';
import * as fsLib from 'fs';
import { LocalFileSystemDataSource } from '../datasource/LocalFileSystemDataSource';

const fs = fsLib.promises;

const userDataFolder = app.getPath('userData');
const userDataFolder = path.join(remote.app.getPath('appData'), 'yana');
const appDataFile = path.join(userDataFolder, 'workspaces.json');

console.log('AppDataFile located at', appDataFile);

interface AppDataContextValue extends AppData {
createWorkSpace: (name: string, path: string) => Promise<void>;
createWorkSpace: (name: string, path: string) => Promise<void>;
setWorkSpace: (workspace: WorkSpace) => void;
currentWorkspace: WorkSpace;
}

export const AppDataContext = React.createContext<AppDataContextValue>(null as any);

export const useAppData = () => useContext(AppDataContext);

export const AppDataProvider: React.FC = props => {
const [appData, setAppData] = useState<AppData>({ workspaces: [] });
const [appData, setAppData] = useState<AppData>({ workspaces: [] });
const [currentWorkspace, setCurrentWorkspace] = useState<WorkSpace>(appData.workspaces[0]);

useAsyncEffect(async () => {
if (!fsLib.existsSync(userDataFolder)) {
await fs.mkdir(userDataFolder);
}
useAsyncEffect(async () => {
if (!fsLib.existsSync(userDataFolder)) {
fsLib.mkdirSync(userDataFolder);
}

let appData: AppData = {
workspaces: []
};
let appData: AppData = {
workspaces: [],
};

if (!fsLib.existsSync(appDataFile)) {
await fs.writeFile(appDataFile, JSON.stringify(appData));
} else {
appData = JSON.parse(await fs.readFile(appDataFile, { encoding: 'utf8' }));
}
if (!fsLib.existsSync(appDataFile)) {
fsLib.writeFileSync(appDataFile, JSON.stringify(appData));
} else {
appData = JSON.parse(fsLib.readFileSync(appDataFile, { encoding: 'utf8' }));
}

setAppData(appData);
}, [])
setAppData(appData);
setCurrentWorkspace(appData.workspaces[0]);
}, []);

return (
<AppDataContext.Provider value={{
return (
<AppDataContext.Provider
value={{
...appData,
currentWorkspace: currentWorkspace,
setWorkSpace: setCurrentWorkspace,
createWorkSpace: async (name, path) => {
const newAppData: AppData = {
...appData,
createWorkSpace: async (name, path) => {
const newAppData: AppData = {
...appData,
workspaces: [
...appData.workspaces,
{
name,
dataSourceType: 'fs',
dataSourceOptions: {
sourcePath: path
}
}
]
}
workspaces: [
...appData.workspaces,
{
name,
dataSourceType: 'fs',
dataSourceOptions: {
sourcePath: path,
},
},
],
};

await LocalFileSystemDataSource.init({ sourcePath: path });
await fs.writeFile(appDataFile, JSON.stringify(newAppData));
setAppData(newAppData);
}
}}>
{ props.children }
</AppDataContext.Provider>
);
await LocalFileSystemDataSource.init({ sourcePath: path });
fsLib.writeFileSync(appDataFile, JSON.stringify(newAppData));
setAppData(newAppData);
},
}}
>
{props.children}
</AppDataContext.Provider>
);
};
36 changes: 18 additions & 18 deletions src/appdata/AppDataService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from "electron";
import { app } from 'electron';
import * as fsLib from 'fs';
import * as path from 'path';
import { AppData } from '../types';
Expand All @@ -11,8 +11,7 @@ const APPDATA_FILE = 'workspaces.json';
export class AppDataService {
appData!: AppData;

constructor() {
}
constructor() {}

private getAppDataFile() {
const userDataFolder = app.getPath('userData');
Expand All @@ -28,7 +27,7 @@ export class AppDataService {
const appDataFile = this.getAppDataFile();

let appData: AppData = {
workspaces: []
workspaces: [],
};

if (!fsLib.existsSync(appDataFile)) {
Expand All @@ -40,18 +39,19 @@ export class AppDataService {
this.appData = appData;
}

public async createWorkSpace(name: string, path: string) { // TODO kind
const appDataFile = this.getAppDataFile();

this.appData.workspaces.push({
name,
dataSourceType: 'fs',
dataSourceOptions: {
sourcePath: path
}
});

await fs.writeFile(appDataFile, JSON.stringify(this.appData));
await LocalFileSystemDataSource.init({ sourcePath: path });
}
// public async createWorkSpace(name: string, path: string) {
// // TODO kind
// const appDataFile = this.getAppDataFile();
//
// this.appData.workspaces.push({
// name,
// dataSourceType: 'fs',
// dataSourceOptions: {
// sourcePath: path,
// },
// });
//
// await fs.writeFile(appDataFile, JSON.stringify(this.appData));
// await LocalFileSystemDataSource.init({ sourcePath: path });
// }
}
4 changes: 2 additions & 2 deletions src/colors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const Colors = {
primary: '#2c3e50'
}
primary: '#2c3e50',
};
2 changes: 1 addition & 1 deletion src/common/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class EventEmitter<EventPayload extends object> {
public on(handler: (payload: EventPayload) => any): number {
this.handlers.push(handler);
return this.handlerCount++;
};
}

public delete(handlerId: number) {
this.handlers[handlerId] = null;
Expand Down
Loading

0 comments on commit 25b0939

Please sign in to comment.