// ao-cli includes an AO client that makes calls to a locla or remote AO server.
// The ao-cli client has no store so it makes frequent (hopefully very quick) calls to get exactly the information it needs.
// This requires us to make sure the AO API server's REST API is concise and efficient.
// The only places ao-cli should call out to an AO server (i.e., use the API in api.js) are in this Use AO menu and in the Tests menu.
import { aoEnv } from '../ao-lib/settings.js'
import { isLoggedIn , loginPrompt , logout } from './session.js'
import { getTopPriorityText } from './priority.js'
import { AO _DEFAULT _HOSTNAME } from '../ao-lib/api.js'
import { headerStyle } from './styles.js'
import { cardMenu } from './cards.js'
import { connectMenu } from './connect.js'
import chatMenu from './chat.js'
import { promptMenu } from './welcome.js'
import { checkAoServerInteractive } from './wizard.js'
// Prints the Use AO Menu and executes the user's choice. Using the AO as a client occurs only under this menu item (except Tests menu).
export default async function useAoMenu ( ) {
const aoServerIsRunning = await checkAoServerInteractive ( )
if ( ! aoServerIsRunning ) {
console . log ( 'Please start an AO server to use AO client features.' )
return false
}
const loggedIn = isLoggedIn ( )
if ( loggedIn ) {
console . log ( 'Logged in as:' , aoEnv ( 'AO_CLI_SESSION_USERNAME' ) )
const topPriority = await getTopPriorityText ( )
console . log ( 'Top priority:' , topPriority || 'None' )
}
let aoMenuChoices = [ ]
if ( loggedIn ) {
aoMenuChoices . push (
'Deck' ,
'Chat' ,
'P2P' ,
)
}
aoMenuChoices . push (
loggedIn ? 'Log Out' : 'Log In' ,
'Back to Main Menu'
)
const answer = await promptMenu ( aoMenuChoices , 'AO' , 'connect to an AO server to use AO features' )
switch ( answer ) {
case 'Deck' :
//await todoList('My Todo List', ['Add full AO install process to ao-cli in convenient format', 'Add AO server unit tests to ao-cli', 'Get groceries', 'Play music every day'])
while ( await cardMenu ( ) ) { }
break
case 'P2P' :
while ( await connectMenu ( ) ) { }
break
case 'Chat' :
while ( await chatMenu ( ) ) { }
break
case 'Log In' :
console . log ( '\nao-cli will use the AO API to log into the AO server at' , ( aoEnv ( 'AO_CLI_TARGET_HOSTNAME' ) || AO _DEFAULT _HOSTNAME ) + '.' )
await loginPrompt ( )
break
case 'Log Out' :
await logout ( )
//await spinnerWait('Logging out...')
break
default :
return false
}
return true
}