fix: changing from one to another non-existing page
This commit is contained in:
parent
6d9cff3c19
commit
d076899045
2 changed files with 14 additions and 6 deletions
|
@ -57,13 +57,21 @@ onMounted(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
figlet.setInputElement(textArea.value)
|
figlet.setInputElement(textArea.value)
|
||||||
const { addText, addLine, clear, footerLinks, setFooter } = useTerminal(textArea.value, commands.value, pages)
|
|
||||||
|
|
||||||
watch(page, () => {
|
function handlePageChange() {
|
||||||
const { title, headerArt, content, uris } = getCurrentPage(page.value.title)
|
const { title, headerArt, content, uris } = getCurrentPage(page.value.title)
|
||||||
addText(`${headerArt}\n${title}\n\n${content}`)
|
addText(`${headerArt}\n${title}\n\n${content}`)
|
||||||
setFooter(uris)
|
setFooter(uris)
|
||||||
}, { immediate: true })
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
addText,
|
||||||
|
addLine,
|
||||||
|
clear,
|
||||||
|
footerLinks,
|
||||||
|
setFooter
|
||||||
|
} = useTerminal(textArea.value, commands.value, pages, handlePageChange)
|
||||||
|
handlePageChange()
|
||||||
|
|
||||||
watch(footerLinks, () => {
|
watch(footerLinks, () => {
|
||||||
footer.value = footerLinks.value
|
footer.value = footerLinks.value
|
||||||
|
|
|
@ -8,7 +8,7 @@ type VitePressPage = {
|
||||||
url: string
|
url: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function useTerminal(inputEl: HTMLTextAreaElement, commands: SimpleCommand[], pages: VitePressPage[]) {
|
export default function useTerminal(inputEl: HTMLTextAreaElement, commands: SimpleCommand[], pages: VitePressPage[], pageChangeCallback: () => void) {
|
||||||
const prompt = '\n$> '
|
const prompt = '\n$> '
|
||||||
const footerLinks = ref<Uri[]>([])
|
const footerLinks = ref<Uri[]>([])
|
||||||
|
|
||||||
|
@ -88,7 +88,6 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFooter(uris: Uri[]) {
|
function setFooter(uris: Uri[]) {
|
||||||
console.log('setting footer links', uris)
|
|
||||||
footerLinks.value = uris
|
footerLinks.value = uris
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +132,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
||||||
|
|
||||||
async function openPage(page: string) {
|
async function openPage(page: string) {
|
||||||
await router.go(page)
|
await router.go(page)
|
||||||
|
if (pageChangeCallback) pageChangeCallback(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCurrentCommand() {
|
function handleCurrentCommand() {
|
||||||
|
@ -162,7 +162,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
||||||
case 'open':
|
case 'open':
|
||||||
addText('\n', false)
|
addText('\n', false)
|
||||||
if (!args.length) addText('USAGE: go page_name')
|
if (!args.length) addText('USAGE: go page_name')
|
||||||
else router.go(args[0])
|
else openPage(args[0])
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
execUserCommand(cmd)
|
execUserCommand(cmd)
|
||||||
|
|
Loading…
Add table
Reference in a new issue