mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-02 12:00:45 -08:00
fix: now showing error message
This commit is contained in:
parent
04f4991948
commit
e89b904c85
8 changed files with 54 additions and 34 deletions
|
|
@ -5,15 +5,17 @@ const REACT_PATH = isDev
|
|||
? 'http://localhost:3000'
|
||||
: `file://${path.resolve(__dirname, '..', '..', 'build', 'index.html')}`;
|
||||
// .app/Contents/Resources/wiki/
|
||||
const TIDDLYWIKI_FOLDER_PATH = isDev
|
||||
const TIDDLYWIKI_TEMPLATE_FOLDER_PATH = isDev
|
||||
? path.resolve(__dirname, '..', '..', 'template', 'wiki')
|
||||
: path.resolve(process.resourcesPath, '..', 'wiki');
|
||||
const TIDDLERS_PATH = 'tiddlers'
|
||||
const ICON_PATH = isDev
|
||||
? path.resolve(__dirname, '..', 'icon.png')
|
||||
: `file://${path.resolve(__dirname, '..', 'icon.png')}`;
|
||||
|
||||
module.exports = {
|
||||
REACT_PATH,
|
||||
TIDDLYWIKI_FOLDER_PATH,
|
||||
TIDDLYWIKI_TEMPLATE_FOLDER_PATH,
|
||||
TIDDLERS_PATH,
|
||||
ICON_PATH,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,32 +1,45 @@
|
|||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const { TIDDLYWIKI_FOLDER_PATH } = require('../constants/paths');
|
||||
const { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } = require('../constants/paths');
|
||||
|
||||
async function createWiki(newFolderPath, folderName) {
|
||||
const newWikiPath = path.join(newFolderPath, folderName);
|
||||
if (!(await fs.pathExists(newFolderPath))) {
|
||||
throw new Error(`该目录不存在 "${newFolderPath}"`);
|
||||
}
|
||||
if (!(await fs.pathExists(TIDDLYWIKI_FOLDER_PATH))) {
|
||||
throw new Error(`Wiki模板缺失 "${TIDDLYWIKI_FOLDER_PATH}"`);
|
||||
if (!(await fs.pathExists(TIDDLYWIKI_TEMPLATE_FOLDER_PATH))) {
|
||||
throw new Error(`Wiki模板缺失 "${TIDDLYWIKI_TEMPLATE_FOLDER_PATH}"`);
|
||||
}
|
||||
if (await fs.pathExists(newWikiPath)) {
|
||||
throw new Error(`Wiki已经存在于该位置 "${newWikiPath}"`);
|
||||
}
|
||||
// Start copying wiki template to destination
|
||||
await fs.copy(TIDDLYWIKI_FOLDER_PATH, newWikiPath);
|
||||
try {
|
||||
await fs.copy(TIDDLYWIKI_TEMPLATE_FOLDER_PATH, newWikiPath);
|
||||
} catch {
|
||||
throw new Error(`无法在该处创建文件夹 "${newWikiPath}"`);
|
||||
}
|
||||
}
|
||||
|
||||
async function createSubWiki(newFolderPath, folderName, mainWikiToLink) {
|
||||
const newWikiPath = path.join(newFolderPath, folderName);
|
||||
const mainWikiTiddlersFolderPath = path.join(mainWikiToLink, TIDDLERS_PATH, folderName);
|
||||
if (!(await fs.pathExists(newFolderPath))) {
|
||||
throw new Error(`该目录不存在 "${newFolderPath}"`);
|
||||
}
|
||||
if (await fs.pathExists(newWikiPath)) {
|
||||
throw new Error(`Wiki已经存在于该位置 "${newWikiPath}"`);
|
||||
}
|
||||
await fs.mkdirs(path.join(newFolderPath, folderName));
|
||||
try {
|
||||
await fs.mkdirs(newWikiPath);
|
||||
} catch {
|
||||
throw new Error(`无法在该处创建文件夹 "${newWikiPath}"`);
|
||||
}
|
||||
try {
|
||||
await fs.createSymlink(newWikiPath, mainWikiTiddlersFolderPath);
|
||||
} catch {
|
||||
throw new Error(`无法链接文件夹 "${newWikiPath}" 到 "${mainWikiTiddlersFolderPath}"`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { createWiki, createSubWiki };
|
||||
|
|
|
|||
|
|
@ -59,8 +59,6 @@ const loadListeners = () => {
|
|||
ipcMain.handle('copy-wiki-template', async (event, newFolderPath, folderName) => {
|
||||
try {
|
||||
await createWiki(newFolderPath, folderName);
|
||||
// eslint-disable-next-line sonarjs/no-duplicate-string
|
||||
return true;
|
||||
} catch (error) {
|
||||
return String(error);
|
||||
}
|
||||
|
|
@ -68,7 +66,6 @@ const loadListeners = () => {
|
|||
ipcMain.handle('create-sub-wiki', async (event, newFolderPath, folderName, mainWikiToLink) => {
|
||||
try {
|
||||
await createSubWiki(newFolderPath, folderName, mainWikiToLink);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return String(error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import FolderIcon from '@material-ui/icons/Folder';
|
|||
import GithubIcon from '@material-ui/icons/GitHub';
|
||||
|
||||
import connectComponent from '../../helpers/connect-component';
|
||||
import { updateForm, save, wikiCreationResult } from '../../state/dialog-add-workspace/actions';
|
||||
import { updateForm, save, setWikiCreationMessage } from '../../state/dialog-add-workspace/actions';
|
||||
|
||||
import {
|
||||
requestCopyWikiTemplate,
|
||||
|
|
@ -64,7 +64,7 @@ const SoftLinkToMainWikiSelectInputLabel = styled(InputLabel)`
|
|||
margin-top: 5px;
|
||||
`;
|
||||
|
||||
function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onWikiCreationResult }) {
|
||||
function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onSetWikiCreationMessage }) {
|
||||
const [isCreateMainWorkspace, isCreateMainWorkspaceSetter] = useState(countWorkspace() === 0);
|
||||
const [parentFolderLocation, parentFolderLocationSetter] = useState('');
|
||||
const [wikiFolderLocation, wikiFolderLocationSetter] = useState('');
|
||||
|
|
@ -134,13 +134,21 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onWikiCreatio
|
|||
error={wikiCreationMessage}
|
||||
helperText={wikiCreationMessage}
|
||||
fullWidth
|
||||
onChange={event => parentFolderLocationSetter(event.target.value)}
|
||||
onChange={event => {
|
||||
parentFolderLocationSetter(event.target.value);
|
||||
onSetWikiCreationMessage('');
|
||||
}}
|
||||
label="知识库的父文件夹"
|
||||
value={parentFolderLocation}
|
||||
/>
|
||||
<LocationPickerInput
|
||||
error={wikiCreationMessage}
|
||||
helperText={wikiCreationMessage}
|
||||
fullWidth
|
||||
onChange={event => wikiFolderNameSetter(event.target.value)}
|
||||
onChange={event => {
|
||||
wikiFolderNameSetter(event.target.value);
|
||||
onSetWikiCreationMessage('');
|
||||
}}
|
||||
label="知识库文件夹名"
|
||||
value={wikiFolderName}
|
||||
/>
|
||||
|
|
@ -197,11 +205,11 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onWikiCreatio
|
|||
disabled={!parentFolderLocation}
|
||||
onClick={async () => {
|
||||
onUpdateForm(workspaceFormData);
|
||||
const creationResult = await requestCopyWikiTemplate(parentFolderLocation, wikiFolderName);
|
||||
if (creationResult) {
|
||||
onSave();
|
||||
const creationError = await requestCopyWikiTemplate(parentFolderLocation, wikiFolderName);
|
||||
if (creationError) {
|
||||
onSetWikiCreationMessage(creationError);
|
||||
} else {
|
||||
onWikiCreationResult(creationResult);
|
||||
onSave();
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
|
@ -232,11 +240,11 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onWikiCreatio
|
|||
disabled={!parentFolderLocation || !mainWikiToLink}
|
||||
onClick={async () => {
|
||||
onUpdateForm(workspaceFormData);
|
||||
const creationResult = await requestCreateSubWiki(parentFolderLocation, wikiFolderName, mainWikiToLink);
|
||||
if (creationResult) {
|
||||
onSave();
|
||||
const creationError = await requestCreateSubWiki(parentFolderLocation, wikiFolderName, mainWikiToLink);
|
||||
if (creationError) {
|
||||
onSetWikiCreationMessage(creationError);
|
||||
} else {
|
||||
onWikiCreationResult(creationResult);
|
||||
onSave();
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
|
@ -276,7 +284,7 @@ AddWorkspace.propTypes = {
|
|||
wikiCreationMessage: PropTypes.string,
|
||||
onUpdateForm: PropTypes.func.isRequired,
|
||||
onSave: PropTypes.func.isRequired,
|
||||
onWikiCreationResult: PropTypes.func.isRequired,
|
||||
onSetWikiCreationMessage: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
|
|
@ -286,7 +294,7 @@ const mapStateToProps = state => ({
|
|||
const actionCreators = {
|
||||
updateForm,
|
||||
save,
|
||||
wikiCreationResult,
|
||||
setWikiCreationMessage,
|
||||
};
|
||||
|
||||
export default connectComponent(AddWorkspace, mapStateToProps, actionCreators);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export const ABOUT_CLOSE = 'ABOUT_CLOSE';
|
|||
export const ABOUT_OPEN = 'ABOUT_OPEN';
|
||||
|
||||
// Add Workspace
|
||||
export const ADD_WORKSPACE_CREATE_WIKI_RESULT = 'ADD_WORKSPACE_CREATE_WIKI_RESULT';
|
||||
export const ADD_WORKSPACE_CREATE_WIKI_MESSAGE = 'ADD_WORKSPACE_CREATE_WIKI_MESSAGE';
|
||||
export const ADD_WORKSPACE_GET_FAILED = 'ADD_WORKSPACE_GET_FAILED';
|
||||
export const ADD_WORKSPACE_GET_REQUEST = 'ADD_WORKSPACE_GET_REQUEST';
|
||||
export const ADD_WORKSPACE_GET_SUCCESS = 'ADD_WORKSPACE_GET_SUCCESS';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { wikiCreationResult } from '../state/dialog-add-workspace/actions';
|
||||
import { setWikiCreationMessage } from '../state/dialog-add-workspace/actions';
|
||||
import { setPreference } from '../state/preferences/actions';
|
||||
import { setSystemPreference } from '../state/system-preferences/actions';
|
||||
import { setWorkspace, setWorkspaces } from '../state/workspaces/actions';
|
||||
|
|
@ -29,7 +29,7 @@ const loadListeners = (store) => {
|
|||
}
|
||||
|
||||
ipcRenderer.on('create-wiki-result', (event, message) => {
|
||||
store.dispatch(wikiCreationResult(message));
|
||||
store.dispatch(setWikiCreationMessage(message));
|
||||
});
|
||||
|
||||
ipcRenderer.on('log', (e, message) => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import algoliasearch from 'algoliasearch';
|
||||
|
||||
import {
|
||||
ADD_WORKSPACE_CREATE_WIKI_RESULT,
|
||||
ADD_WORKSPACE_CREATE_WIKI_MESSAGE,
|
||||
ADD_WORKSPACE_GET_FAILED,
|
||||
ADD_WORKSPACE_GET_REQUEST,
|
||||
ADD_WORKSPACE_GET_SUCCESS,
|
||||
|
|
@ -24,9 +24,9 @@ import { requestCreateWorkspace } from '../../senders';
|
|||
const client = algoliasearch('OQ55YRVMNP', 'fc0fb115b113c21d58ed6a4b4de1565f');
|
||||
const index = client.initIndex('apps');
|
||||
|
||||
export const wikiCreationResult = resultMessage => ({
|
||||
type: ADD_WORKSPACE_CREATE_WIKI_RESULT,
|
||||
value: resultMessage,
|
||||
export const setWikiCreationMessage = message => ({
|
||||
type: ADD_WORKSPACE_CREATE_WIKI_MESSAGE,
|
||||
value: message,
|
||||
});
|
||||
|
||||
export const saveCreatedWiki = () => (dispatch, getState) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { combineReducers } from 'redux';
|
||||
|
||||
import {
|
||||
ADD_WORKSPACE_CREATE_WIKI_RESULT,
|
||||
ADD_WORKSPACE_CREATE_WIKI_MESSAGE,
|
||||
ADD_WORKSPACE_GET_FAILED,
|
||||
ADD_WORKSPACE_GET_REQUEST,
|
||||
ADD_WORKSPACE_GET_SUCCESS,
|
||||
|
|
@ -16,7 +16,7 @@ import {
|
|||
|
||||
const wikiCreationMessage = (state = '', action) => {
|
||||
switch (action.type) {
|
||||
case ADD_WORKSPACE_CREATE_WIKI_RESULT:
|
||||
case ADD_WORKSPACE_CREATE_WIKI_MESSAGE:
|
||||
return action.value;
|
||||
default:
|
||||
return state;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue