mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
feat: suggest TagName on create
This commit is contained in:
parent
6d6bbee015
commit
5d932c7fb8
6 changed files with 75 additions and 16 deletions
|
|
@ -1,9 +1,17 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { take, drop, compact } = require('lodash');
|
const { take, drop, compact } = require('lodash');
|
||||||
|
const { logger } = require('../log');
|
||||||
|
|
||||||
const getMatchPart = tagToMatch => `[!is[system]kin::to[${tagToMatch}]`;
|
const getMatchPart = tagToMatch => `[!is[system]kin::to[${tagToMatch}]`;
|
||||||
const getPathPart = folderToPlace => `addprefix[subwiki/${folderToPlace}/]]`;
|
const getPathPart = folderToPlace => `addprefix[subwiki/${folderToPlace}/]]`;
|
||||||
|
const getTagNameFromMatchPart = matchPart => matchPart.replace('[!is[system]kin::to[', '').replace(/].*/, '');
|
||||||
|
const getFolderNamePathPart = pathPart => pathPart.replace(/.+addprefix\[subwiki\//, '').replace('/]]', '');
|
||||||
|
|
||||||
|
function getFileSystemPathsTiddlerPath(mainWikiPath) {
|
||||||
|
const pluginPath = path.join(mainWikiPath, 'plugins', 'linonetwo', 'sub-wiki');
|
||||||
|
return path.join(pluginPath, 'FileSystemPaths.tid');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update $:/config/FileSystemPaths programmatically to make private tiddlers goto the sub-wiki
|
* update $:/config/FileSystemPaths programmatically to make private tiddlers goto the sub-wiki
|
||||||
|
|
@ -12,8 +20,7 @@ const getPathPart = folderToPlace => `addprefix[subwiki/${folderToPlace}/]]`;
|
||||||
* @param {Object} oldConfig if you need to replace a line, you need to pass-in what old line looks like, so here we can find and replace it
|
* @param {Object} oldConfig if you need to replace a line, you need to pass-in what old line looks like, so here we can find and replace it
|
||||||
*/
|
*/
|
||||||
function updateSubWikiPluginContent(mainWikiPath, newConfig, oldConfig) {
|
function updateSubWikiPluginContent(mainWikiPath, newConfig, oldConfig) {
|
||||||
const pluginPath = path.join(mainWikiPath, 'plugins', 'linonetwo', 'sub-wiki');
|
const FileSystemPathsTiddlerPath = getFileSystemPathsTiddlerPath(mainWikiPath);
|
||||||
const FileSystemPathsTiddlerPath = path.join(pluginPath, 'FileSystemPaths.tid');
|
|
||||||
|
|
||||||
const FileSystemPathsFile = fs.readFileSync(FileSystemPathsTiddlerPath, 'utf-8');
|
const FileSystemPathsFile = fs.readFileSync(FileSystemPathsTiddlerPath, 'utf-8');
|
||||||
let newFileSystemPathsFile = '';
|
let newFileSystemPathsFile = '';
|
||||||
|
|
@ -66,6 +73,23 @@ function updateSubWikiPluginContent(mainWikiPath, newConfig, oldConfig) {
|
||||||
fs.writeFileSync(FileSystemPathsTiddlerPath, newFileSystemPathsFile);
|
fs.writeFileSync(FileSystemPathsTiddlerPath, newFileSystemPathsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getSubWikiPluginContent(mainWikiPath) {
|
||||||
|
if (!mainWikiPath) return [];
|
||||||
|
const FileSystemPathsTiddlerPath = getFileSystemPathsTiddlerPath(mainWikiPath);
|
||||||
|
try {
|
||||||
|
const FileSystemPathsFile = await fs.readFile(FileSystemPathsTiddlerPath, 'utf-8');
|
||||||
|
const FileSystemPaths = compact(drop(FileSystemPathsFile.split('\n'), 3));
|
||||||
|
return FileSystemPaths.map(line => ({
|
||||||
|
tagName: getTagNameFromMatchPart(line),
|
||||||
|
folderName: getFolderNamePathPart(line),
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, { function: 'getSubWikiPluginContent' });
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateSubWikiPluginContent,
|
updateSubWikiPluginContent,
|
||||||
|
getSubWikiPluginContent,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ const { autoUpdater } = require('electron-updater');
|
||||||
|
|
||||||
const { initWikiGit, getRemoteUrl } = require('../libs/git');
|
const { initWikiGit, getRemoteUrl } = require('../libs/git');
|
||||||
const { stopWatchWiki, watchWiki } = require('../libs/wiki/watch-wiki');
|
const { stopWatchWiki, watchWiki } = require('../libs/wiki/watch-wiki');
|
||||||
|
const { getSubWikiPluginContent } = require('../libs/wiki/update-plugin-content');
|
||||||
const { stopWiki, startWiki } = require('../libs/wiki/wiki-worker-mamager');
|
const { stopWiki, startWiki } = require('../libs/wiki/wiki-worker-mamager');
|
||||||
const { logger } = require('../libs/log');
|
const { logger } = require('../libs/log');
|
||||||
const {
|
const {
|
||||||
|
|
@ -123,6 +124,7 @@ const loadListeners = () => {
|
||||||
return String(error);
|
return String(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ipcMain.handle('get-sub-wiki-plugin-content', (event, mainWikiPath) => getSubWikiPluginContent(mainWikiPath));
|
||||||
ipcMain.on('get-constant', (event, name) => {
|
ipcMain.on('get-constant', (event, name) => {
|
||||||
event.returnValue = {
|
event.returnValue = {
|
||||||
ICON_PATH,
|
ICON_PATH,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import FormHelperText from '@material-ui/core/FormHelperText';
|
||||||
import Select from '@material-ui/core/Select';
|
import Select from '@material-ui/core/Select';
|
||||||
import MenuItem from '@material-ui/core/MenuItem';
|
import MenuItem from '@material-ui/core/MenuItem';
|
||||||
import FolderIcon from '@material-ui/icons/Folder';
|
import FolderIcon from '@material-ui/icons/Folder';
|
||||||
|
import Autocomplete from '@material-ui/lab/Autocomplete';
|
||||||
|
|
||||||
import * as actions from '../../state/dialog-add-workspace/actions';
|
import * as actions from '../../state/dialog-add-workspace/actions';
|
||||||
|
|
||||||
|
|
@ -51,6 +52,7 @@ type OwnProps = {|
|
||||||
existedFolderLocation: string,
|
existedFolderLocation: string,
|
||||||
wikiPort: number,
|
wikiPort: number,
|
||||||
wikiPortSetter: number => void,
|
wikiPortSetter: number => void,
|
||||||
|
fileSystemPaths: { tagName: string, folderName: string }[],
|
||||||
isCreateMainWorkspace: boolean,
|
isCreateMainWorkspace: boolean,
|
||||||
|};
|
|};
|
||||||
type DispatchProps = {|
|
type DispatchProps = {|
|
||||||
|
|
@ -79,6 +81,7 @@ function WikiPathForm({
|
||||||
mainWikiToLinkSetter,
|
mainWikiToLinkSetter,
|
||||||
wikiPort,
|
wikiPort,
|
||||||
wikiPortSetter,
|
wikiPortSetter,
|
||||||
|
fileSystemPaths,
|
||||||
isCreateMainWorkspace,
|
isCreateMainWorkspace,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [workspaces, workspacesSetter] = useState({});
|
const [workspaces, workspacesSetter] = useState({});
|
||||||
|
|
@ -139,13 +142,6 @@ function WikiPathForm({
|
||||||
)}
|
)}
|
||||||
{!isCreateMainWorkspace && (
|
{!isCreateMainWorkspace && (
|
||||||
<>
|
<>
|
||||||
<TextField
|
|
||||||
fullWidth
|
|
||||||
onChange={event => tagNameSetter(event.target.value)}
|
|
||||||
label={t('AddWorkspace.TagName')}
|
|
||||||
helperText={t('AddWorkspace.TagNameHelp')}
|
|
||||||
value={tagName}
|
|
||||||
/>
|
|
||||||
<SoftLinkToMainWikiSelectInputLabel id="main-wiki-select-label">
|
<SoftLinkToMainWikiSelectInputLabel id="main-wiki-select-label">
|
||||||
{t('AddWorkspace.MainWorkspaceLocation')}
|
{t('AddWorkspace.MainWorkspaceLocation')}
|
||||||
</SoftLinkToMainWikiSelectInputLabel>
|
</SoftLinkToMainWikiSelectInputLabel>
|
||||||
|
|
@ -178,6 +174,20 @@ function WikiPathForm({
|
||||||
</Typography>
|
</Typography>
|
||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
)}
|
)}
|
||||||
|
<Autocomplete
|
||||||
|
freeSolo
|
||||||
|
options={fileSystemPaths.map(fileSystemPath => fileSystemPath.tagName)}
|
||||||
|
renderInput={parameters => (
|
||||||
|
<TextField
|
||||||
|
{...parameters}
|
||||||
|
onChange={event => tagNameSetter(event.target.value)}
|
||||||
|
value={tagName}
|
||||||
|
fullWidth
|
||||||
|
label={t('AddWorkspace.TagName')}
|
||||||
|
helperText={t('AddWorkspace.TagNameHelp')}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</CreateContainer>
|
</CreateContainer>
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import {
|
||||||
countWorkspace,
|
countWorkspace,
|
||||||
getWorkspaceRemote,
|
getWorkspaceRemote,
|
||||||
requestOpen,
|
requestOpen,
|
||||||
|
getSubWikiPluginContent,
|
||||||
} from '../../senders';
|
} from '../../senders';
|
||||||
|
|
||||||
const graphqlClient = new GraphQLClient({
|
const graphqlClient = new GraphQLClient({
|
||||||
|
|
@ -84,6 +85,13 @@ export default function AddWorkspace() {
|
||||||
}, [userInfo]);
|
}, [userInfo]);
|
||||||
|
|
||||||
const [mainWikiToLink, mainWikiToLinkSetter] = useState({ name: '', port: 0 });
|
const [mainWikiToLink, mainWikiToLinkSetter] = useState({ name: '', port: 0 });
|
||||||
|
const [fileSystemPaths, fileSystemPathsSetter] = useState([]);
|
||||||
|
useEffect(() => {
|
||||||
|
// eslint-disable-next-line promise/catch-or-return
|
||||||
|
getSubWikiPluginContent(mainWikiToLink.name).then(fileSystemPathsSetter);
|
||||||
|
}, [mainWikiToLink]);
|
||||||
|
// DEBUG: console
|
||||||
|
console.log(`fileSystemPaths`, fileSystemPaths);
|
||||||
const [githubWikiUrl, githubWikiUrlSetter] = useState<string>('');
|
const [githubWikiUrl, githubWikiUrlSetter] = useState<string>('');
|
||||||
const [tagName, tagNameSetter] = useState<string>('');
|
const [tagName, tagNameSetter] = useState<string>('');
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -168,6 +176,7 @@ export default function AddWorkspace() {
|
||||||
mainWikiToLinkSetter={mainWikiToLinkSetter}
|
mainWikiToLinkSetter={mainWikiToLinkSetter}
|
||||||
wikiPort={wikiPort}
|
wikiPort={wikiPort}
|
||||||
wikiPortSetter={wikiPortSetter}
|
wikiPortSetter={wikiPortSetter}
|
||||||
|
fileSystemPaths={fileSystemPaths}
|
||||||
isCreateMainWorkspace={isCreateMainWorkspace}
|
isCreateMainWorkspace={isCreateMainWorkspace}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
@ -196,6 +205,7 @@ export default function AddWorkspace() {
|
||||||
mainWikiToLinkSetter={mainWikiToLinkSetter}
|
mainWikiToLinkSetter={mainWikiToLinkSetter}
|
||||||
wikiPort={wikiPort}
|
wikiPort={wikiPort}
|
||||||
wikiPortSetter={wikiPortSetter}
|
wikiPortSetter={wikiPortSetter}
|
||||||
|
fileSystemPaths={fileSystemPaths}
|
||||||
isCreateMainWorkspace={isCreateMainWorkspace}
|
isCreateMainWorkspace={isCreateMainWorkspace}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
@ -223,6 +233,7 @@ export default function AddWorkspace() {
|
||||||
mainWikiToLinkSetter={mainWikiToLinkSetter}
|
mainWikiToLinkSetter={mainWikiToLinkSetter}
|
||||||
wikiPort={wikiPort}
|
wikiPort={wikiPort}
|
||||||
wikiPortSetter={wikiPortSetter}
|
wikiPortSetter={wikiPortSetter}
|
||||||
|
fileSystemPaths={fileSystemPaths}
|
||||||
isCreateMainWorkspace={isCreateMainWorkspace}
|
isCreateMainWorkspace={isCreateMainWorkspace}
|
||||||
/>
|
/>
|
||||||
<CloneWikiDoneButton
|
<CloneWikiDoneButton
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import FormHelperText from '@material-ui/core/FormHelperText';
|
||||||
import Select from '@material-ui/core/Select';
|
import Select from '@material-ui/core/Select';
|
||||||
import MenuItem from '@material-ui/core/MenuItem';
|
import MenuItem from '@material-ui/core/MenuItem';
|
||||||
import FolderIcon from '@material-ui/icons/Folder';
|
import FolderIcon from '@material-ui/icons/Folder';
|
||||||
|
import Autocomplete from '@material-ui/lab/Autocomplete';
|
||||||
|
|
||||||
import * as actions from '../../state/dialog-add-workspace/actions';
|
import * as actions from '../../state/dialog-add-workspace/actions';
|
||||||
|
|
||||||
|
|
@ -50,6 +51,7 @@ type OwnProps = {|
|
||||||
parentFolderLocation: string,
|
parentFolderLocation: string,
|
||||||
wikiPort: number,
|
wikiPort: number,
|
||||||
wikiPortSetter: number => void,
|
wikiPortSetter: number => void,
|
||||||
|
fileSystemPaths: { tagName: string, folderName: string }[],
|
||||||
isCreateMainWorkspace: boolean,
|
isCreateMainWorkspace: boolean,
|
||||||
|};
|
|};
|
||||||
type DispatchProps = {|
|
type DispatchProps = {|
|
||||||
|
|
@ -73,6 +75,7 @@ function NewWikiPathForm({
|
||||||
mainWikiToLinkSetter,
|
mainWikiToLinkSetter,
|
||||||
wikiPort,
|
wikiPort,
|
||||||
wikiPortSetter,
|
wikiPortSetter,
|
||||||
|
fileSystemPaths,
|
||||||
isCreateMainWorkspace,
|
isCreateMainWorkspace,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [workspaces, workspacesSetter] = useState({});
|
const [workspaces, workspacesSetter] = useState({});
|
||||||
|
|
@ -143,13 +146,6 @@ function NewWikiPathForm({
|
||||||
)}
|
)}
|
||||||
{!isCreateMainWorkspace && (
|
{!isCreateMainWorkspace && (
|
||||||
<>
|
<>
|
||||||
<TextField
|
|
||||||
fullWidth
|
|
||||||
onChange={event => tagNameSetter(event.target.value)}
|
|
||||||
label={t('AddWorkspace.TagName')}
|
|
||||||
helperText={t('AddWorkspace.TagNameHelp')}
|
|
||||||
value={tagName}
|
|
||||||
/>
|
|
||||||
<SoftLinkToMainWikiSelectInputLabel id="main-wiki-select-label">
|
<SoftLinkToMainWikiSelectInputLabel id="main-wiki-select-label">
|
||||||
{t('AddWorkspace.MainWorkspaceLocation')}
|
{t('AddWorkspace.MainWorkspaceLocation')}
|
||||||
</SoftLinkToMainWikiSelectInputLabel>
|
</SoftLinkToMainWikiSelectInputLabel>
|
||||||
|
|
@ -182,6 +178,20 @@ function NewWikiPathForm({
|
||||||
</Typography>
|
</Typography>
|
||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
)}
|
)}
|
||||||
|
<Autocomplete
|
||||||
|
freeSolo
|
||||||
|
options={fileSystemPaths.map(fileSystemPath => fileSystemPath.tagName)}
|
||||||
|
renderInput={parameters => (
|
||||||
|
<TextField
|
||||||
|
{...parameters}
|
||||||
|
onChange={event => tagNameSetter(event.target.value)}
|
||||||
|
value={tagName}
|
||||||
|
fullWidth
|
||||||
|
label={t('AddWorkspace.TagName')}
|
||||||
|
helperText={t('AddWorkspace.TagNameHelp')}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</CreateContainer>
|
</CreateContainer>
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ export const requestCloneSubWiki = (
|
||||||
userInfo,
|
userInfo,
|
||||||
tagName,
|
tagName,
|
||||||
);
|
);
|
||||||
|
export const getSubWikiPluginContent = (mainWikiPath: string): Promise<{ tagName: string, folderName: string }[]> =>
|
||||||
|
ipcRenderer.invoke('get-sub-wiki-plugin-content', mainWikiPath);
|
||||||
export const requestOpen = (uri: string, isDirectory?: boolean) => ipcRenderer.send('request-open', uri, !!isDirectory);
|
export const requestOpen = (uri: string, isDirectory?: boolean) => ipcRenderer.send('request-open', uri, !!isDirectory);
|
||||||
export const requestShowMessageBox = (message: string, type: string) =>
|
export const requestShowMessageBox = (message: string, type: string) =>
|
||||||
ipcRenderer.send('request-show-message-box', message, type);
|
ipcRenderer.send('request-show-message-box', message, type);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue