Skip to content

Commit

Permalink
repl replace with new, add default save path
Browse files Browse the repository at this point in the history
  • Loading branch information
nanqic committed Jan 28, 2024
1 parent 431f345 commit 155a349
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/components/Nav.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { useState, useEffect, lazy } from 'react'
import { Link, useLocation } from 'wouter'
import { getToken } from '../utils';
import { useParams } from 'wouter'

const FileTree = lazy(() => import("@/components/FileTree"))

export default function
({ state, setContent }) {
const [theme, setTheme] = useState()
const [, setLocation] = useLocation();
const params = useParams();

useEffect(() => {

Expand Down Expand Up @@ -49,7 +52,7 @@ export default function
})
}
</select>}
<Link href={`${import.meta.env.VITE_BASE_URL}/repl`} className='pl-3' title='新建'>
<Link href={`${import.meta.env.VITE_BASE_URL}/new?path=/${params.foldername || ''}/${!params.dir || params.dir?.endsWith('.md') ? '' : params.dir + '/'}`} className='pl-3' title='新建'>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4" />
Expand Down
15 changes: 9 additions & 6 deletions src/components/TextEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'
import { useLocation } from 'wouter';
import { useLocation, useSearch } from 'wouter';
import { saveEdit } from '../utils'
import { useNotification } from '../components/NotificationContext';
import "@uiw/react-md-editor/markdown-editor.css";
Expand All @@ -22,6 +22,7 @@ MDEditor,
export default function TextEdit({ content, setContent, setEditing }) {
const [value, setValue] = useState(content || localStorage.getItem("raw-content"))
const [, setLocation] = useLocation()
const searchString = useSearch()
useEffect(() => {
// Use a separate useEffect to handle the debouncedValue change
const timer = setTimeout(() => {
Expand All @@ -41,15 +42,17 @@ export default function TextEdit({ content, setContent, setEditing }) {

const handleSave = async () => {
let title, res, userInput;
const re = /(?<=(#|-) )\S{1,32}/
title = content.match(re).shift()

if (location.pathname.endsWith('/repl')) {
const re = /(?<=(#|-) )\S{1,32}/
title = content.match(re).shift()
userInput = window.prompt("确认保存", `${title}`)
} else if (location.pathname.endsWith('/new')) {
title = decodeURI(location.pathname.replace(import.meta.env.VITE_BASE_URL, '').slice(0, -4)) + searchString.slice(5) + title
userInput = window.prompt("确认保存('/'前为保存路径)", `${title}`)
} else {
title = decodeURI(location.pathname.replace(import.meta.env.VITE_BASE_URL, '').slice(0, -3))
userInput = window.prompt("确认保存('/'中间为目录)", `${title}`)

userInput = window.prompt("确认保存('/'前为保存路径)", `${title}`)
}

if (userInput === null || userInput.trim() === "") {
Expand Down Expand Up @@ -82,7 +85,7 @@ export default function TextEdit({ content, setContent, setEditing }) {
buttonProps: { "title": "new line" },
icon: (
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m0 4a.5.5 0 0 1 .5-.5h9a2.5 2.5 0 0 1 0 5h-1.293l.647.646a.5.5 0 0 1-.708.708l-1.5-1.5a.5.5 0 0 1 0-.708l1.5-1.5a.5.5 0 0 1 .708.708l-.647.646H11.5a1.5 1.5 0 0 0 0-3h-9a.5.5 0 0 1-.5-.5m0 4a.5.5 0 0 1 .5-.5H7a.5.5 0 0 1 0 1H2.5a.5.5 0 0 1-.5-.5" />
<path fillRule="evenodd" d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m0 4a.5.5 0 0 1 .5-.5h9a2.5 2.5 0 0 1 0 5h-1.293l.647.646a.5.5 0 0 1-.708.708l-1.5-1.5a.5.5 0 0 1 0-.708l1.5-1.5a.5.5 0 0 1 .708.708l-.647.646H11.5a1.5 1.5 0 0 0 0-3h-9a.5.5 0 0 1-.5-.5m0 4a.5.5 0 0 1 .5-.5H7a.5.5 0 0 1 0 1H2.5a.5.5 0 0 1-.5-.5" />
</svg>
),
execute: (state, api) => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function Home() {
return (
<>
<Switch>
<Route path={`${import.meta.env.VITE_BASE_URL}/new`} component={Repl} />
<Route path={`${import.meta.env.VITE_BASE_URL}/repl`} component={Repl} />
<Route path={`${import.meta.env.VITE_BASE_URL}/:foldername?/:dir?/:filename?`} component={MarkmapLoader} />
</Switch>
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const initMarkmapOptions = (mm, root, level) => {
}

if (!root.content) {
root.content = `<strong>${decodeURI(location.pathname.split('/').pop().replace(/(.md|repl)$/, ''))}</strong>`;
root.content = `<strong>${decodeURI(location.pathname.split('/').pop().replace(/(.md|repl|new)$/, ''))}</strong>`;
} else {
root.content = `<strong>${root.content}</strong>`;

Expand Down

0 comments on commit 155a349

Please sign in to comment.