mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: highlight active page
This commit is contained in:
parent
543846c241
commit
e297769ac2
@ -1,14 +1,16 @@
|
|||||||
import { useAppSelector } from '../../../stores/store';
|
import { useAppDispatch, useAppSelector } from '../../../stores/store';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { IPage } from '../../../stores/reducers/pages/slice';
|
import { IPage } from '../../../stores/reducers/pages/slice';
|
||||||
import { ViewLayoutTypePB } from '../../../../services/backend';
|
import { ViewLayoutTypePB } from '../../../../services/backend';
|
||||||
import { MouseEventHandler, useState } from 'react';
|
import { MouseEventHandler, useState } from 'react';
|
||||||
|
import { activePageIdActions } from '../../../stores/reducers/activePageId/slice';
|
||||||
|
|
||||||
// number of pixels from left side of screen to show hidden navigation panel
|
// number of pixels from left side of screen to show hidden navigation panel
|
||||||
const FLOATING_PANEL_SHOW_WIDTH = 10;
|
const FLOATING_PANEL_SHOW_WIDTH = 10;
|
||||||
const FLOATING_PANEL_HIDE_EXTRA_WIDTH = 10;
|
const FLOATING_PANEL_HIDE_EXTRA_WIDTH = 10;
|
||||||
|
|
||||||
export const useNavigationPanelHooks = function () {
|
export const useNavigationPanelHooks = function () {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
const folders = useAppSelector((state) => state.folders);
|
const folders = useAppSelector((state) => state.folders);
|
||||||
const pages = useAppSelector((state) => state.pages);
|
const pages = useAppSelector((state) => state.pages);
|
||||||
const width = useAppSelector((state) => state.navigationWidth);
|
const width = useAppSelector((state) => state.navigationWidth);
|
||||||
@ -52,6 +54,8 @@ export const useNavigationPanelHooks = function () {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
dispatch(activePageIdActions.setActivePageId(page.id));
|
||||||
|
|
||||||
navigate(`/page/${pageTypeRoute}/${page.id}`);
|
navigate(`/page/${pageTypeRoute}/${page.id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { IPage, pagesActions } from '../../../stores/reducers/pages/slice';
|
import { IPage, pagesActions } from '../../../stores/reducers/pages/slice';
|
||||||
import { useAppDispatch } from '../../../stores/store';
|
import { useAppDispatch, useAppSelector } from '../../../stores/store';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { ViewBackendService } from '../../../stores/effects/folder/view/view_bd_svc';
|
import { ViewBackendService } from '../../../stores/effects/folder/view/view_bd_svc';
|
||||||
@ -9,6 +9,7 @@ export const usePageEvents = (page: IPage) => {
|
|||||||
const appDispatch = useAppDispatch();
|
const appDispatch = useAppDispatch();
|
||||||
const [showPageOptions, setShowPageOptions] = useState(false);
|
const [showPageOptions, setShowPageOptions] = useState(false);
|
||||||
const [showRenamePopup, setShowRenamePopup] = useState(false);
|
const [showRenamePopup, setShowRenamePopup] = useState(false);
|
||||||
|
const activePageId = useAppSelector((state) => state.activePageId);
|
||||||
const viewBackendService: ViewBackendService = new ViewBackendService(page.id);
|
const viewBackendService: ViewBackendService = new ViewBackendService(page.id);
|
||||||
const error = useError();
|
const error = useError();
|
||||||
|
|
||||||
@ -69,5 +70,6 @@ export const usePageEvents = (page: IPage) => {
|
|||||||
duplicatePage,
|
duplicatePage,
|
||||||
closePopup,
|
closePopup,
|
||||||
closeRenamePopup,
|
closeRenamePopup,
|
||||||
|
activePageId,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -20,13 +20,16 @@ export const PageItem = ({ page, onPageClick }: { page: IPage; onPageClick: () =
|
|||||||
duplicatePage,
|
duplicatePage,
|
||||||
closePopup,
|
closePopup,
|
||||||
closeRenamePopup,
|
closeRenamePopup,
|
||||||
|
activePageId,
|
||||||
} = usePageEvents(page);
|
} = usePageEvents(page);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'relative'}>
|
<div className={'relative'}>
|
||||||
<div
|
<div
|
||||||
onClick={() => onPageClick()}
|
onClick={() => onPageClick()}
|
||||||
className={'flex cursor-pointer items-center justify-between rounded-lg py-2 pl-8 pr-4 hover:bg-surface-2 '}
|
className={`flex cursor-pointer items-center justify-between rounded-lg py-2 pl-8 pr-4 hover:bg-surface-2 ${
|
||||||
|
activePageId === page.id ? 'bg-surface-2' : ''
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button className={'flex min-w-0 flex-1 items-center'}>
|
<button className={'flex min-w-0 flex-1 items-center'}>
|
||||||
<i className={'ml-1 mr-1 h-[16px] w-[16px]'}>
|
<i className={'ml-1 mr-1 h-[16px] w-[16px]'}>
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||||
|
export const activePageIdSlice = createSlice({
|
||||||
|
name: 'activePageId',
|
||||||
|
initialState: '',
|
||||||
|
reducers: {
|
||||||
|
setActivePageId(state, action: PayloadAction<string>) {
|
||||||
|
return action.payload;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const activePageIdActions = activePageIdSlice.actions;
|
@ -16,6 +16,7 @@ import { workspaceSlice } from './reducers/workspace/slice';
|
|||||||
import { databaseSlice } from './reducers/database/slice';
|
import { databaseSlice } from './reducers/database/slice';
|
||||||
import { boardSlice } from './reducers/board/slice';
|
import { boardSlice } from './reducers/board/slice';
|
||||||
import { errorSlice } from './reducers/error/slice';
|
import { errorSlice } from './reducers/error/slice';
|
||||||
|
import { activePageIdSlice } from './reducers/activePageId/slice';
|
||||||
|
|
||||||
const listenerMiddlewareInstance = createListenerMiddleware({
|
const listenerMiddlewareInstance = createListenerMiddleware({
|
||||||
onError: () => console.error,
|
onError: () => console.error,
|
||||||
@ -25,6 +26,7 @@ const store = configureStore({
|
|||||||
reducer: {
|
reducer: {
|
||||||
[foldersSlice.name]: foldersSlice.reducer,
|
[foldersSlice.name]: foldersSlice.reducer,
|
||||||
[pagesSlice.name]: pagesSlice.reducer,
|
[pagesSlice.name]: pagesSlice.reducer,
|
||||||
|
[activePageIdSlice.name]: activePageIdSlice.reducer,
|
||||||
[navigationWidthSlice.name]: navigationWidthSlice.reducer,
|
[navigationWidthSlice.name]: navigationWidthSlice.reducer,
|
||||||
[currentUserSlice.name]: currentUserSlice.reducer,
|
[currentUserSlice.name]: currentUserSlice.reducer,
|
||||||
[gridSlice.name]: gridSlice.reducer,
|
[gridSlice.name]: gridSlice.reducer,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user