feat: close resource

This commit is contained in:
cha0s 2020-06-28 11:03:42 -05:00
parent 36fd1184f6
commit f7eeb15301
3 changed files with 31 additions and 2 deletions

View File

@ -200,6 +200,8 @@ select {
padding: 0.75em; padding: 0.75em;
} }
.close { .close {
background-color: transparent;
border: none;
color: #999999; color: #999999;
padding: 0.25em; padding: 0.25em;
visibility: hidden; visibility: hidden;

View File

@ -11,7 +11,10 @@ import {
} from 'react-tabs'; } from 'react-tabs';
import Resource from './resource'; import Resource from './resource';
import {setActiveResourceUri} from './state'; import {
closeResource,
setActiveResourceUri,
} from './state';
const decorate = compose( const decorate = compose(
contempo(require('./resources.raw.scss')), contempo(require('./resources.raw.scss')),
@ -32,7 +35,16 @@ const Resources = (props) => {
<span className="wrapper"> <span className="wrapper">
<span className="icon" /> <span className="icon" />
<span className="text">{uri}</span> <span className="text">{uri}</span>
<span className="close"></span> <button
className="close"
onClick={(event) => {
dispatch(closeResource(uri));
event.stopPropagation();
}}
type="button"
>
</button>
</span> </span>
</Tab> </Tab>
))} ))}

View File

@ -35,6 +35,20 @@ const slice = createSlice({
resourceUris: [], resourceUris: [],
}, },
reducers: { reducers: {
closeResource: (state, {payload: uri}) => {
const index = state.resourceUris.indexOf(uri);
if (-1 !== index) {
state.resourceUris.splice(index, 1);
if (state.resourceUris.length > 0) {
state.activeResourceUri = state.resourceUris[
Math.min(state.resourceUris.length - 1, index)
];
}
else {
state.activeResourceUri = '';
}
}
},
setActiveResourceUri: (state, {payload: uri}) => { setActiveResourceUri: (state, {payload: uri}) => {
state.activeResourceUri = uri; state.activeResourceUri = uri;
if (-1 === state.resourceUris.indexOf(uri)) { if (-1 === state.resourceUris.indexOf(uri)) {
@ -51,6 +65,7 @@ const slice = createSlice({
}); });
export const { export const {
closeResource,
setActiveResourceUri, setActiveResourceUri,
setActiveSidebarIndex, setActiveSidebarIndex,
setIsSidebarExpanded, setIsSidebarExpanded,