Skip to content

Commit f3acde4

Browse files
authored
Merge pull request #2368 from JohnDuprey/dev
Recent Pages
2 parents cd85a05 + 657138c commit f3acde4

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

src/components/utilities/CippActionsOffcanvas.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const CippOffcanvasCard = ({ action, key }) => {
6767
title={`${action.label} - Details`}
6868
state={offcanvasVisible}
6969
hideFunction={() => setOffcanvasVisible(false)}
70+
modal={true}
7071
/>
7172
)}
7273
</CCardBody>

src/hooks/useNavFavouriteCheck.jsx

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,55 @@
11
import { CNavGroup, CNavItem, CNavTitle } from '@coreui/react'
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
33
import { useSelector } from 'react-redux'
4+
import routes from 'src/routes'
45

56
export const useNavFavouriteCheck = (navigation) => {
67
const favourites = useSelector((state) => state.app.userSettingsDefaults?.favourites)
7-
8+
const recentPages = useSelector((state) => state.app.recentPages)
9+
const newNavigation = [{ component: CNavTitle, name: 'Home' }]
810
if (Array.isArray(favourites)) {
9-
const newNavigation = [
10-
{ component: CNavTitle, name: 'Favourites' },
11-
{
11+
newNavigation.push({
12+
component: CNavGroup,
13+
section: 'favourites',
14+
name: 'Favourites',
15+
to: '/favorites',
16+
icon: <FontAwesomeIcon icon={'star'} className="nav-icon" />,
17+
items: favourites.map((item) => {
18+
//console.log(item)
19+
return {
20+
name: item.value.name,
21+
to: item.value.to,
22+
component: CNavItem,
23+
}
24+
}),
25+
})
26+
}
27+
if (Array.isArray(recentPages)) {
28+
var items = []
29+
30+
recentPages.map((path) => {
31+
const item = routes.find((route) => route.path === path)
32+
if (item?.path) {
33+
items.push({
34+
name: item.name,
35+
to: item.path,
36+
component: CNavItem,
37+
})
38+
}
39+
})
40+
if (items.length > 0) {
41+
items = items.slice(0, 5)
42+
newNavigation.push({
1243
component: CNavGroup,
13-
section: 'favourites',
14-
name: 'Favourites',
15-
to: '/favorites',
16-
icon: <FontAwesomeIcon icon={'star'} className="nav-icon" />,
17-
items: favourites.map((item) => {
18-
//console.log(item)
19-
return {
20-
name: item.value.name,
21-
to: item.value.to,
22-
component: CNavItem,
23-
}
24-
}),
25-
},
26-
{ component: CNavTitle, name: 'Dashboard' },
27-
...navigation,
28-
]
29-
return newNavigation
44+
section: 'recent',
45+
name: 'Recent Pages',
46+
to: '/recent',
47+
icon: <FontAwesomeIcon icon={'history'} className="nav-icon" />,
48+
items: items,
49+
})
50+
}
3051
}
31-
return navigation
52+
newNavigation.push(...navigation)
53+
54+
return newNavigation
3255
}

src/layout/DefaultLayout.jsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import React, { useEffect, Suspense, useCallback } from 'react'
1+
import React, { useEffect, Suspense, useCallback, useState } from 'react'
22
import { AppFooter, AppHeader, AppSidebar } from 'src/components/layout'
33
import { FullScreenLoading, ModalRoot, FastSwitcherModal, Toasts } from 'src/components/utilities'
44
import { useDispatch, useSelector } from 'react-redux'
5-
import { Outlet } from 'react-router-dom'
5+
import { Outlet, useLocation } from 'react-router-dom'
66
import { CContainer } from '@coreui/react'
77
import { toggleSwitcher } from 'src/store/features/switcher'
88
import { useHotkeys } from 'react-hotkeys-hook'
99
import { useMediaPredicate } from 'react-media-hook'
10+
import { setRecentPages } from 'src/store/features/app'
1011

1112
const DefaultLayout = () => {
1213
const preferredTheme = useMediaPredicate('(prefers-color-scheme: dark)') ? 'impact' : 'cyberdrain'
1314
const themePreference = useSelector((state) => state.app.currentTheme)
15+
const recentPages = useSelector((state) => state.app.recentPages)
16+
const [lastPage, setLastPage] = useState('')
1417
const dispatch = useDispatch()
18+
const location = useLocation()
1519

1620
let theme
1721
if (themePreference === 'default') {
@@ -25,6 +29,25 @@ const DefaultLayout = () => {
2529
document.body.dataset.theme = theme
2630
})
2731

32+
useEffect(() => {
33+
if (recentPages[0] !== location.pathname && lastPage !== location.pathname) {
34+
var currentPages = []
35+
currentPages.push(lastPage)
36+
if (recentPages.length > 0) {
37+
recentPages.forEach((page) => {
38+
if (page !== lastPage) {
39+
currentPages.push(page)
40+
}
41+
})
42+
}
43+
currentPages = currentPages.slice(0, 10)
44+
if (currentPages.length > 0) {
45+
dispatch(setRecentPages({ recentPages: currentPages }))
46+
}
47+
}
48+
setLastPage(location.pathname)
49+
}, [location.pathname, recentPages, dispatch, lastPage, setLastPage])
50+
2851
const handleFastSwitcher = useCallback(() => {
2952
dispatch(toggleSwitcher())
3053
}, [dispatch])

src/store/features/app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const initialState = {
1313
TenantListSelector: false,
1414
defaultColumns: {},
1515
newUserDefaults: {},
16+
recentPages: [],
1617
}
1718

1819
export const appSlice = createSlice({
@@ -58,6 +59,9 @@ export const appSlice = createSlice({
5859
state[key] = action.payload?.userSettings[key]
5960
})
6061
},
62+
setRecentPages: (state, action) => {
63+
state.recentPages = action.payload?.recentPages
64+
},
6165
},
6266
})
6367

@@ -75,6 +79,7 @@ export const {
7579
setUserSettings,
7680
setDefaultColumns,
7781
setNewUserDefaults,
82+
setRecentPages,
7883
} = appSlice.actions
7984

8085
export default persistReducer(

0 commit comments

Comments
 (0)