urbit/pkg/interface/webterm/Tabs.tsx
fang d98611a04b
webterm: support multiple sessions
Fully implements webterm support for multiple dill terminal sessions.

Remaining work includes styling, session creation safety (name-wise),
and general cleanup.

Co-authored-by: tomholford <tomholford@users.noreply.github.com>
Co-authored-by: liam-fitzgerald <liam@tlon.io>
2022-03-02 17:34:19 -06:00

37 lines
907 B
TypeScript

import { pokeTask } from '@urbit/api/term';
import api from './api';
import React from 'react';
import useTermState from './state';
import { Tab } from './Tab';
export const Tabs = () => {
const { sessions, names } = useTermState();
const onAddClick = () => {
const name = prompt('please entew a session name uwu');
if (!name) {
return;
}
//TODO name must be @ta
api.poke(pokeTask(name, { open: { term: 'hood', apps: [{ who: '~'+(window as any).ship, app: 'dojo' }] } }));
useTermState.getState().set(state => {
state.names = [name, ...state.names].sort();
state.selected = name;
state.sessions[name] = null;
});
}
return (
<div className="tabs">
{ names.map((n, i) => {
return (
<Tab session={sessions[n]} name={n} key={i} />
);
})}
<button onClick={onAddClick}>+</button>
</div>
);
};