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

Add tags functionality implemented #108

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/components/Card/CardWithoutPicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const useStyles = makeStyles(theme => ({
padding: "5px"
},
time: {
marginLeft:"2%",
lineHeight: "1"
},
small: {
Expand Down Expand Up @@ -100,6 +101,8 @@ export default function CardWithoutPicture({ tutorial }) {
return timestamp.toDate().toDateString();
};



return (
<Card className={classes.root} data-testId="codelabz">
<CardHeader
Expand Down Expand Up @@ -161,14 +164,16 @@ export default function CardWithoutPicture({ tutorial }) {
</CardContent>
</Link>
<CardActions className={classes.settings} disableSpacing>
{tutorial?.tags.map((tag, index) => (
<Chip
label="HTML"
key={index}
label={tag}
component="a"
href="#chip"
href={`#${tag}`}
clickable
variant="outlined"
className={classes.margin}
/>
))}
<Typography
variant="overline"
display="block"
Expand Down
1 change: 1 addition & 0 deletions src/components/HomePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function HomePage({ background = "white", textColor = "black" }) {
}
}) => homepageFeedArray
);
// console.log(tutorials, "tutorials")

const notification = () => {};
const handleChange = (event, newValue) => {
Expand Down
110 changes: 101 additions & 9 deletions src/components/Tutorials/NewTutorial/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createTutorial } from "../../../store/actions";
import { useFirebase, useFirestore } from "react-redux-firebase";
import { useHistory } from "react-router-dom";
import Button from "@mui/material/Button";
import { Alert, Box } from "@mui/material";
import { Alert, Box,Chip } from "@mui/material";
import TextField from "@mui/material/TextField";
import Divider from "@mui/material/Divider";
import { IconButton } from "@mui/material";
Expand All @@ -32,6 +32,48 @@ const useStyles = makeStyles(theme => ({
purple: {
color: deepPurple[700],
backgroundColor: deepPurple[500]
},
tagsInput: {
display: 'flex',
flexWrap: 'wrap',
minHeight: 48,
width: 480,
border: '1px solid rgb(214, 216, 218)',
borderRadius: 6,
// outline: '1px solid #673ab7',
'& input': {
flex: 1,
border: 'none',
height: 46,
fontSize: 14,
padding: '4px 0 0 0',
'&:focus': {
outline: 'none',
},
},
},
tagsContainer: {
display: 'flex',
flexWrap: 'wrap',
padding: 0,
margin: '8px 0 0 0',
},
tag: {
margin: '0 8px 8px 0',
},
tagInput:{
border: 'none',
width: "100%",
height:"100%",
textAlign:"center",
// height: 46,
// border:"1px solid white" ,
fontSize: 14,
outline:"none",
'&:focus': {
outline: 'none',
},

}
}));

Expand All @@ -43,6 +85,9 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
const [visible, setVisible] = useState(false);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [tags, setTags] = useState([]);
const [tagsInput, setTagsInput] = useState('');
const [tagsInputClicked, setTagsInputClicked] = useState(false);
const [formValue, setformValue] = useState({
title: "",
summary: "",
Expand Down Expand Up @@ -103,14 +148,14 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
const orgList =
allowOrgs > 0
? organizations
.map((org, i) => {
if (org.permissions.includes(3) || org.permissions.includes(2)) {
return org;
} else {
return null;
}
})
.filter(Boolean)
.map((org, i) => {
if (org.permissions.includes(3) || org.permissions.includes(2)) {
return org;
} else {
return null;
}
})
.filter(Boolean)
: null;

useEffect(() => {
Expand All @@ -122,6 +167,7 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
const tutorialData = {
...formValue,
created_by: userHandle,
tags: tags,
is_org: userHandle !== formValue.owner,
completed: false
};
Expand All @@ -146,6 +192,22 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
};

const classes = useStyles();


const removeTags = (indexToRemove) => {
setTags(tags.filter((_, index) => index !== indexToRemove));
};

const addTags = (event) => {
if (event.target.value !== '') {
setTags([...tags, event.target.value]);
event.target.value = '';
setTagsInput('');
console.log(tagsInput)
}

};

return (
<Modal
open={visible}
Expand All @@ -154,6 +216,8 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
aria-describedby="simple-modal-description"
style={{
display: "flex",
maxWidth: "50%",
marginLeft: "25%",
alignItems: "center",
justifyContent: "center"
}}
Expand Down Expand Up @@ -200,6 +264,7 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
prefix={
<AppstoreAddOutlined style={{ color: "rgba(0,0,0,.25)" }} />
}
onClick={()=>setTagsInputClicked(false)}
placeholder="Title of the Tutorial"
autoComplete="title"
name="title"
Expand All @@ -215,6 +280,7 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
prefix={
<AppstoreAddOutlined style={{ color: "rgba(0,0,0,.25)" }} />
}
onClick={()=>setTagsInputClicked(false)}
fullWidth
variant="outlined"
name="summary"
Expand All @@ -226,6 +292,32 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
style={{ marginBottom: "2rem" }}
/>

<div className={classes.tagsInput} style={{outline: tagsInputClicked ? '1px solid #673ab7 ' : ''}} onClick={()=>setTagsInputClicked(true)} >
<div className={classes.tagsContainer}>
{tags.map((tag, index) => (
<Chip
key={index}
label={tag}
onDelete={() => removeTags(index)}
className={classes.tag}
/>
))}
</div>
<TextField
type="text"
variant="standard"
className={classes.tagInput}
value={tagsInput}
onChange={(event) => setTagsInput(event.target.value)}
InputProps={{
disableUnderline: true,
inputProps: { style: { marginLeft: '14px',border:"none !important",outline:"none !important" } },
}}
onKeyUp={(event) => (event.key === 'ArrowUp' ? addTags(event) : null)}
placeholder="Press ArrowUp key to add tags"
/>
</div>

<IconButton>
<ImageIcon />
</IconButton>
Expand Down
1 change: 1 addition & 0 deletions src/store/actions/tutorialPageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const getTutorialFeedData =
title: tutorial?.title,
summary: tutorial?.summary,
owner: tutorial?.owner,
tags: tutorial?.tags,
created_by: tutorial?.created_by,
createdAt: tutorial?.createdAt,
featured_image: tutorial?.featured_image
Expand Down
Loading