Skip to content

Commit

Permalink
remove dual panel slice
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Sep 23, 2024
1 parent 62c65ca commit 389da0b
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 341 deletions.
2 changes: 0 additions & 2 deletions ui2/src/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import tagsReducer from "@/features/tags/tagsSlice"
import uiReducer from "@/features/ui/uiSlice"
import usersReducer from "@/features/users/usersSlice"
import currentUserReducer from "@/slices/currentUser"
import dualPanelReducer from "@/slices/dualPanel/dualPanel"
import {configureStore} from "@reduxjs/toolkit"
import {listenerMiddleware} from "./listenerMiddleware"

export const store = configureStore({
reducer: {
auth: authSliceReducer,
currentUser: currentUserReducer,
dualPanel: dualPanelReducer,
tags: tagsReducer,
groups: groupsReducer,
users: usersReducer,
Expand Down
22 changes: 5 additions & 17 deletions ui2/src/components/DualPanel/ToggleSecondaryPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {useAppDispatch, useAppSelector} from "@/app/hooks"
import {
selectMainPanel,
selectSecondaryPanel
} from "@/slices/dualPanel/dualPanel"
import {ActionIcon} from "@mantine/core"
import {IconColumns2, IconX} from "@tabler/icons-react"
import {useContext} from "react"
Expand All @@ -20,16 +16,10 @@ import {

export default function ToggleSecondaryPanel() {
const mode: PanelMode = useContext(PanelContext)
const mainPanel = useAppSelector(selectMainPanel)
const secondaryPanel = useAppSelector(selectSecondaryPanel)
const dispatch = useAppDispatch()
const nodeID = useAppSelector(s => selectCurrentNodeID(s, mode))
const ctype = useAppSelector(s => selectCurrentNodeCType(s, mode))

if (mainPanel) {
// mainPanel is always there
}

const onClick = () => {
dispatch(secondaryPanelOpened(ctype == "folder" ? "commander" : "viewer"))
dispatch(
Expand All @@ -38,13 +28,11 @@ export default function ToggleSecondaryPanel() {
}

if (mode == "main") {
if (!secondaryPanel) {
return (
<ActionIcon size="lg" onClick={onClick} variant="default">
<IconColumns2 size={18} />
</ActionIcon>
)
}
return (
<ActionIcon size="lg" onClick={onClick} variant="default">
<IconColumns2 size={18} />
</ActionIcon>
)

return <></>
}
Expand Down
3 changes: 1 addition & 2 deletions ui2/src/features/document/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {useAppSelector} from "@/app/hooks"
import PanelContext from "@/contexts/PanelContext"
import {useGetPageImageQuery} from "@/features/document/apiSlice"
import {selectZoomFactor} from "@/features/ui/uiSlice"
import {selectDocumentCurrentPage} from "@/slices/dualPanel/dualPanel"
import {ClientPage, PanelMode} from "@/types"
import {Skeleton, Stack} from "@mantine/core"
import {useContext, useEffect, useRef} from "react"
Expand All @@ -15,7 +14,7 @@ type Args = {
export default function Page({page}: Args) {
const {currentData, data, isFetching} = useGetPageImageQuery(page.id)
const mode: PanelMode = useContext(PanelContext)
const currentPage = useAppSelector(s => selectDocumentCurrentPage(s, mode))
const currentPage = 1
const targetRef = useRef<HTMLImageElement | null>(null)
const zoomFactor = useAppSelector(s => selectZoomFactor(s, mode))

Expand Down
3 changes: 1 addition & 2 deletions ui2/src/features/document/components/Thumbnail/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
viewerSelectionPageAdded,
viewerSelectionPageRemoved
} from "@/features/ui/uiSlice"
import {setCurrentPage} from "@/slices/dualPanel/dualPanel"
import type {ClientPage, DroppedThumbnailPosition, PanelMode} from "@/types"

import {contains_every} from "@/utils"
Expand Down Expand Up @@ -80,7 +79,7 @@ export default function Thumbnail({page}: Args) {
}, [draggedPages?.length])

const onClick = () => {
dispatch(setCurrentPage({mode, page: page.number}))
//dispatch(setCurrentPage({mode, page: page.number}))
}

const onLocalDragOver = (event: React.DragEvent<HTMLDivElement>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {useDispatch} from "react-redux"

import {searchResultItemTargetUpdated} from "@/features/ui/uiSlice"
import {Checkbox} from "@mantine/core"
import {updateSearchResultItemTarget} from "@/slices/dualPanel/dualPanel"

export default function OpenInOtherPanelCheckbox() {
const dispatch = useDispatch()

const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const targetPanel = event.currentTarget.checked ? "secondary" : "main"
dispatch(updateSearchResultItemTarget(targetPanel))
const inOtherPanel = Boolean(event.currentTarget.checked)
dispatch(searchResultItemTargetUpdated(inOtherPanel))
}

return (
<Checkbox onChange={onChange} defaultChecked label="Open in other panel" />
)
Expand Down
5 changes: 3 additions & 2 deletions ui2/src/features/search/components/SearchResultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ export default function SearchResultItem({item, onClick}: Args) {
<Stack my={"lg"} pt={"sm"} gap="xs">
<Breadcrumb
onClick={onClick}
// for documents breadcrumb also indicates page number
// for documents breadcrumb also indicates
// page number (if page number > 1)
pageNumber={item.page_number}
items={nodeDetails?.breadcrumb}
/>
<Group className={classes.item} onClick={onLocalClickDocumentItem}>
<div className={classes.title}>{item.title}</div>
<Tags items={nodeDetails.tags} maxItems={8} />
<Tags items={nodeDetails?.tags} maxItems={8} />
</Group>
</Stack>
)
Expand Down
17 changes: 15 additions & 2 deletions ui2/src/features/search/components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
useGetPaginatedSearchResultsQuery
} from "@/features/search/apiSlice"
import {
currentNodeChanged,
searchResultsLastPageSizeUpdated,
selectOpenResultItemInOtherPanel,
selectSearchContentHeight,
selectSearchLastPageSize,
selectSearchQuery
} from "@/features/ui/uiSlice"
import {SearchResultNode} from "@/types"
import {NType, SearchResultNode} from "@/types"
import {skipToken} from "@reduxjs/toolkit/query"
import ActionButtons from "./ActionButtons"
import SearchResultItems from "./SearchResultItems"
Expand All @@ -28,6 +30,7 @@ export default function SearchResults() {
const dispatch = useAppDispatch()
const height = useAppSelector(selectSearchContentHeight)
const query = useAppSelector(selectSearchQuery)
const openItemInOtherPanel = useAppSelector(selectOpenResultItemInOtherPanel)
const {data, isLoading, isFetching} = useGetPaginatedSearchResultsQuery({
qs: query!,
page_number: page,
Expand All @@ -52,7 +55,17 @@ export default function SearchResults() {
}
}, [data?.items])

const onClick = () => {}
const onClick = (node: NType, pageNumber?: number) => {
if (openItemInOtherPanel) {
dispatch(
currentNodeChanged({id: node.id, ctype: node.ctype, panel: "secondary"})
)
} else {
dispatch(
currentNodeChanged({id: node.id, ctype: node.ctype, panel: "main"})
)
}
}

const onPageNumberChange = (page: number) => {
setPage(page)
Expand Down
10 changes: 10 additions & 0 deletions ui2/src/features/ui/uiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ const uiSlice = createSlice({
}
state.currentNodeMain = undefined
},
searchResultItemTargetUpdated(state, action: PayloadAction<boolean>) {
if (state.search) {
/* in which panel will search result item open ? */
state.search.openResultItemInOtherPanel = action.payload
}
},
currentNodeChanged(state, action: PayloadAction<CurrentNodeArgs>) {
const payload = action.payload
if (payload.panel == "main") {
Expand Down Expand Up @@ -610,6 +616,7 @@ export const {
This happens when user clicks enter in search field
in the header */
mainPanelSwitchedToSearchResults,
searchResultItemTargetUpdated,
secondaryPanelClosed,
secondaryPanelOpened,
commanderSelectionNodeAdded,
Expand Down Expand Up @@ -802,6 +809,9 @@ export const selectSearchQuery = (state: RootState) => state.ui.search?.query
export const selectSearchLastPageSize = (state: RootState): number =>
state.ui.searchLastPageSize || PAGINATION_DEFAULT_ITEMS_PER_PAGES

export const selectOpenResultItemInOtherPanel = (state: RootState) =>
state.ui.search?.openResultItemInOtherPanel

/* Load initial collapse state value from cookie */
function initial_collapse_value(): boolean {
const collapsed = Cookies.get(NAVBAR_COLLAPSED_COOKIE) as BooleanString
Expand Down
Loading

0 comments on commit 389da0b

Please sign in to comment.