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)
|
||||
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)
|
||||
addText(`${headerArt}\n${title}\n\n${content}`)
|
||||
setFooter(uris)
|
||||
}, { immediate: true })
|
||||
}
|
||||
|
||||
const {
|
||||
addText,
|
||||
addLine,
|
||||
clear,
|
||||
footerLinks,
|
||||
setFooter
|
||||
} = useTerminal(textArea.value, commands.value, pages, handlePageChange)
|
||||
handlePageChange()
|
||||
|
||||
watch(footerLinks, () => {
|
||||
footer.value = footerLinks.value
|
||||
|
|
|
@ -8,7 +8,7 @@ type VitePressPage = {
|
|||
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 footerLinks = ref<Uri[]>([])
|
||||
|
||||
|
@ -88,7 +88,6 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
|||
}
|
||||
|
||||
function setFooter(uris: Uri[]) {
|
||||
console.log('setting footer links', uris)
|
||||
footerLinks.value = uris
|
||||
}
|
||||
|
||||
|
@ -133,6 +132,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
|||
|
||||
async function openPage(page: string) {
|
||||
await router.go(page)
|
||||
if (pageChangeCallback) pageChangeCallback(page)
|
||||
}
|
||||
|
||||
function handleCurrentCommand() {
|
||||
|
@ -162,7 +162,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
|||
case 'open':
|
||||
addText('\n', false)
|
||||
if (!args.length) addText('USAGE: go page_name')
|
||||
else router.go(args[0])
|
||||
else openPage(args[0])
|
||||
break
|
||||
default:
|
||||
execUserCommand(cmd)
|
||||
|
|
Loading…
Reference in a new issue