Skip to content

Commit

Permalink
UI: resplit one component per file, clean a bit of JS style (thanks #127
Browse files Browse the repository at this point in the history
 again!)
  • Loading branch information
jaesivsm committed May 13, 2020
1 parent 16d2f8f commit 6f1e72a
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { connect } from "react-redux";
import Button from "@material-ui/core/Button";
import FormControl from "@material-ui/core/FormControl";
// jarr
import { closePanel } from "./editSlice";
import { doCreateObj, doEditObj } from "../feedlist/feedSlice";
import ClusterSettings from "./common/ClusterSettings";
import DeleteButton from "./common/DeleteButton";
import StateTextInput from "./common/StateTextInput";
import ClusterSettings from "../common/ClusterSettings";
import DeleteButton from "../common/DeleteButton";
import StateTextInput from "../common/StateTextInput";

import editPanelStyle from "./editPanelStyle";
import { closePanel } from "../editSlice";
import editPanelStyle from "../editPanelStyle";
import { doCreateObj, doEditObj } from "../../feedlist/feedSlice";

const mapDispatchToProps = (dispatch) => ({
commit(e, job) {
Expand All @@ -35,8 +35,7 @@ function AddEditCategory({ job, catId, commit }) {
return (
<form onSubmit={(e) => commit(e, job)}>
<FormControl component="fieldset">
<StateTextInput label="Category name" name="name"
className={classes.editPanelInput} />
<StateTextInput label="Category name" name="name" />
<ClusterSettings level="category" />
<div className={classes.editPanelButtons}>
<Button className={classes.editPanelBtn} variant="contained" color="primary" type="submit">
Expand Down
10 changes: 5 additions & 5 deletions jsclient/src/features/editpanel/EditPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import IconButton from "@material-ui/core/IconButton";
import Close from "@material-ui/icons/Close";
import CircularProgress from "@material-ui/core/CircularProgress";
// jarr
import BuildFeed from "./BuildFeed";
import AddEditFeed from "./AddEditFeed";
import AddEditCategory from "./AddEditCategory";
import BuildFeed from "./Feed/Build";
import AddEditFeed from "./Feed";
import AddEditCategory from "./Category";
import SettingsPanel from "./SettingsPanel";
import { closePanel } from "./editSlice";
import editPanelStyle from "./editPanelStyle";
Expand All @@ -29,7 +29,7 @@ function mapStateToProps(state) {
};
}

function EditPanel({ isOpen, isLoading, job, objType, close }) {
const EditPanel = ({ isOpen, isLoading, job, objType, close }) => {
const classes = editPanelStyle();
let form;
if (isLoading) {
Expand Down Expand Up @@ -69,7 +69,7 @@ function EditPanel({ isOpen, isLoading, job, objType, close }) {
</div>
</Drawer>
);
}
};

EditPanel.propTypes = {
isOpen: PropTypes.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import IconButton from "@material-ui/core/IconButton";
import FormControl from "@material-ui/core/FormControl";
import HelpIcon from "@material-ui/icons/Help";
// jarr
import editPanelStyle from "./editPanelStyle";
import { doBuildFeed } from "./editSlice";
import editPanelStyle from "../editPanelStyle";
import { doBuildFeed } from "../editSlice";

const mapDispatchToProps = (dispatch) => ({
doBuildFeed(e, feedUrl) {
Expand Down
109 changes: 109 additions & 0 deletions jsclient/src/features/editpanel/Feed/FilterSettings/Line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React from "react";
import PropTypes from "prop-types";
import { createSelector } from "reselect";
import { connect, useDispatch } from "react-redux";
// material ui components
import Select from "@material-ui/core/Select";
import MenuItem from "@material-ui/core/MenuItem";
import TextField from "@material-ui/core/TextField";
import IconButton from "@material-ui/core/IconButton";
import FormControl from "@material-ui/core/FormControl";
// material icons
import MinusIcon from "@material-ui/icons/Remove";
import ArrowUpIcon from "@material-ui/icons/ArrowUpward";
import ArrowDownIcon from "@material-ui/icons/ArrowDownward";
// jarr
import style from "./style";
import { moveUpFilter, moveDownFilter, editFilter, removeFilter
} from "../../editSlice";
// constants
const FiltersAction = { "mark as read": "mark as read",
"mark as unread": "mark as unread (default)",
"mark as favorite": "mark as liked",
"mark as unliked": "mark as unliked (default)",
"skipped": "skip",
"unskipped": "unskip (default)",
"allow clustering": "allow clustering (default)",
"disallow clustering": "forbid clustering"};
const FiltersType = { "regex": "title match (regex)",
"simple match": "title contains",
"exact match": "title is",
"tag match": "one of the tag is",
"tag contains": "one of the tags contains" };
const FiltersTrigger = {"match": "If", "no match": "If not", };

const getFilter = (state, props) => state.edit.loadedObj.filters[props.index];
const makeGetFilter = () => createSelector([ getFilter ], (filter) => filter);

const makeMapStateToProps = () => {
const madeGetFilter = makeGetFilter();
const mapStateToProps = (state, props) => {
return { filter: madeGetFilter(state, props) };
}
return mapStateToProps
}

function FilterSettingLine({ index, position, filter }) {
let moveUpBtn;
let moveDownBtn;
const dispatch = useDispatch();
const classes = style();
if (position !== "first") {
moveUpBtn = (
<IconButton onClick={() => dispatch(moveUpFilter(index))}
className={classes.editPanelFilterArrow} color="primary">
<ArrowUpIcon />
</IconButton>);
}
if (position !== "last") {
moveDownBtn = (
<IconButton onClick={() => dispatch(moveDownFilter(index))}
className={classes.editPanelFilterArrow} color="primary">
<ArrowDownIcon />
</IconButton>
);
}
const onChange = (key) => (e) => dispatch(editFilter({ index, key, value: e.target.value }));
return (
<div className={classes.editPanelFilter}>
<div className={classes.editPanelFilterArrows}>
{moveUpBtn}{moveDownBtn}
</div>
<FormControl key="trigger" className={classes.editPanelFilterItem}>
<Select value={filter["action on"]} onChange={onChange("action on")}>
{Object.entries(FiltersTrigger).map(([trigger, label]) => (
<MenuItem key={trigger} value={trigger}>{label}</MenuItem>
))}
</Select>
</FormControl>
<FormControl key="type" className={classes.editPanelFilterItem}>
<Select value={filter.type} onChange={onChange("type")}>
{Object.entries(FiltersType).map(([type, label]) => (
<MenuItem key={type} value={type}>{label}</MenuItem>
))}
</Select>
</FormControl>
<FormControl key="pattern" className={classes.editPanelFilterItem}>
<TextField value={filter.pattern} required onChange={onChange("pattern")} />
</FormControl>
<FormControl key="action" className={classes.editPanelFilterItem}>
<Select value={filter.action} onChange={onChange("action")} >
{Object.entries(FiltersAction).map(([action, label]) => (
<MenuItem key={action} value={action}>{label}</MenuItem>
))}
</Select>
</FormControl>
<IconButton color="primary" onClick={() => dispatch(removeFilter(index))}
className={classes.editPanelFilterDelBtn}>
<MinusIcon />
</IconButton>
</div>
);
}

FilterSettingLine.propTypes = {
index: PropTypes.number.isRequired,
position: PropTypes.string.isRequired,
};

export default connect(makeMapStateToProps)(FilterSettingLine);
86 changes: 86 additions & 0 deletions jsclient/src/features/editpanel/Feed/FilterSettings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { useState } from "react";
import { connect } from "react-redux";
import PropTypes from "prop-types";
// material ui components
import Fab from "@material-ui/core/Fab";
import Alert from "@material-ui/lab/Alert";
import Typography from "@material-ui/core/Typography";
import IconButton from "@material-ui/core/IconButton";
import ExpansionPanel from "@material-ui/core/ExpansionPanel";
import ExpansionPanelSummary from "@material-ui/core/ExpansionPanelSummary";
import ExpansionPanelDetails from "@material-ui/core/ExpansionPanelDetails";
// material icons
import HelpIcon from "@material-ui/icons/Help";
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
import PlusIcon from "@material-ui/icons/Add";
// jarr
import editPanelStyle from "../../editPanelStyle";
import style from "./style";
import FilterSettingLine from "./Line";
import { addFilter } from "../../editSlice";

export function mapStateToProps(state) {
return { filters: (state.edit.loadedObj.filters
? state.edit.loadedObj.filters
: []).map((filter) => filter.id),
};
};

const mapDispatchToProps = (dispatch) => ({
add() {
dispatch(addFilter());
},
});

function FilterSettings({ filters, add }) {
const filterClasses = style();
const classes = editPanelStyle();
const [showHelp, setShowHelp] = useState(false);
let help;
if(showHelp) {
help = (
<Alert>
<p>Filters are processed in the order you place them on every new articles that will be fetched for that feed.</p>
<p>Through filters you can modify the read, liked status, allow or forbid clustering new articles. You can also skip entierly the creation of an article match a filter.</p>
<p>Filters are processed one after another and you can revert the filter you applied just before. For example you might want to skip every article which title contains &quot;Python&quot; and &apos;unskip&apos; every article containing &quot;Monthy&quot;. This way you would see every article mentionning &quot;Monthy Python&quot; but none about python solely.</p>
</Alert>
);
}
return (
<ExpansionPanel className={classes.editPanelCluster} >
<ExpansionPanelSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography className={classes.heading}>Filters Settings</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails className={classes.editPanelClusterSettings}>
<IconButton onClick={() => setShowHelp(!showHelp)}
className={classes.showHelpButton}>
<HelpIcon />
</IconButton>
{help}
{filters.map((filter, i) =>
<FilterSettingLine
key={filter}
index={i}
position={i === 0 ? "first": (i === filters.length -1 ? "last": "none")}
/>
)}
<div className={filterClasses.editPanelFilterAddBtn}>
<Fab onClick={add} color="primary">
<PlusIcon />
</Fab>
</div>
</ExpansionPanelDetails>
</ExpansionPanel>
);
}

FilterSettings.propTypes = {
filters: PropTypes.array.isRequired,
add: PropTypes.func.isRequired,
};

export default connect(mapStateToProps, mapDispatchToProps)(FilterSettings);
61 changes: 61 additions & 0 deletions jsclient/src/features/editpanel/Feed/FilterSettings/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { makeStyles, Theme, createStyles } from "@material-ui/core/styles";

export default makeStyles((theme: Theme) =>
createStyles({
editPanelFilter: {
display: "table",
alignItems: "baseline",
flexDirection: "row",
marginBottom: 25,
marginLeft: 16,
marginRight: 16
},
editPanelFilterItem: {
display: "table-cell",
"& .MuiInput-root": {
height: 32,
justifyContent: "center"
},
"& .MuiTextField-root": {
height: 32,
justifyContent: "center",
"& input": {
padding: 0
}
}
},
editPanelFilterArrows: {
display: "flex",
flexDirection: "column",
justifyContent: "center",
left: 5,
position: "absolute"
},
editPanelFilterArrow: {
position: "relative",
padding: 0,
"& svg": {
height: 18,
width: 18,
}
},
editPanelFilterAddBtn: {
textAlign: "center",
width: "100%",
"& button": {
minHeight: "unset",
height: 35,
width: 35,
}
},
editPanelFilterDelBtn: {
position: "absolute",
right: 0,
padding: 8,
"& svg": {
height: 18,
width: 18
}
},
}),
);
52 changes: 52 additions & 0 deletions jsclient/src/features/editpanel/Feed/ProposedLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
// material components
import Select from "@material-ui/core/Select";
import MenuItem from "@material-ui/core/MenuItem";
import FormControl from "@material-ui/core/FormControl";
import FormHelperText from "@material-ui/core/FormHelperText";
// jarr
import editPanelStyle from "../editPanelStyle";
import { editLoadedObj } from "../editSlice";

function mapStateToProps(state) {
return { link: state.edit.loadedObj.link,
links: state.edit.loadedObj.links,
};
}

const mapDispatchToProp = (dispatch) => ({
edit(value) {
dispatch(editLoadedObj({ key: "link", value }));
}
});

function ProposedLinks({ link, links, edit }) {
const classes = editPanelStyle();
if (!links) {
return null;
}
return (
<FormControl>
<FormHelperText>Other possible feed link have been found :</FormHelperText>
<Select variant="outlined" value={link}
onChange={(e) => edit(e.target.value)}
className={classes.editPanelInput}
>
{links.map((proposedLink) => (
<MenuItem key={`l${links.indexOf(proposedLink)}`}
value={proposedLink}>{proposedLink}</MenuItem>
))}
</Select>
</FormControl>
);
}

ProposedLinks.propTypes = {
link: PropTypes.string,
links: PropTypes.array,
edit: PropTypes.func.isRequired,
};

export default connect(mapStateToProps, mapDispatchToProp)(ProposedLinks)
Loading

0 comments on commit 6f1e72a

Please sign in to comment.