2022-03-03 02:34:19 +03:00
|
|
|
import { pokeTask } from '@urbit/api/term';
|
|
|
|
import api from './api';
|
|
|
|
import React from 'react';
|
|
|
|
import useTermState from './state';
|
|
|
|
import { Tab } from './Tab';
|
2022-03-04 01:58:48 +03:00
|
|
|
import { SESSION_ID_REGEX } from './constants';
|
2022-03-03 02:34:19 +03:00
|
|
|
|
|
|
|
export const Tabs = () => {
|
|
|
|
const { sessions, names } = useTermState();
|
|
|
|
|
|
|
|
const onAddClick = () => {
|
|
|
|
const name = prompt('please entew a session name uwu');
|
2022-03-04 01:58:48 +03:00
|
|
|
if (!name || !SESSION_ID_REGEX.test(name) || names.includes(name)) {
|
|
|
|
console.log('invalid session name:', name);
|
2022-03-03 02:34:19 +03:00
|
|
|
return;
|
|
|
|
}
|
2022-03-04 01:58:48 +03:00
|
|
|
api.poke(pokeTask(name, { open: { term: 'hood', apps: [{ who: '~' + (window as any).ship, app: 'dojo' }] } }));
|
2022-03-03 02:34:19 +03:00
|
|
|
useTermState.getState().set(state => {
|
|
|
|
state.names = [name, ...state.names].sort();
|
|
|
|
state.selected = name;
|
|
|
|
state.sessions[name] = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="tabs">
|
2022-03-04 01:58:48 +03:00
|
|
|
{names.map((n, i) => {
|
2022-03-03 02:34:19 +03:00
|
|
|
return (
|
|
|
|
<Tab session={sessions[n]} name={n} key={i} />
|
|
|
|
);
|
|
|
|
})}
|
2022-03-04 02:10:54 +03:00
|
|
|
<button className="tab" onClick={onAddClick}>+</button>
|
2022-03-03 02:34:19 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|