From 4fb217aa0f97a709fd18c233119ba903a0f8b12a Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Thu, 29 Jul 2021 17:46:59 +0545 Subject: [PATCH 01/27] news add modal ui --- .../newsCreateModal/NewsCreateModal.scss | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/newsCreateModal/NewsCreateModal.scss b/src/components/newsCreateModal/NewsCreateModal.scss index c02af3aaf..5d5c6c2e6 100644 --- a/src/components/newsCreateModal/NewsCreateModal.scss +++ b/src/components/newsCreateModal/NewsCreateModal.scss @@ -184,7 +184,7 @@ top: 50%; left: 50%; transform: translate(-50%, -50%); - background-color: var(--primary-black); + background-color: var(--cards); border-radius: 0.4em; @media (max-width: 768px) { @@ -201,8 +201,8 @@ } .input-container { .block { - border: 1px solid var(--primary-grey); - background-color: var(--popups); + border: 1px solid var(--dropdowns); + background-color: var(--cards); .label { width: 100%; margin-left: 2.5em; @@ -219,9 +219,9 @@ } .textarea { margin-bottom: 1.5em; - border: 1px solid var(--primary-grey); + border: 1px solid var(--dropdowns); outline: none; - background-color: var(--popups); + background-color: var(--cards); color: #ffff; font-size: 1.05em; font-family: inherit; @@ -282,9 +282,9 @@ } .video-row-3 { input { - border: 1px solid var(--primary-grey); + border: 1px solid var(--dropdowns); outline: none; - background-color: var(--popups); + background-color: var(--cards); color: #ffff; font-size: 1.05em; font-family: inherit; From 975df155b68dd28ec8063a8e45f2ab84ad521d7d Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Thu, 29 Jul 2021 17:56:11 +0545 Subject: [PATCH 02/27] scss lint fix --- .../newsCreateModal/NewsCreateModal.scss | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/newsCreateModal/NewsCreateModal.scss b/src/components/newsCreateModal/NewsCreateModal.scss index 5d5c6c2e6..54d794048 100644 --- a/src/components/newsCreateModal/NewsCreateModal.scss +++ b/src/components/newsCreateModal/NewsCreateModal.scss @@ -54,6 +54,7 @@ .last-input-variation { width: 45%; } + .full { width: 100% !important; } @@ -87,11 +88,13 @@ font-size: 11px; width: 50%; } + .errorMsg { color: var(--secondary-red); margin: 0.5em 0 1em 0; font-size: 1em; } + .error { border-color: var(--secondary-red); &:focus { @@ -107,7 +110,6 @@ padding: 1.4em 1em; border: 0.5px solid var(--primary-white); background: var(--background-color-light); - outline: none; cursor: pointer; position: relative; @@ -119,14 +121,17 @@ img.avatar { display: none; } + img.drag-drop-close { right: 0; top: 0; } + .videoName { color: #fff; z-index: 1; } + .drag-drop-icon-container { width: 100%; height: 100%; @@ -151,6 +156,7 @@ } } } + .videoUploadBtn::-webkit-file-upload-button { display: none; } @@ -160,6 +166,7 @@ flex-wrap: wrap; text-align: center; } + .video-row-3 > input, span { width: 100% !important; @@ -195,6 +202,7 @@ .toggle-container { background: var(--cards); } + .active + .toggle-container { background: var(--primary-color); } @@ -203,10 +211,12 @@ .block { border: 1px solid var(--dropdowns); background-color: var(--cards); + .label { width: 100%; margin-left: 2.5em; } + .inputField { padding: 1.2em 0; color: #fff; @@ -217,6 +227,7 @@ } } } + .textarea { margin-bottom: 1.5em; border: 1px solid var(--dropdowns); @@ -242,6 +253,7 @@ } } } + .drag-drop-container { width: 100%; height: 15em; @@ -252,6 +264,7 @@ position: relative; overflow: hidden; } + .drag-drop { height: 100%; border: none; @@ -280,6 +293,7 @@ margin-bottom: 1.5em; } } + .video-row-3 { input { border: 1px solid var(--dropdowns); @@ -302,14 +316,17 @@ margin: 0; } } + .dragDropText { color: #ffff; height: auto; } + @media (max-width: 768px) { span { margin: 0.8em 0; } + .videoUploadBtn { width: 100% !important; @@ -320,6 +337,7 @@ } } } + &__text { .input-container { margin-bottom: 1.5em; From 0195fb227d2fc4ec921c123a072e407ccf2dc5e4 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Thu, 29 Jul 2021 18:09:41 +0545 Subject: [PATCH 03/27] scss fix part 2 --- src/components/newsCreateModal/NewsCreateModal.scss | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/newsCreateModal/NewsCreateModal.scss b/src/components/newsCreateModal/NewsCreateModal.scss index 54d794048..3b1744aa2 100644 --- a/src/components/newsCreateModal/NewsCreateModal.scss +++ b/src/components/newsCreateModal/NewsCreateModal.scss @@ -97,6 +97,7 @@ .error { border-color: var(--secondary-red); + &:focus { border-color: var(--secondary-red) !important; } @@ -207,6 +208,7 @@ background: var(--primary-color); } } + .input-container { .block { border: 1px solid var(--dropdowns); @@ -239,18 +241,19 @@ &__error { border-color: var(--secondary-red); + &:focus { border-color: var(--secondary-red) !important; } } - &:focus { - border-color: var(--primary-color); - } - &::-webkit-input-placeholder { color: var(--primary-grey); } + + &:focus { + border-color: var(--primary-color); + } } } From 0ca05c00242ca24c3a7ebdc4dd4b4d0f582f3937 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Mon, 2 Aug 2021 17:53:59 +0545 Subject: [PATCH 04/27] news modal: same component for course and news --- src/App.jsx | 2 +- .../btnCollection/BtnCollection.jsx | 40 +++ .../btnCollection/BtnCollection.scss | 0 src/components/newAddModal/NewsAddModal.jsx | 17 +- src/screens/communityNews/newsAdd/NewsAdd.jsx | 333 +++++++++++------- .../courseManager/addLesson/AddContent.jsx | 31 +- 6 files changed, 271 insertions(+), 152 deletions(-) create mode 100644 src/components/btnCollection/BtnCollection.jsx create mode 100644 src/components/btnCollection/BtnCollection.scss diff --git a/src/App.jsx b/src/App.jsx index 2e71c6150..f85b20d67 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -73,7 +73,7 @@ function App () { - + diff --git a/src/components/btnCollection/BtnCollection.jsx b/src/components/btnCollection/BtnCollection.jsx new file mode 100644 index 000000000..ff335273e --- /dev/null +++ b/src/components/btnCollection/BtnCollection.jsx @@ -0,0 +1,40 @@ +import React from 'react' +import Text from '../../screens/courseManager/addLesson/Text' +import Image from '../lessonImage/Image' +import Video from '../videoPlayer/Video' + +const BtnCollection = ({data, setVideoModal, setImageModal, setTextModal}) => { + return ( + <> + {data.length && + data.map((vid, index) => ( +
+
+ ))} +
+ + + +
+ + ) +} + +export default BtnCollection diff --git a/src/components/btnCollection/BtnCollection.scss b/src/components/btnCollection/BtnCollection.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/components/newAddModal/NewsAddModal.jsx b/src/components/newAddModal/NewsAddModal.jsx index c81e0b48d..24575aac0 100644 --- a/src/components/newAddModal/NewsAddModal.jsx +++ b/src/components/newAddModal/NewsAddModal.jsx @@ -1,6 +1,6 @@ import { useState } from 'react' import './NewsAddModal.scss' -import { Link } from 'react-router-dom' +import { Link, useHistory } from 'react-router-dom' import { useDispatch } from 'react-redux' import { newsUpdate } from '../../actions/newsActions' @@ -11,6 +11,8 @@ const NewsAddModal = ({ setAddModal, editData, setEditData }) => { const [titleError, setTitleError] = useState() const [categoryError, setCategoryError] = useState() + const history = useHistory(); + const dispatch = useDispatch() const titleChange = (e) => { setTitle(e.target.value) @@ -50,11 +52,16 @@ const NewsAddModal = ({ setAddModal, editData, setEditData }) => { - {editData + { + editData ? - : - - } + : + } ) diff --git a/src/screens/communityNews/newsAdd/NewsAdd.jsx b/src/screens/communityNews/newsAdd/NewsAdd.jsx index e62dff06e..4766043b2 100644 --- a/src/screens/communityNews/newsAdd/NewsAdd.jsx +++ b/src/screens/communityNews/newsAdd/NewsAdd.jsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useLayoutEffect, useState } from 'react' import NewsCreateModal from '../../../components/newsCreateModal/NewsCreateModal' import DashboardLayout from '../../../layout/dashboardLayout/DashboardLayout' import { useParams, useHistory } from 'react-router-dom' @@ -7,6 +7,12 @@ import BackButton from '../../../components/backButton/BackButton' import CommunityNewsViewPage from '../../communityNewsView/CommunityNewsView' import { useDispatch, useSelector } from 'react-redux' import { createNews } from '../../../actions/newsActions' +import AddContent from '../../courseManager/addLesson/AddContent' +import { useForm } from 'react-hook-form' +import { useEffect } from 'react' +import { useLocation } from 'react-router-dom/cjs/react-router-dom.min' +import { ErrorText, TextArea } from '../../../components/formUI/FormUI' +import BtnCollection from '../../../components/btnCollection/BtnCollection' const NewsAdd = () => { const { currentCommunity } = useSelector(state => state.activeCommunity) @@ -16,152 +22,243 @@ const NewsAdd = () => { const [videoActive, setVideoActive] = useState(true) const [imageActive, setImageActive] = useState(true) const [textActive, setTextActive] = useState(true) + const [newsData, setNewsData] = useState([]) + const news = useSelector((state) => (state.addNewNews !== {} ? state.addNewNews : '')) + const { register, errors, handleSubmit } = useForm() + + const { title} = useParams() + + const dispatch = useDispatch(); - const { title, category } = useParams() + // fetching category from route + const {state} = useLocation(); + const {category} = state; + + useEffect(() => { + setNewsData([{title, category}]) + }, []) + + const submitNewsForm = ({ title }) => { + console.log(newsData); + // const order = fetchLesson.length + 1 + // dispatch( + // createLesson({ + // title, + // category, + // coverImg, + // }) + // ) + } return ( <> - {createVideoModal && } - {createImageModal && } - {createTextModal && } + {createVideoModal && } + {createImageModal && } + {createTextModal && } - + + ) } -function NewsAddMainContainer ({ - setCreateVideoModal, - setCreateImageModal, - setCreateTextModal, - setVideoActive, - setImageActive, - setTextActive, - news, - title, - category - -}) { - function createVideo () { - setCreateVideoModal(true) - setCreateImageModal(false) - setCreateTextModal(false) - setVideoActive(true) - } - - function createImage () { - setCreateVideoModal(false) - setCreateImageModal(true) - setCreateTextModal(false) - setImageActive(true) - } +const AddNewsContent = ({ + errors, + newsData, + setVideoModal, + setImageModal, + setTextModal, + register +}) => { - function createText () { - setCreateVideoModal(false) - setCreateImageModal(false) - setCreateTextModal(true) - setTextActive(true) - } + const [title, setTitle] = useState(''); + + useEffect(() => { + if(newsData.length) { + setTitle(newsData[0].title) + } + }, [newsData]) - return ( -
- + -
{Object.entries(news).length !== 0 && }
+ + +
- ) } -function NewsAddContainer ({ createVideo, createImage, createText, title, news }) { +const NewsSaveModal = ({ pathId, onClick }) => { + const history = useHistory() return ( -
- -
- - -
) } -function NewContent ({ title, news }) { - return ( - <> -
-

{title}

- {news && } -
- - ) -} +// function NewsAddMainContainer ({ +// setCreateVideoModal, +// setCreateImageModal, +// setCreateTextModal, +// setVideoActive, +// setImageActive, +// setTextActive, +// news, +// title, +// category -function PopUp ({ news, title, category }) { - const { file } = news.imageDetail ? news.imageDetail.file && news.imageDetail : {} - const newNews = { ...news, title, category, file } - const [activePopup, setActivePopup] = useState(true) - const { currentCommunity } = useSelector(state => state.activeCommunity) - const dispatch = useDispatch() - const history = useHistory() - const handleOnSaveClick = (e) => { - if (file) { - dispatch(createNews(newNews)) - setActivePopup(false) - history.push(`/community-page-news/${currentCommunity.slug}`) - } else { - dispatch(createNews(newNews)) - setActivePopup(false) - history.push(`/community-page-news/${currentCommunity.slug}`) - } - } +// }) { +// function createVideo () { +// setCreateVideoModal(true) +// setCreateImageModal(false) +// setCreateTextModal(false) +// setVideoActive(true) +// } - const handleOnCancelClick = (e) => { - setActivePopup(false) - history.push(`/community-page-news/${currentCommunity.slug}`) - } - return ( - <> - {activePopup && ( -
-

Do you want to save?

-
- - -
-
- )} - - ) -} +// function createImage () { +// setCreateVideoModal(false) +// setCreateImageModal(true) +// setCreateTextModal(false) +// setImageActive(true) +// } + +// function createText () { +// setCreateVideoModal(false) +// setCreateImageModal(false) +// setCreateTextModal(true) +// setTextActive(true) +// } + +// return ( +//
+// +//
{Object.entries(news).length !== 0 && }
+//
+// ) +// } + +// function NewsAddContainer ({ createVideo, createImage, createText, title, news }) { +// return ( +//
+// +//
+// +// +// +//
+//
+// ) +// } + +// function NewContent ({ title, news }) { +// return ( +// <> +//
+//

{title}

+// {news && } +//
+// +// ) +// } + +// function PopUp ({ news, title, category }) { +// const { file } = news.imageDetail ? news.imageDetail.file && news.imageDetail : {} +// const newNews = { ...news, title, category, file } +// const [activePopup, setActivePopup] = useState(true) +// const { currentCommunity } = useSelector(state => state.activeCommunity) +// const dispatch = useDispatch() +// const history = useHistory() +// const handleOnSaveClick = (e) => { +// if (file) { +// dispatch(createNews(newNews)) +// setActivePopup(false) +// history.push(`/community-page-news/${currentCommunity.slug}`) +// } else { +// dispatch(createNews(newNews)) +// setActivePopup(false) +// history.push(`/community-page-news/${currentCommunity.slug}`) +// } +// } + +// const handleOnCancelClick = (e) => { +// setActivePopup(false) +// history.push(`/community-page-news/${currentCommunity.slug}`) +// } +// return ( +// <> +// {activePopup && ( +//
+//

Do you want to save?

+//
+// +// +//
+//
+// )} +// +// ) +// } export default NewsAdd diff --git a/src/screens/courseManager/addLesson/AddContent.jsx b/src/screens/courseManager/addLesson/AddContent.jsx index 177a1b3b8..687588009 100644 --- a/src/screens/courseManager/addLesson/AddContent.jsx +++ b/src/screens/courseManager/addLesson/AddContent.jsx @@ -1,8 +1,10 @@ +import React, { useEffect, useLayoutEffect, useState } from 'react' import DragDrop from '../../../components/dragDrop/DragDrop' import { ErrorText, TextArea } from '../../../components/formUI/FormUI' import Video from '../../../components/videoPlayer/Video' import Image from '../../../components/lessonImage/Image' import Text from './Text' +import BtnCollection from '../../../components/btnCollection/BtnCollection' const AddContent = ({ setVideoModal, @@ -41,34 +43,7 @@ const AddContent = ({ /> setLessonCover(img)} /> - - {lessonData && - lessonData.map((vid, index) => ( -
-
- ))} -
- - - -
+ ) } From c1298f18a3418ed0b7231a496095b9536d3df6c7 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Tue, 3 Aug 2021 13:00:57 +0545 Subject: [PATCH 05/27] video feature added in news --- api/src/controllers/newsController.js | 17 ++++++++++++----- ...10803053107-alter-news-table-video-desc.js | 19 +++++++++++++++++++ api/src/models/newsModel.js | 7 ++++++- api/src/routes/newsRouter.js | 10 +++++++++- 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 api/src/migrations/20210803053107-alter-news-table-video-desc.js diff --git a/api/src/controllers/newsController.js b/api/src/controllers/newsController.js index ace3a6066..99ab77502 100644 --- a/api/src/controllers/newsController.js +++ b/api/src/controllers/newsController.js @@ -40,16 +40,23 @@ const getNews = (req, res) => { // @route POST /api/news/add/community/:id // @access Public const addNews = (req, res) => { - let filename = '' - if (req.file) { - filename = req.file.filename + let imageFilename = '' + let videoFilename = '' + if (req.files) { + imageFilename = req.files['newsImage'][0].filename + videoFilename = req.files['newsVideo'][0].filename } + const { - title, message, docType, readTime, language, creator, textDetail, imageDetail, videoDetail, category + title, message, docType, readTime, language, creator, textDetail, imageDetail, videoDetail, category, videoTitle, videoDescription, videoLink } = req.body db.News.create({ // _attachments: 'uploads/' + req.file.filename, - _attachments: 'news/' + filename, + _attachments: 'news/' + imageFilename, + videoCover: videoFilename, + videoTitle, + videoDescription, + videoLink, title, message, docType, diff --git a/api/src/migrations/20210803053107-alter-news-table-video-desc.js b/api/src/migrations/20210803053107-alter-news-table-video-desc.js new file mode 100644 index 000000000..bd2c24aac --- /dev/null +++ b/api/src/migrations/20210803053107-alter-news-table-video-desc.js @@ -0,0 +1,19 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + queryInterface.addColumn('news', 'videoTitle', Sequelize.STRING) + queryInterface.addColumn('news', 'videoDescription', Sequelize.STRING) + queryInterface.addColumn('news', 'videoCover', Sequelize.STRING) + queryInterface.addColumn('news', 'videoLink', Sequelize.STRING) + queryInterface.addColumn('news', 'videoResource', Sequelize.STRING) + }, + + down: async (queryInterface, Sequelize) => { + queryInterface.removeColumn('news', 'videoTitle') + queryInterface.removeColumn('news', 'videoDescription') + queryInterface.removeColumn('news', 'videoCover') + queryInterface.removeColumn('news', 'videoLink') + queryInterface.removeColumn('news', 'videoResource') + } +}; diff --git a/api/src/models/newsModel.js b/api/src/models/newsModel.js index 16ab72926..5309c5d15 100644 --- a/api/src/models/newsModel.js +++ b/api/src/models/newsModel.js @@ -45,7 +45,12 @@ module.exports = (sequelize, DataTypes) => { deleted: { type: DataTypes.BOOLEAN, defaultValue: false - } + }, + videoTitle: DataTypes.STRING, + videoDescription: DataTypes.STRING, + videoCover: DataTypes.STRING, + videoLink: DataTypes.STRING, + videoResource: DataTypes.STRING }, { timestamps: true } ) diff --git a/api/src/routes/newsRouter.js b/api/src/routes/newsRouter.js index d93246632..068c75954 100644 --- a/api/src/routes/newsRouter.js +++ b/api/src/routes/newsRouter.js @@ -6,8 +6,16 @@ const checkCommunity = require('../middleware/checkCommunity') const { addNews, getNews, updateNews, getNewsById, deleteNews, searchNewsTitle } = require('../controllers/newsController') const { upload, resizeImage } = require('../helpers/filehelpers') +// uploading multiple files +const cpUpload = upload.fields([{ name: 'newsImage', maxCount: 1 }, { name: 'newsVideo', maxCount: 1 }]) +// attaching single file to req.file for converting it +const fileChanger = (req, _res, next) => { + req.file = req.files.newsImage[0] + next() +} + router.route('/community/:id').get(checkCommunity, getNews) -router.route('/add/community/:id').post(checkCommunity, upload.single('news'), resizeImage, addNews) +router.route('/add/community/:id').post(checkCommunity, cpUpload, fileChanger, resizeImage, addNews) router.route('/community/:id/search').get(checkCommunity, searchNewsTitle) router .route('/:newsId/community/:id') From a99c995f2495845145fbde6a39018c21e6d2d5b8 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Tue, 3 Aug 2021 14:17:53 +0545 Subject: [PATCH 06/27] video feature added in the news add --- src/actions/newsActions.js | 17 ++++++++-- .../ContentAdd.jsx} | 4 +-- .../ContentAdd.scss} | 0 src/components/newsCard/NewsCard.jsx | 2 +- .../newsCreateModal/NewsCreateVideo.jsx | 1 + src/screens/communityNews/newsAdd/NewsAdd.jsx | 33 +++++++++++-------- .../courseManager/addLesson/AddContent.jsx | 9 ++--- 7 files changed, 41 insertions(+), 25 deletions(-) rename src/components/{btnCollection/BtnCollection.jsx => contentAdd/ContentAdd.jsx} (92%) rename src/components/{btnCollection/BtnCollection.scss => contentAdd/ContentAdd.scss} (100%) diff --git a/src/actions/newsActions.js b/src/actions/newsActions.js index 8a4293cbf..2ce1a3eaf 100644 --- a/src/actions/newsActions.js +++ b/src/actions/newsActions.js @@ -69,14 +69,25 @@ export const searchNews = (search) => async (dispatch) => { export const createNews = (newNews) => async (dispatch, getState) => { const formData = new FormData() - formData.append('news', newNews.file) + formData.append('newsImage', newNews.lessonImg) + formData.append('newsVideo', newNews.videoCover) formData.append('title', newNews.title) formData.append('category', newNews.category) - formData.append('imageDetail', newNews.imageDetail) + formData.append('videoTitle', newNews.videoTitle) + formData.append('videoDescription', newNews.videoDescription) + formData.append('videoLink', newNews.videoLink) try { + const configFunc = () => { + const userdata = window.localStorage.getItem('userInfo') + const token = JSON.parse(userdata).token + const headers = { 'Content-Type': 'multipart/form-data' } + headers.Authorization = token && `Bearer ${token}` + return { headers } + } + dispatch({ type: NEWS_CREATE_REQUEST }) const { userLogin: { userInfo } } = getState() - const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/news/add/community/${currentCommunity.id}`, formData, configFunc()) + const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/news/add/community/${currentCommunity.id}`, formData, configFunc) dispatch({ type: NEWS_CREATE_SUCCESS, payload: data }) dispatch({ type: NEWS_CLEAR, payload: data }) } catch (error) { diff --git a/src/components/btnCollection/BtnCollection.jsx b/src/components/contentAdd/ContentAdd.jsx similarity index 92% rename from src/components/btnCollection/BtnCollection.jsx rename to src/components/contentAdd/ContentAdd.jsx index ff335273e..b56734705 100644 --- a/src/components/btnCollection/BtnCollection.jsx +++ b/src/components/contentAdd/ContentAdd.jsx @@ -3,7 +3,7 @@ import Text from '../../screens/courseManager/addLesson/Text' import Image from '../lessonImage/Image' import Video from '../videoPlayer/Video' -const BtnCollection = ({data, setVideoModal, setImageModal, setTextModal}) => { +const ContentAdd = ({data, setVideoModal, setImageModal, setTextModal}) => { return ( <> {data.length && @@ -37,4 +37,4 @@ const BtnCollection = ({data, setVideoModal, setImageModal, setTextModal}) => { ) } -export default BtnCollection +export default ContentAdd diff --git a/src/components/btnCollection/BtnCollection.scss b/src/components/contentAdd/ContentAdd.scss similarity index 100% rename from src/components/btnCollection/BtnCollection.scss rename to src/components/contentAdd/ContentAdd.scss diff --git a/src/components/newsCard/NewsCard.jsx b/src/components/newsCard/NewsCard.jsx index adffd07d0..2265fbd42 100644 --- a/src/components/newsCard/NewsCard.jsx +++ b/src/components/newsCard/NewsCard.jsx @@ -31,7 +31,7 @@ const NewsSingleCard = ({ news, editCard }) => { setDropDown(false) } return ( - +
{moment(news.createdAt).fromNow()}
diff --git a/src/components/newsCreateModal/NewsCreateVideo.jsx b/src/components/newsCreateModal/NewsCreateVideo.jsx index a4d234745..2adbca853 100644 --- a/src/components/newsCreateModal/NewsCreateVideo.jsx +++ b/src/components/newsCreateModal/NewsCreateVideo.jsx @@ -36,6 +36,7 @@ const CreateVideo = ({ setLessonData(vData) setVideoActive(false) } + return ( <> {videoActive && ( diff --git a/src/screens/communityNews/newsAdd/NewsAdd.jsx b/src/screens/communityNews/newsAdd/NewsAdd.jsx index 4766043b2..9eff1117c 100644 --- a/src/screens/communityNews/newsAdd/NewsAdd.jsx +++ b/src/screens/communityNews/newsAdd/NewsAdd.jsx @@ -12,7 +12,7 @@ import { useForm } from 'react-hook-form' import { useEffect } from 'react' import { useLocation } from 'react-router-dom/cjs/react-router-dom.min' import { ErrorText, TextArea } from '../../../components/formUI/FormUI' -import BtnCollection from '../../../components/btnCollection/BtnCollection' +import ContentAdd from '../../../components/contentAdd/ContentAdd' const NewsAdd = () => { const { currentCommunity } = useSelector(state => state.activeCommunity) @@ -39,16 +39,23 @@ const NewsAdd = () => { setNewsData([{title, category}]) }, []) - const submitNewsForm = ({ title }) => { - console.log(newsData); - // const order = fetchLesson.length + 1 - // dispatch( - // createLesson({ - // title, - // category, - // coverImg, - // }) - // ) + const submitNewsForm = ({ title }) => { + const newData = convertArrToObject(newsData) + newData.title = title + newData.category = category; + dispatch(createNews(newData)); + } + + // converting the arrray into object for submission + + function convertArrToObject (arr) { + let newData = {}; + arr.map(item => { + let prop = Object.getOwnPropertyNames(item); + prop.forEach(el => newData[el] = item[el]) + }) + + return newData; } return ( @@ -112,7 +119,7 @@ const AddNewsContent = ({ })} /> - +
} @@ -125,7 +132,7 @@ const NewsSaveModal = ({ pathId, onClick }) => { diff --git a/src/screens/courseManager/addLesson/AddContent.jsx b/src/screens/courseManager/addLesson/AddContent.jsx index 687588009..bb615af6f 100644 --- a/src/screens/courseManager/addLesson/AddContent.jsx +++ b/src/screens/courseManager/addLesson/AddContent.jsx @@ -1,10 +1,7 @@ -import React, { useEffect, useLayoutEffect, useState } from 'react' +import React from 'react' import DragDrop from '../../../components/dragDrop/DragDrop' import { ErrorText, TextArea } from '../../../components/formUI/FormUI' -import Video from '../../../components/videoPlayer/Video' -import Image from '../../../components/lessonImage/Image' -import Text from './Text' -import BtnCollection from '../../../components/btnCollection/BtnCollection' +import ContentAdd from '../../../components/contentAdd/ContentAdd' const AddContent = ({ setVideoModal, @@ -43,7 +40,7 @@ const AddContent = ({ /> setLessonCover(img)} /> - +
) } From 49e04dc6b6429cf3772f0d4183b2e6cb7d3080c6 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Tue, 3 Aug 2021 14:34:43 +0545 Subject: [PATCH 07/27] js lint fix in content --- src/components/contentAdd/ContentAdd.jsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/contentAdd/ContentAdd.jsx b/src/components/contentAdd/ContentAdd.jsx index b56734705..38971116f 100644 --- a/src/components/contentAdd/ContentAdd.jsx +++ b/src/components/contentAdd/ContentAdd.jsx @@ -4,21 +4,23 @@ import Image from '../lessonImage/Image' import Video from '../videoPlayer/Video' const ContentAdd = ({data, setVideoModal, setImageModal, setTextModal}) => { - return ( - <> - {data.length && - data.map((vid, index) => ( -
-
- +
diff --git a/src/components/videoPlayer/Video.jsx b/src/components/videoPlayer/Video.jsx index 8d7f858ef..287d1df1f 100644 --- a/src/components/videoPlayer/Video.jsx +++ b/src/components/videoPlayer/Video.jsx @@ -6,6 +6,7 @@ import './Video.scss' const Video = ({ title, description, url, thumbnail }) => { const [showInfo, setShowInfo] = useState(false) +console.log(url); return ( <> {url ? ( diff --git a/src/components/videoPlayer/Video.scss b/src/components/videoPlayer/Video.scss index bef19509b..7a264f2c1 100644 --- a/src/components/videoPlayer/Video.scss +++ b/src/components/videoPlayer/Video.scss @@ -29,6 +29,7 @@ line-height: 2em; margin-bottom: 0.5em; font-weight: 600; + color: var(--primary-white); &::first-letter { text-transform: uppercase; @@ -38,6 +39,7 @@ font-size: 1em; line-height: 1.5em; width: 80%; + color: var(--primary-white); &::first-letter { text-transform: uppercase; diff --git a/src/screens/communityNews/newsAdd/NewsAdd.jsx b/src/screens/communityNews/newsAdd/NewsAdd.jsx index 9eff1117c..b505cbb33 100644 --- a/src/screens/communityNews/newsAdd/NewsAdd.jsx +++ b/src/screens/communityNews/newsAdd/NewsAdd.jsx @@ -40,10 +40,11 @@ const NewsAdd = () => { }, []) const submitNewsForm = ({ title }) => { + const newData = convertArrToObject(newsData) newData.title = title newData.category = category; - dispatch(createNews(newData)); + dispatch(createNews(newsData, newData)); } // converting the arrray into object for submission diff --git a/src/screens/communityNewsView/CommunityNewsView.jsx b/src/screens/communityNewsView/CommunityNewsView.jsx index 0e5aacfe0..6155e5089 100644 --- a/src/screens/communityNewsView/CommunityNewsView.jsx +++ b/src/screens/communityNewsView/CommunityNewsView.jsx @@ -3,24 +3,46 @@ import './CommunityNewsView.scss' import DashboardLayout from '../../layout/dashboardLayout/DashboardLayout' import BackButton from '../../components/backButton/BackButton' import { useLocation } from 'react-router-dom' +import { useParams } from 'react-router-dom/cjs/react-router-dom.min' +import { getApi } from '../../utils/apiFunc' +import { useDispatch } from 'react-redux' +import Text from '../courseManager/addLesson/Text' +import Video from '../../components/videoPlayer/Video' +import { GET_VIDEO, LESSON_IMG, VIDEO_COVER } from '../../utils/urlConstants' +import Image from '../../components/lessonImage/Image' -function CommunityNewsViewPage ({ newNews }) { +function CommunityNewsViewPage () { const [news, setNews] = useState({}) - const val = useLocation()?.state?.news + // const val = useLocation()?.state?.news + + // fetching current community +const currentCommunity = localStorage.getItem('currentCommunity') + ? JSON.parse(localStorage.getItem('currentCommunity')) + : null + const dispatch = useDispatch(); + const {id} = useParams(); + useEffect(() => { - setNews(newNews || val) - }, [newNews, val]) + getSingleNews(id); + }, []) + + async function getSingleNews (id) { + const { data } = await getApi( + dispatch, + `${process.env.REACT_APP_API_BASE_URL}/api/news/${id}/community/${currentCommunity.id}` + ) + setNews(data) + } + + console.log(news) return ( <> - {newNews ? ( - - ) : (
- - + + {news && }
facebook-icon @@ -38,7 +60,6 @@ function CommunityNewsViewPage ({ newNews }) {
- )} ) } @@ -56,20 +77,41 @@ const NewsSingleView = ({ news }) => { {news?.readTime}
-
- community-single-article -
-
-

{news?.textDetail?.collectionTitle}

-

{news?.textDetail?.collectionDescription}

-
-
-

{news?.imageDetail?.imageDescription}

-
-
-

{news?.videoDetail?.videoTitle}

-

{news?.videoDetail?.videoDescription}

-
+ + { + news?.photos && news?.photos.map(item => { + return + }) + } + + { + news?.texts && news?.texts.map(item => { + return + }) + } + + { + news?.videos && news?.videos.map(item => { + return
- +
{(windowWidth < 1200) diff --git a/src/screens/communityNews/newsAdd/NewsAdd.jsx b/src/screens/communityNews/newsAdd/NewsAdd.jsx index b505cbb33..4e513d5dd 100644 --- a/src/screens/communityNews/newsAdd/NewsAdd.jsx +++ b/src/screens/communityNews/newsAdd/NewsAdd.jsx @@ -13,9 +13,18 @@ import { useEffect } from 'react' import { useLocation } from 'react-router-dom/cjs/react-router-dom.min' import { ErrorText, TextArea } from '../../../components/formUI/FormUI' import ContentAdd from '../../../components/contentAdd/ContentAdd' +import { getApi } from '../../../utils/apiFunc' +import DragDrop from '../../../components/dragDrop/DragDrop' +import Image from '../../../components/lessonImage/Image' +import Text from '../../courseManager/addLesson/Text' +import Video from '../../../components/videoPlayer/Video' +import { GET_VIDEO, LESSON_IMG, VIDEO_COVER } from '../../../utils/urlConstants' const NewsAdd = () => { const { currentCommunity } = useSelector(state => state.activeCommunity) + // fetching category from route + const {state} = useLocation(); + const [createVideoModal, setCreateVideoModal] = useState(false) const [createImageModal, setCreateImageModal] = useState(false) const [createTextModal, setCreateTextModal] = useState(false) @@ -23,24 +32,31 @@ const NewsAdd = () => { const [imageActive, setImageActive] = useState(true) const [textActive, setTextActive] = useState(true) const [newsData, setNewsData] = useState([]) + const [newsSingleData, setNewsSingleData] = useState([]) + const [category, setCategory] = useState(state?.category || null) + const [newsCover, setNewsCover] = useState(null); const news = useSelector((state) => (state.addNewNews !== {} ? state.addNewNews : '')) const { register, errors, handleSubmit } = useForm() - const { title} = useParams() + const { title, id} = useParams() const dispatch = useDispatch(); - // fetching category from route - const {state} = useLocation(); - const {category} = state; - useEffect(() => { - setNewsData([{title, category}]) + if(id) { + getSingleNews() + } else { + setNewsData([{title, category}]) + } }, []) + async function getSingleNews () { + const { data } = await getApi(dispatch, `${process.env.REACT_APP_API_BASE_URL}/api/news/${id}/community/${currentCommunity.id}`) + setNewsSingleData(data) + } + const submitNewsForm = ({ title }) => { - const newData = convertArrToObject(newsData) newData.title = title newData.category = category; @@ -48,7 +64,6 @@ const NewsAdd = () => { } // converting the arrray into object for submission - function convertArrToObject (arr) { let newData = {}; arr.map(item => { @@ -59,12 +74,16 @@ const NewsAdd = () => { return newData; } + const editNewsForm = () => { + console.log(newsCover) + } + return ( <> {createVideoModal && } {createImageModal && } {createTextModal && } - + { errors={errors} setNewsData = {setNewsData} newsData = {newsData} + newsSingleData = {newsSingleData} + setNewsCover={setNewsCover} /> - + { + newsSingleData + ? + : + } @@ -91,7 +114,9 @@ const AddNewsContent = ({ setVideoModal, setImageModal, setTextModal, - register + register, + newsSingleData, + setNewsCover }) => { const [title, setTitle] = useState(''); @@ -100,8 +125,13 @@ const AddNewsContent = ({ if(newsData.length) { setTitle(newsData[0].title) } - }, [newsData]) + if(newsSingleData) { + setTitle(newsSingleData.title) + } + }, [newsData, newsSingleData]) + +console.log(newsSingleData); return
+ + {/* Edit component for news */} + {newsSingleData && <> + { + newsSingleData?.photos && newsSingleData?.photos.map(item => { + return + }) + } + + { + newsSingleData?.texts && newsSingleData?.texts.map(item => { + return + }) + } + + { + newsSingleData?.videos && newsSingleData?.videos.map(item => { + return
} -const NewsSaveModal = ({ pathId, onClick }) => { +const NewsSaveModal = ({ pathId, onClick, name}) => { const history = useHistory() return (
-

Do you want to save News?

+

Do you want to {name} News?

From 1cb7e0d69575f4701acbc0e00c704747c301a5ea Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Fri, 6 Aug 2021 12:55:40 +0545 Subject: [PATCH 12/27] edit content component added --- src/components/editContent/EditContent.jsx | 90 +++++++++++++++++++ src/screens/communityNews/newsAdd/NewsAdd.jsx | 5 ++ 2 files changed, 95 insertions(+) create mode 100644 src/components/editContent/EditContent.jsx diff --git a/src/components/editContent/EditContent.jsx b/src/components/editContent/EditContent.jsx new file mode 100644 index 000000000..d8827de89 --- /dev/null +++ b/src/components/editContent/EditContent.jsx @@ -0,0 +1,90 @@ +import { useState, useEffect } from 'react' +import { GET_VIDEO, VIDEO_COVER, LESSON_IMG } from '../../../utils/urlConstants' +import Image from '../../../components/lessonImage/Image' +import Video from '../../../components/videoPlayer/Video' +import Text from '../addLesson/Text' + +const EditContent = ({ + data, + newLessonData, + setEditTextModel, + setEditPhotoModel, + setEditVideoModel, + modelPopUp, + removeTextItem, + removePhoto, + removeVideo, + removeLocalData +}) => { + const [allLessonData, setAllLessonData] = useState([]) + + useEffect(() => { + setAllLessonData(data, newLessonData) + }, [data, newLessonData]) + + function video (data) { + if (typeof data?.videoResource === 'string') { + return `${GET_VIDEO}${data?.videoResource}` + } else { + return data?.videoResource?.preview + } + } + return ( + <> + {data + .sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1)) + .map((data, index) => ( +
+ +
+ ))} + + ) +} + +export default EditContent diff --git a/src/screens/communityNews/newsAdd/NewsAdd.jsx b/src/screens/communityNews/newsAdd/NewsAdd.jsx index 4e513d5dd..3305239d8 100644 --- a/src/screens/communityNews/newsAdd/NewsAdd.jsx +++ b/src/screens/communityNews/newsAdd/NewsAdd.jsx @@ -19,6 +19,7 @@ import Image from '../../../components/lessonImage/Image' import Text from '../../courseManager/addLesson/Text' import Video from '../../../components/videoPlayer/Video' import { GET_VIDEO, LESSON_IMG, VIDEO_COVER } from '../../../utils/urlConstants' +import EditContent from '../../../components/editContent/EditContent' const NewsAdd = () => { const { currentCommunity } = useSelector(state => state.activeCommunity) @@ -189,6 +190,10 @@ console.log(newsSingleData); } + { + newsSingleData && + } +
} From 2f4d815c0587d6f3089190ea93e9c19e7944d4d3 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Fri, 6 Aug 2021 14:12:57 +0545 Subject: [PATCH 13/27] importing necessary files --- src/components/editContent/EditContent.jsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/editContent/EditContent.jsx b/src/components/editContent/EditContent.jsx index d8827de89..b4201028d 100644 --- a/src/components/editContent/EditContent.jsx +++ b/src/components/editContent/EditContent.jsx @@ -1,8 +1,11 @@ import { useState, useEffect } from 'react' import { GET_VIDEO, VIDEO_COVER, LESSON_IMG } from '../../../utils/urlConstants' -import Image from '../../../components/lessonImage/Image' -import Video from '../../../components/videoPlayer/Video' -import Text from '../addLesson/Text' +import Text from '../../screens/courseManager/addLesson/Text' +import Image from '../lessonImage/Image' +import Video from '../videoPlayer/Video' +// import Image from '../../../components/lessonImage/Image' +// import Video from '../../../components/videoPlayer/Video' +// import Text from '../addLesson/Text' const EditContent = ({ data, From 01a405f63040affd805fe99b883688fa10188d11 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Fri, 6 Aug 2021 14:24:28 +0545 Subject: [PATCH 14/27] changes to the text, video and image --- src/components/lessonImage/Image.jsx | 19 ++++++++++- src/components/videoPlayer/Video.jsx | 31 +++++++++++++++--- src/screens/courseManager/addLesson/Text.jsx | 34 ++++++++++++++++++-- 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/components/lessonImage/Image.jsx b/src/components/lessonImage/Image.jsx index e784c51c4..fe7af0064 100644 --- a/src/components/lessonImage/Image.jsx +++ b/src/components/lessonImage/Image.jsx @@ -1,12 +1,29 @@ +import Actions from '../../screens/courseManager/addLesson/Actions' import './Image.scss' -const Image = ({ src, desc }) => { +const Image = ({ + src, + desc, + onRemove, + id, + modelPopUp, + setEditPhotoModel, + isEditable +}) => { + const poopUp = () => { + modelPopUp(setEditPhotoModel(true), id) + } return ( <> {src ? (
{`lesson_${src}_img`}

{desc && `"${desc}"`}

+ {isEditable ? ( + + ) : ( + '' + )}
) : ( '' diff --git a/src/components/videoPlayer/Video.jsx b/src/components/videoPlayer/Video.jsx index a04927211..bad294978 100644 --- a/src/components/videoPlayer/Video.jsx +++ b/src/components/videoPlayer/Video.jsx @@ -1,12 +1,27 @@ import { useState } from 'react' import ReactPlayer from 'react-player' + +import Actions from '../../screens/courseManager/addLesson/Actions' import { ReactComponent as Play } from '../../assets/images/play.svg' import { ReactComponent as BookMark } from '../../assets/images/book-outlined.svg' import './Video.scss' -const Video = ({ title, description, url, thumbnail }) => { +const Video = ({ + title, + description, + url, + thumbnail, + itemId, + isEditable, + onRemove, + id, + setEditVideoModel, + modelPopUp +}) => { const [showInfo, setShowInfo] = useState(false) - + const poopUp = () => { + modelPopUp(setEditVideoModel(true), id) + } return ( <> {url ? ( @@ -14,10 +29,15 @@ const Video = ({ title, description, url, thumbnail }) => {

{title}

{description}

+

{itemId}

-
- -
+ {isEditable ? ( + + ) : ( +
+ +
+ )} { } export default Video + diff --git a/src/screens/courseManager/addLesson/Text.jsx b/src/screens/courseManager/addLesson/Text.jsx index 8700bdbe4..88447b85e 100644 --- a/src/screens/courseManager/addLesson/Text.jsx +++ b/src/screens/courseManager/addLesson/Text.jsx @@ -1,11 +1,39 @@ +import Actions from './Actions' + import './Text.scss' -const Text = ({ heading, desc }) => { +const Text = ({ + heading, + desc, + onRemove, + id, + setEditTextModel, + modelPopUp, + isEditable, + refetch +}) => { + const poopUp = () => { + modelPopUp(setEditTextModel(true), id) + } return ( <> {heading || desc ? (
-

{heading}

-

{desc}

+
+

{heading}

+

+ {desc} {id} +

+
+ {isEditable ? ( + + ) : ( + '' + )}
) : ( '' From aeddcce9d55245b35563b8e5f5b104770989d7e3 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Fri, 6 Aug 2021 14:27:24 +0545 Subject: [PATCH 15/27] Action file created --- .../courseManager/addLesson/Actions.jsx | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/screens/courseManager/addLesson/Actions.jsx diff --git a/src/screens/courseManager/addLesson/Actions.jsx b/src/screens/courseManager/addLesson/Actions.jsx new file mode 100644 index 000000000..48b00a38e --- /dev/null +++ b/src/screens/courseManager/addLesson/Actions.jsx @@ -0,0 +1,35 @@ +import React, { useState } from 'react' +import useHideOnClick from '../../../utils/useHideOnClick' +const LessonActions = ({ id, onRemove = () => {}, poopUp, refetch }) => { + const [actionActive, setActionActive] = useState(false) + + const domNode = useHideOnClick(() => { + setActionActive(false) + }) + + return ( +
+ + {actionActive && ( +
    +
  • { + poopUp() + setActionActive(!actionActive) + }} + > + Edit +
  • +
  • onRemove(id)}>Delete
  • +
+ )} +
+ ) +} + +export default LessonActions From 3eae3924d50a4989935cc368ed53282fc630e757 Mon Sep 17 00:00:00 2001 From: Sujal Lama Date: Fri, 6 Aug 2021 14:46:59 +0545 Subject: [PATCH 16/27] changes to edit content --- src/components/editContent/EditContent.jsx | 94 ++++++++++--------- src/screens/communityNews/newsAdd/NewsAdd.jsx | 39 +------- src/utils/urlConstants.js | 26 ++--- 3 files changed, 65 insertions(+), 94 deletions(-) diff --git a/src/components/editContent/EditContent.jsx b/src/components/editContent/EditContent.jsx index b4201028d..0fdcb259e 100644 --- a/src/components/editContent/EditContent.jsx +++ b/src/components/editContent/EditContent.jsx @@ -1,11 +1,8 @@ import { useState, useEffect } from 'react' -import { GET_VIDEO, VIDEO_COVER, LESSON_IMG } from '../../../utils/urlConstants' +import { GET_VIDEO, VIDEO_COVER, LESSON_IMG } from '../../utils/urlConstants' import Text from '../../screens/courseManager/addLesson/Text' import Image from '../lessonImage/Image' import Video from '../videoPlayer/Video' -// import Image from '../../../components/lessonImage/Image' -// import Video from '../../../components/videoPlayer/Video' -// import Text from '../addLesson/Text' const EditContent = ({ data, @@ -32,60 +29,67 @@ const EditContent = ({ return data?.videoResource?.preview } } + console.log(data); return ( - <> - {data - .sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1)) - .map((data, index) => ( -
- { + data && <> + { + data?.photos && data?.photos.map(item => { + return + }) + } + + { + data?.texts && data?.texts.map(item => { + return -
- ))} + }) + } + + } ) } diff --git a/src/screens/communityNews/newsAdd/NewsAdd.jsx b/src/screens/communityNews/newsAdd/NewsAdd.jsx index 3305239d8..70a750673 100644 --- a/src/screens/communityNews/newsAdd/NewsAdd.jsx +++ b/src/screens/communityNews/newsAdd/NewsAdd.jsx @@ -152,44 +152,7 @@ console.log(newsSingleData); /> {/* Edit component for news */} - {newsSingleData && <> - { - newsSingleData?.photos && newsSingleData?.photos.map(item => { - return - }) - } - - { - newsSingleData?.texts && newsSingleData?.texts.map(item => { - return - }) - } - - { - newsSingleData?.videos && newsSingleData?.videos.map(item => { - return