feat(project-list): highlight active link.
This commit is contained in:
parent
4cf3b61da7
commit
5d3f97667a
20
src/commons/route/active-link.tsx
Normal file
20
src/commons/route/active-link.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { ActiveHookProps, Link, LinkProps, useActive } from '@curi/react-dom';
|
||||||
|
import React, { FC, ReactNode } from 'react';
|
||||||
|
|
||||||
|
export type ActiveLinkProps = ActiveHookProps &
|
||||||
|
LinkProps & {
|
||||||
|
className?: string;
|
||||||
|
children: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ActiveLink:FC<ActiveLinkProps> = ({ name, params, partial, className = "", ...rest }) => {
|
||||||
|
const active = useActive({ name, params, partial });
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
name={name}
|
||||||
|
params={params}
|
||||||
|
{...rest}
|
||||||
|
className={active ? `${className} active` : className}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
@ -3,7 +3,6 @@ import { Link } from '@curi/react-dom';
|
|||||||
import { List, ListItem, Typography, ListItemText } from '@material-ui/core';
|
import { List, ListItem, Typography, ListItemText } from '@material-ui/core';
|
||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { Pipeline } from '../generated/graphql';
|
import { Pipeline } from '../generated/graphql';
|
||||||
import { Fragment } from 'react';
|
|
||||||
import { CallMerge } from '@material-ui/icons';
|
import { CallMerge } from '@material-ui/icons';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { gql, useQuery } from '@apollo/client';
|
import { gql, useQuery } from "@apollo/client";
|
||||||
import { Link, useRouter } from '@curi/react-dom';
|
import { Link } from "@curi/react-dom";
|
||||||
import { Box, List, ListItem } from '@material-ui/core';
|
import { Box, List, ListItem, makeStyles, Theme } from "@material-ui/core";
|
||||||
import { find, propEq } from 'ramda';
|
import { FC } from "react";
|
||||||
import React, { useState, FC, useEffect } from 'react';
|
import { Project } from "../generated/graphql";
|
||||||
import { Project } from '../generated/graphql';
|
import { ListItemText } from "@material-ui/core";
|
||||||
import { ListItemText } from '@material-ui/core';
|
import { Button } from "@material-ui/core";
|
||||||
import { Button } from '@material-ui/core';
|
import { AddBox } from "@material-ui/icons";
|
||||||
import { AddBox } from '@material-ui/icons';
|
import { ActiveLink } from "../commons/route/active-link";
|
||||||
|
|
||||||
const PROJECTS = gql`
|
const PROJECTS = gql`
|
||||||
query Projects {
|
query Projects {
|
||||||
@ -21,13 +21,31 @@ const PROJECTS = gql`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
|
item: {
|
||||||
|
position: "relative",
|
||||||
|
".active &": {
|
||||||
|
backgroundColor: theme.palette.background.default,
|
||||||
|
},
|
||||||
|
".active &::before": {
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
content: '""',
|
||||||
|
display: "block",
|
||||||
|
borderLeftColor: theme.palette.secondary.main,
|
||||||
|
borderLeftWidth: 4,
|
||||||
|
borderLeftStyle: "solid",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
export function ProjectPanel() {
|
export function ProjectPanel() {
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<Box m={2}>
|
<Box m={2}>
|
||||||
<Link
|
<Link name="create-project">
|
||||||
name="create-project"
|
|
||||||
>
|
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
@ -44,32 +62,23 @@ export function ProjectPanel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ProjectList: FC<{}> = () => {
|
const ProjectList: FC<{}> = () => {
|
||||||
const { data, refetch } = useQuery<{
|
const { data } = useQuery<{
|
||||||
projects: Project[];
|
projects: Project[];
|
||||||
}>(PROJECTS);
|
}>(PROJECTS);
|
||||||
const projects = data?.projects;
|
const projects = data?.projects;
|
||||||
const [currentProject, setCurrentProject] = useState<Project | undefined>(
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
const { current } = useRouter();
|
|
||||||
|
|
||||||
useEffect(() => {
|
const classes = useStyles();
|
||||||
const currId = current()?.response?.params.projectId;
|
|
||||||
console.log(currId);
|
|
||||||
setCurrentProject(find(propEq("id", currId), projects ?? []));
|
|
||||||
}, [current, projects]);
|
|
||||||
|
|
||||||
const items = projects?.map((item) => (
|
const items = projects?.map((item) => (
|
||||||
<Link
|
<ActiveLink
|
||||||
name="project-detail"
|
name="project-detail"
|
||||||
params={{ projectId: item.id }}
|
params={{ projectId: item.id }}
|
||||||
key={item.id}
|
key={item.id}
|
||||||
onNav={() => setCurrentProject(item)}
|
|
||||||
>
|
>
|
||||||
<ListItem button>
|
<ListItem button className={classes.item}>
|
||||||
<ListItemText primary={item.name} secondary={item.comment} />
|
<ListItemText primary={item.name} secondary={item.comment} />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</Link>
|
</ActiveLink>
|
||||||
));
|
));
|
||||||
return <List>{items}</List>;
|
return <List>{items}</List>;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user