@@ -6,42 +6,57 @@ import { ArrowLeft, ArrowRight, ArrowClockwise } from 'react-bootstrap-icons';
6
6
import { useDispatch , useSelector } from 'react-redux' ;
7
7
import Tabs from './Tabs.jsx' ;
8
8
import Search from './Search.jsx' ;
9
- import { actions as tabDataActions } from '../slices/tabsData' ;
9
+ import { updateTabData } from '../slices/tabsData' ;
10
10
11
11
import TabsContent from './TabsContent.jsx' ;
12
12
import * as selectors from '../selectors' ;
13
13
14
14
const Header = ( ) => {
15
15
const activeTabId = useSelector ( selectors . activeTabIdSelector ) ;
16
16
const currentLinks = useSelector ( selectors . currentLinksSelector ) ;
17
+ const historyTabs = useSelector ( selectors . historyTabsSelector ) ;
18
+ const currentHistoryTab = historyTabs [ activeTabId ] ?? [ ] ;
19
+ const url = currentLinks [ activeTabId ] ;
20
+ const currentIndexURL = currentHistoryTab . indexOf ( url ) ;
21
+ const lastIndexHistory = currentHistoryTab . length - 1 ;
17
22
const dispatch = useDispatch ( ) ;
18
23
19
24
const refresh = async ( ) => {
20
25
if ( activeTabId in currentLinks ) {
21
- const url = currentLinks [ activeTabId ] ;
22
- try {
23
- const response = await fetch ( url ) ;
24
- const htmlDoc = await response . text ( ) ;
25
- const data = { [ activeTabId ] : htmlDoc } ;
26
- dispatch ( tabDataActions . updateTabData ( data ) ) ;
27
- } catch ( e ) {
28
- console . error ( 'something wrong: ' , e ) ;
29
- }
26
+ dispatch ( updateTabData ( { activeTabId, url } ) ) ;
30
27
}
31
28
} ;
32
29
30
+ const backwardHistory = ( ) => {
31
+ const previosIndex = currentIndexURL - 1 ;
32
+ dispatch ( updateTabData ( { activeTabId, url : currentHistoryTab [ previosIndex ] } ) ) ;
33
+ } ;
34
+
35
+ const forwardsHistory = ( ) => {
36
+ const nextIndex = currentIndexURL + 1 ;
37
+ dispatch ( updateTabData ( { activeTabId, url : currentHistoryTab [ nextIndex ] } ) ) ;
38
+ } ;
39
+
40
+ const isFirstHistory = ( ) => currentIndexURL === 0 || currentIndexURL === - 1 ;
41
+
42
+ const isLastHistory = ( ) => currentIndexURL === lastIndexHistory || currentIndexURL === - 1 ;
43
+
33
44
return (
34
45
< Tab . Container id = "left-tabs-example" defaultActiveKey = "first" >
35
46
< Tabs />
36
47
< Row >
37
- < Col sm = { 1 } className = "d-flex justify-content-between align-items-center" >
38
- < ArrowLeft size = { 26 } />
39
- < ArrowRight size = { 26 } />
48
+ < Col sm = { 2 } className = "d-flex justify-content-around align-items-center" >
49
+ < Button disabled = { isFirstHistory ( ) } variant = "outline-secondary" size = "sm" onClick = { backwardHistory } >
50
+ < ArrowLeft size = { 26 } />
51
+ </ Button >
52
+ < Button disabled = { isLastHistory ( ) } variant = "outline-secondary" size = "sm" onClick = { forwardsHistory } >
53
+ < ArrowRight size = { 26 } />
54
+ </ Button >
40
55
< Button variant = "outline-secondary" size = "sm" onClick = { refresh } >
41
56
< ArrowClockwise size = { 26 } />
42
57
</ Button >
43
58
</ Col >
44
- < Col sm = { 11 } >
59
+ < Col sm = { 10 } >
45
60
< Search />
46
61
</ Col >
47
62
</ Row >
0 commit comments