Cleanup ImageGalleryDrawer
Build and publish docker image snapshot / build-and-publish (push) Successful in 1m10s
Details
Build and publish docker image snapshot / build-and-publish (push) Successful in 1m10s
Details
Move pathname related functions in pathnames.ts
This commit is contained in:
parent
4da3376d5f
commit
da273cbc87
|
|
@ -10,7 +10,7 @@ import Toolbar from "@mui/material/Toolbar";
|
|||
import { Chip, useTheme } from "@mui/material";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import { smallScreenMediaQuery } from "../ImageGalleryLayout";
|
||||
import { getDefaultExpanded } from "./PathToExpaned";
|
||||
import { getDefaultExpanded, getParentAndChildPath } from "./pathnames";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
function generateTreeViewChildren(
|
||||
|
|
@ -61,17 +61,9 @@ const GenerateTreeView = ({ root }: { root: Folders }) => {
|
|||
);
|
||||
const [selectedItem, setSelectedItem] = useState<string>(location.pathname);
|
||||
|
||||
// TODO: clean this effect up. See also `getDefaultExpanded`
|
||||
useEffect(() => {
|
||||
let curPathname = location.pathname.startsWith("/")
|
||||
? location.pathname.slice(1)
|
||||
: location.pathname;
|
||||
while (curPathname.endsWith("/")) {
|
||||
curPathname = curPathname.slice(0, -1);
|
||||
}
|
||||
const parentPathname = curPathname.substring(
|
||||
0,
|
||||
curPathname.lastIndexOf("/"),
|
||||
const { parent: parentPathname, cur: curPathname } = getParentAndChildPath(
|
||||
location.pathname,
|
||||
);
|
||||
if (!expandedItems.includes(parentPathname)) {
|
||||
setExpandedItems([parentPathname, ...expandedItems]);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getDefaultExpanded } from "../PathToExpaned";
|
||||
import { getDefaultExpanded } from "../pathnames";
|
||||
|
||||
interface pathWithExpanded {
|
||||
pathname: string;
|
||||
|
|
@ -1,12 +1,28 @@
|
|||
export const getDefaultExpanded = (pathname: string): string[] => {
|
||||
const pathParts = [];
|
||||
const cleanupPath = (pathname: string): string => {
|
||||
let curPathname = pathname.startsWith("/") ? pathname.slice(1) : pathname;
|
||||
while (curPathname.endsWith("/")) {
|
||||
curPathname = curPathname.slice(0, -1);
|
||||
}
|
||||
return curPathname;
|
||||
};
|
||||
|
||||
export const getDefaultExpanded = (pathname: string): string[] => {
|
||||
let curPathname = cleanupPath(pathname);
|
||||
const pathParts = [];
|
||||
while (curPathname.length > 0) {
|
||||
pathParts.push(curPathname);
|
||||
curPathname = curPathname.substring(0, curPathname.lastIndexOf("/"));
|
||||
}
|
||||
return pathParts;
|
||||
};
|
||||
|
||||
export const getParentAndChildPath = (
|
||||
pathname: string,
|
||||
): { parent: string; cur: string } => {
|
||||
let curPathname = cleanupPath(pathname);
|
||||
const parentPathname = curPathname.substring(0, curPathname.lastIndexOf("/"));
|
||||
return {
|
||||
parent: parentPathname,
|
||||
cur: curPathname,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue