-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
209 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BookmarkNode } from "../../lib/typesFacade"; | ||
|
||
export default class Filterer { | ||
static byRegex(nodes: BookmarkNode[], regex: RegExp): BookmarkNode[] { | ||
return []; | ||
} | ||
static dateAddedBefore(nodes: BookmarkNode[], cutoff: Date): BookmarkNode[] { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import DataEditor, { | ||
CellClickedEventArgs, | ||
CompactSelection, | ||
GridSelection, | ||
Item, | ||
} from "@glideapps/glide-data-grid"; | ||
import React from "react"; | ||
import { BookmarkNode } from "../../lib/typesFacade"; | ||
import { isAFolder } from "../../utils/ifHasChildrenFolders"; | ||
import { | ||
ContextMenuActionTypes, | ||
useContextMenuDispatch, | ||
} from "../context-menu/ContextMenuContext"; | ||
import { usePathDispatch } from "../path/PathContext"; | ||
import { columns, getData } from "../table/columns"; | ||
import { | ||
decideContextType, | ||
getNodesFromTableSelection, | ||
runDoubleClickSideEffects, | ||
} from "./utils/getNodesFromTableSelection"; | ||
|
||
// todo use a reducer for the whole thing probably | ||
interface FilterSearch { | ||
regex?: RegExp; | ||
page?: string; | ||
substringInName?: string; | ||
onlyFolder: boolean; | ||
onlyBookmark: boolean; | ||
// todo this with a slider interface between 3 things | ||
} | ||
|
||
export function SearchResultsTable( | ||
props: { | ||
rows: BookmarkNode[]; | ||
}, | ||
): JSX.Element { | ||
const pathDispatch = usePathDispatch(); | ||
const contextMenuDispatch = useContextMenuDispatch(); | ||
const [selection, setSelection] = React.useState<GridSelection>({ | ||
columns: CompactSelection.empty(), | ||
rows: CompactSelection.empty(), | ||
}); | ||
|
||
// CLICK HANDLING | ||
const doubleClickHandler = (cell: Item) => { | ||
const selectedBookmarks = getNodesFromTableSelection( | ||
props.rows, | ||
selection, | ||
cell, | ||
); | ||
if (selectedBookmarks.length === 0) return; | ||
const b = selectedBookmarks[0]; // always double click only on one thing | ||
const isFolder = isAFolder(b); | ||
|
||
runDoubleClickSideEffects( | ||
cell[0], | ||
contextMenuDispatch, | ||
isFolder, | ||
b, | ||
pathDispatch, | ||
); | ||
}; | ||
|
||
const contextMenuHandler = (cell: Item, event: CellClickedEventArgs) => { | ||
event.preventDefault(); | ||
const selectedBookmarks = getNodesFromTableSelection( | ||
props.rows, | ||
selection, | ||
cell, | ||
); | ||
if (selectedBookmarks.length === 0) return; | ||
const type: ContextMenuActionTypes = decideContextType(selectedBookmarks); | ||
contextMenuDispatch({ | ||
type: type, | ||
direction: "open", | ||
position: [event.localEventX, event.localEventY], | ||
things: selectedBookmarks, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div | ||
className="table-container flex flex-grow pb-4 mb-40 " | ||
id="search-results-table-container" | ||
onDragOver={(e) => { | ||
e.preventDefault(); | ||
e.dataTransfer.dropEffect = "move"; | ||
}} | ||
> | ||
<div id="filter" className="m-2 p-2 rounded flex flex-row"> | ||
<button id="filterBlock1" className="mx-2 py-6"> | ||
isFolder filter | ||
</button> | ||
<button id="filterBlock1" className="mx-2 py-6"> | ||
contains word | ||
</button> | ||
<button id="filterBlock1" className="mx-2 py-6"> | ||
match regex | ||
</button> | ||
</div> | ||
<DataEditor | ||
// contents | ||
rows={props.rows.length} | ||
columns={columns} | ||
getCellContent={getData(props.rows)} | ||
// click interactivity | ||
keybindings={{ | ||
search: true, | ||
selectAll: true, | ||
selectRow: true, | ||
copy: true, | ||
paste: true, | ||
}} | ||
onCellActivated={doubleClickHandler} | ||
onCellContextMenu={contextMenuHandler} | ||
rowSelect={"single"} | ||
gridSelection={selection} | ||
onGridSelectionChange={setSelection} | ||
getCellsForSelection={true} | ||
/> | ||
</div> | ||
); | ||
} |
67 changes: 67 additions & 0 deletions
67
app/src/features/search/utils/getNodesFromTableSelection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
GridSelection, | ||
gridSelectionHasItem, | ||
Item, | ||
} from "@glideapps/glide-data-grid"; | ||
import React from "react"; | ||
import CRUDBookmarkFacade from "../../../lib/CRUDBookmarkFacade"; | ||
import { BookmarkNode } from "../../../lib/typesFacade"; | ||
import { isAFolder } from "../../../utils/ifHasChildrenFolders"; | ||
import { | ||
ContextMenuActionTypes, | ||
ContextMenuContextAction, | ||
} from "../../context-menu/ContextMenuContext"; | ||
import { PathAction } from "../../path/PathContext"; | ||
import { viewDetailsColNumber } from "../../table/columns"; | ||
|
||
export function runDoubleClickSideEffects( | ||
col: number, | ||
contextMenuDispatch: React.Dispatch<ContextMenuContextAction>, | ||
isFolder: boolean, | ||
b: BookmarkNode, | ||
pathDispatch: React.Dispatch<PathAction>, | ||
): void { | ||
if (col === viewDetailsColNumber) { | ||
contextMenuDispatch({ | ||
type: isFolder ? "folder" : "single-bookmark", | ||
direction: "open", | ||
// todo change that hardcoded value for position, should be some start of the table maybe | ||
position: [550, 550], | ||
things: [b], | ||
}); | ||
} else if (isFolder) { | ||
CRUDBookmarkFacade.getPath(b).then((newPath) => { | ||
console.debug("path:", newPath); | ||
pathDispatch({ | ||
type: "full", | ||
nodes: newPath, | ||
}); | ||
}); | ||
} else { | ||
chrome.tabs.create({ url: b.url }); | ||
} | ||
} | ||
|
||
// todo here logic does not seem to work actualyl | ||
export function decideContextType( | ||
selectedBookmarks: BookmarkNode[], | ||
): ContextMenuActionTypes { | ||
return selectedBookmarks.length === 1 | ||
? "mixed" | ||
: isAFolder(selectedBookmarks[0]) | ||
? "folder" | ||
: "single-bookmark"; | ||
} | ||
|
||
export function getNodesFromTableSelection( | ||
rows: BookmarkNode[], | ||
selection: GridSelection, | ||
cell: Item, | ||
): BookmarkNode[] { | ||
const includes: boolean = gridSelectionHasItem(selection, cell); | ||
if (!includes) return []; | ||
const start: number = selection.current?.range.y ?? 0; | ||
const end: number = start + (selection.current?.range.height ?? 0); | ||
const selectedBookmarks = rows.slice(start, end); | ||
return selectedBookmarks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters