Skip to content

Commit

Permalink
FINISHED all logic :)
Browse files Browse the repository at this point in the history
  • Loading branch information
yulev5 committed Apr 30, 2021
1 parent 6a1e282 commit 2831d80
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/AppBarComponents/MyLocationsAppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const useStyles = makeStyles((theme) => ({
function MyLocationsAppBar({ categories, currentSelectedCategory }) {
const classes = useStyles();

debugger;
let appBarTitle = "Categories";
if (currentSelectedCategory) {
appBarTitle = categories.find(cat => cat.id == currentSelectedCategory).name;
Expand Down
11 changes: 8 additions & 3 deletions src/Categories/CategoriesListView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { List, ListItemText, makeStyles } from '@material-ui/core';
import ListItem from '@material-ui/core/ListItem';
import { connect } from "react-redux"
Expand All @@ -22,10 +22,11 @@ const useStyles = makeStyles((theme) => ({
},
}));

function Categories({ categories, setContext, saveSelectedCategory }) {
function Categories({ categories, currentSelectedCategory, setContext, saveSelectedCategory }) {
const classes = useStyles();
const [boldListItem, setBoldListItem] = React.useState();

debugger;
const handleListItemClick = (index, cat) => {
if (index === boldListItem) {
handleClearSelection();
Expand Down Expand Up @@ -59,6 +60,11 @@ function Categories({ categories, setContext, saveSelectedCategory }) {
</ListItem>
}

useEffect(() => {
if(!currentSelectedCategory){
setBoldListItem();
}
}, [currentSelectedCategory]);

return (
<div className={classes.categoriesListContainer}>
Expand All @@ -82,7 +88,6 @@ const mapStateToProps = state => {
return {
categories: state.categoriesReducer.categories,
currentSelectedCategory: state.selectedCategoryReducer.currentSelectedCategory,
currentContext: state.contextReducer.currentContext,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Content/Delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useStyles = makeStyles((theme) => ({
}
}));

function Delete({ categories, currentSelectedCategory, currentContext, setContext, deleteCategory }) {
function Delete({ categories, currentSelectedCategory, currentContext, setContext, deleteCategory, saveSelectedCategory }) {
const classes = useStyles();

let currentEditingCategory = categories.find(cat => cat.id == currentSelectedCategory)
Expand Down
18 changes: 6 additions & 12 deletions src/Content/ViewCategoryDetails.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, makeStyles, TextField, Typography } from '@material-ui/core';
import { Button, makeStyles, Typography } from '@material-ui/core';
import React, { useRef } from 'react';
import { connect } from "react-redux"
import { INITIAL_CONTEXT, VIEW_CATEGORY_DETAILS } from '../../redux/contextTypes';
import { CATEGORY_SELECTED, INITIAL_CONTEXT, VIEW_CATEGORY_DETAILS } from '../../redux/contextTypes';
import { setContext } from "../../redux/actions/main"

const useStyles = makeStyles((theme) => ({
Expand All @@ -28,31 +28,25 @@ const useStyles = makeStyles((theme) => ({
}
}));

function ViewCategoryDetails(props) {
function ViewCategoryDetails({ categories, currentSelectedCategory, currentContext, setContext }) {
const classes = useStyles();
const { categories, currentSelectedCategory, currentContext, setContext, addCategory } = props
const catNewNameRef = useRef();

let currentEditingCategory = categories.find(cat => cat.id == currentSelectedCategory)

function handleSubmit(event) {
event.preventDefault();
addCategory({ name: catNewNameRef.current.value, id: currentEditingCategory.id });
setContext(INITIAL_CONTEXT);
setContext(CATEGORY_SELECTED);
}

function cancelAddingNewCat() {
setContext(INITIAL_CONTEXT);
}


return (
<>
{currentContext === VIEW_CATEGORY_DETAILS &&
(
<form className={classes.formContainer} onSubmit={handleSubmit}>
<Typography variant="h6" className={classes.header}>Category {currentEditingCategory.name} Details:</Typography>
<Typography style={{ marginTop: '30px' }}>Name: {currentEditingCategory.name}</Typography>
<Button className={classes.button} variant="contained" onClick={() => cancelAddingNewCat()}>Close</Button>
<Button className={classes.button} variant="contained" type="submit">Close</Button>
</form>
)
}
Expand Down

1 comment on commit 2831d80

@vercel
Copy link

@vercel vercel bot commented on 2831d80 Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.