Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling feat/delete-selected-news into develop #838

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
40 changes: 40 additions & 0 deletions apps/dicty-frontpage/src/common/components/DeleteNewsButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useState } from "react"
import { Fab, Tooltip, makeStyles } from "@material-ui/core"
import DeleteIcon from "@material-ui/icons/Delete"
import { red } from "@material-ui/core/colors"
import { DeleteSelectedNewsDialog } from "./DeleteSelectedNewsDialog"

const useDeleteNewsButtonStyles = makeStyles({
root: {
backgroundColor: red[700],
color: red[50],
"&:hover": {
backgroundColor: red[900],
},
},
})

const DeleteNewsButton = () => {
const [isDialogOpen, setIsDialogOpen] = useState(false)
const { root } = useDeleteNewsButtonStyles()
const handleClick = () => {
setIsDialogOpen(true)
}
const handleClose = () => {
setIsDialogOpen(false)
}
return (
<>
<Tooltip
title="Delete Selected News Articles"
aria-label="delete-news-articles">
<Fab className={root} onClick={handleClick}>
<DeleteIcon />
</Fab>
</Tooltip>
<DeleteSelectedNewsDialog open={isDialogOpen} onClose={handleClose} />
</>
)
}

export { DeleteNewsButton }
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Button,
Dialog,
DialogTitle,
DialogContent,
DialogContentText,
DialogActions,
} from "@material-ui/core"

type DeleteDialogProperties = {
open: boolean
onClose: () => void
}

const DeleteSelectedNewsDialog = ({
open,
onClose,
}: DeleteDialogProperties) => (
<Dialog open={open} onClose={onClose}>
<DialogTitle>Delete Content</DialogTitle>
<DialogContent>
<DialogContentText>
Are you sure you want to delete this content?
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={onClose}> Cancel </Button>
</DialogActions>
</Dialog>
)

export { DeleteSelectedNewsDialog }
80 changes: 63 additions & 17 deletions apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,81 @@
import { Typography, Grid } from "@material-ui/core"
import { Link } from "react-router-dom"
import { ChangeEvent } from "react"
import { useAtom } from "jotai"
import { pipe } from "fp-ts/function"
import { match as Bmatch } from "fp-ts/boolean"
import {
elem as Aelem,
uniq as Auniq,
filter as Afilter,
append as Aappend,
} from "fp-ts/Array"
import { Eq as SEq } from "fp-ts/string"
import {
Typography,
Grid,
Checkbox,

Check failure on line 15 in apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx#L15

[@typescript-eslint/no-unused-vars] 'Checkbox' is defined but never used.
List,

Check failure on line 16 in apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx#L16

[@typescript-eslint/no-unused-vars] 'List' is defined but never used.
ListItem,

Check failure on line 17 in apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx#L17

[@typescript-eslint/no-unused-vars] 'ListItem' is defined but never used.
ListItemIcon,

Check failure on line 18 in apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx#L18

[@typescript-eslint/no-unused-vars] 'ListItemIcon' is defined but never used.
} from "@material-ui/core"
import { Link } from "react-router-dom"
import { parseISO, format } from "date-fns/fp"
import { parseContentToText } from "@dictybase/editor"
import { truncateString } from "../utils/truncateString"
import { selectedNewsArticlesAtom } from "../../state"

type NewsItemProperties = {
id: string
name: string
content: string
updated_at: string
}

const EditableNewsItem = ({
id,
name,
content,
updated_at,
}: NewsItemProperties) => (
<Link to={`../news/${name}/editable`}>
<Grid container spacing={2} direction="column">
<Grid item>
<Typography variant="h2">
{pipe(updated_at, parseISO, format("PPPP"))}
</Typography>
</Grid>
<Grid item>
<Typography color="textPrimary">
{truncateString(parseContentToText(content), 400)}
</Typography>
}: NewsItemProperties) => {
const [selectedNewsArticles, setSelectedNewsArticles] = useAtom(
selectedNewsArticlesAtom,
)
const isChecked = pipe(selectedNewsArticles, Aelem(SEq)(id))

Check failure on line 42 in apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx#L42

[@typescript-eslint/no-unused-vars] 'isChecked' is assigned a value but never used.

const addToSelected = () => {
setSelectedNewsArticles(pipe(selectedNewsArticles, Aappend(id), Auniq(SEq)))
}

const removeFromSelected = () => {
setSelectedNewsArticles(
pipe(
selectedNewsArticles,
Afilter((element) => element !== id),
),
)
}

const handleChange = ({

Check failure on line 57 in apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/dicty-frontpage/src/common/components/EditableNewsItem.tsx#L57

[@typescript-eslint/no-unused-vars] 'handleChange' is assigned a value but never used.
target: { checked },
}: ChangeEvent<HTMLInputElement>) => {
pipe(checked, Bmatch(removeFromSelected, addToSelected))
}

return (
<Link to={`../news/${name}/editable`}>
<Grid container spacing={2} direction="column">
<Grid item>
<Typography variant="h2">
{pipe(updated_at, parseISO, format("PPPP"))}
</Typography>
</Grid>
<Grid item>
<Typography color="textPrimary">
{truncateString(parseContentToText(content), 400)}
</Typography>
</Grid>
</Grid>
</Grid>
</Link>
)
</Link>
)
}

export { EditableNewsItem }
1 change: 1 addition & 0 deletions apps/dicty-frontpage/src/pages/news/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const NewsView = ({ contentList }: NewsViewProperties) => {
Amap(({ id, name, content, created_at }) => (
<EditableNewsItem
key={id}
id={id}
name={name}
updated_at={created_at}
content={content}
Expand Down
5 changes: 4 additions & 1 deletion apps/dicty-frontpage/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ import { Option, none } from "fp-ts/Option"

const contentIdAtom = atom<Option<string>>(none)

export { contentIdAtom }
// News Content IDs
const selectedNewsArticlesAtom = atom<Array<string>>([])

export { contentIdAtom, selectedNewsArticlesAtom }
Loading