From 974ee8f68480a8461eea12ad0ee9bdc3babb84e1 Mon Sep 17 00:00:00 2001 From: Dixit Sigdel Date: Mon, 31 May 2021 09:22:02 +0545 Subject: [PATCH 1/9] collection mapping and adding files --- .../20210530092345-alter_collections.js | 12 +++ src/actions/collectionActions.js | 83 +++++++++++++++++++ src/components/groupModal/GroupModal.jsx | 37 +++++++-- src/components/groupUsers/GroupUsers.jsx | 8 +- src/constants/collectionConstants.js | 12 +++ src/reducers/collectionReducres.js | 57 +++++++++++++ src/screens/library/Library.jsx | 1 + src/store.js | 2 + 8 files changed, 200 insertions(+), 12 deletions(-) create mode 100644 api/migrations/20210530092345-alter_collections.js create mode 100644 src/actions/collectionActions.js create mode 100644 src/constants/collectionConstants.js create mode 100644 src/reducers/collectionReducres.js diff --git a/api/migrations/20210530092345-alter_collections.js b/api/migrations/20210530092345-alter_collections.js new file mode 100644 index 000000000..07a081b71 --- /dev/null +++ b/api/migrations/20210530092345-alter_collections.js @@ -0,0 +1,12 @@ + +module.exports = { + up: async (queryInterface, Sequelize) => { + queryInterface.addColumn('collections', 'filename', Sequelize.STRING) + queryInterface.addColumn('collections', 'description', Sequelize.STRING) + }, + + down: async (queryInterface, Sequelize) => { + queryInterface.addColumn('collections', 'filename', Sequelize.STRING) + queryInterface.addColumn('collections', 'description', Sequelize.STRING) + } +} diff --git a/src/actions/collectionActions.js b/src/actions/collectionActions.js new file mode 100644 index 000000000..ce7b99b12 --- /dev/null +++ b/src/actions/collectionActions.js @@ -0,0 +1,83 @@ +import axios from 'axios' +import { + COLLECTION_LIST_REQUEST, + COLLECTION_LIST_SUCCESS, + COLLECTION_LIST_FAIL, + COLLECTION_SEARCH_REQUEST, + COLLECTION_SEARCH_SUCCESS, + COLLECTION_SEARCH_FAIL, + COLLECTION_CREATE_REQUEST, + COLLECTION_CREATE_SUCCESS, + COLLECTION_CREATE_FAIL +} from '../constants/collectionConstants' + +export const listCollections = (sort = '', pageNumber = '') => async ( + dispatch +) => { + try { + dispatch({ type: COLLECTION_LIST_REQUEST }) + const { data } = await axios.get( + `${process.env.REACT_APP_API_BASE_URL}/api/collection` + ) + console.log('data', data) + dispatch({ + type: COLLECTION_LIST_SUCCESS, + payload: data + }) + } catch (error) { + dispatch({ + type: COLLECTION_LIST_FAIL, + payload: + error.response && error.response.data.message + ? error.response.data.message + : error.message + }) + } +} + +export const searchCollections = (search) => async ( + dispatch +) => { + try { + dispatch({ type: COLLECTION_SEARCH_REQUEST }) + const { data } = await axios.get(`${process.env.REACT_APP_API_BASE_URL}/api/collection/search?title=${search}`) + dispatch({ + type: COLLECTION_SEARCH_SUCCESS, + payload: data + }) + } catch (error) { + dispatch({ + type: COLLECTION_SEARCH_FAIL, + payload: + error.response && error.response.data.message + ? error.response.data.message + : error.message + }) + } +} + +export const createCollection = (newCollection) => async (dispatch, getState) => { + const formData = new FormData() + formData.append('name', newCollection.name) + formData.append('docType', newCollection.docType) + formData.append('resourceType', newCollection.resourceType) + formData.append('linkId', newCollection.linkId) + try { + dispatch({ type: COLLECTION_CREATE_REQUEST }) + const { userLogin: { userInfo } } = getState() + const config = { + headers: { + // Authorization : `Bearer ${userInfo.token}`, + 'Content-Type': 'multipart/form-data' + } + } + const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/collection/add`, formData, config) + dispatch({ type: COLLECTION_CREATE_SUCCESS, payload: data }) + } catch (error) { + const message = + error.response && error.response.data.message + ? error.response.data.message + : error.message + dispatch({ type: COLLECTION_CREATE_FAIL, payload: message }) + } +} diff --git a/src/components/groupModal/GroupModal.jsx b/src/components/groupModal/GroupModal.jsx index a30826e80..fc03ae18f 100644 --- a/src/components/groupModal/GroupModal.jsx +++ b/src/components/groupModal/GroupModal.jsx @@ -1,22 +1,40 @@ - +import { useEffect } from 'react' +import { useSelector, useDispatch } from 'react-redux' import GroupUsers from '../groupUsers/GroupUsers' import SearchComponent from '../searchComponent/SearchComponent' import './GroupModal.scss' +import { listCollections } from '../../actions/collectionActions' -const GroupModal = ({ clickHandler, setNewCollection, data, btnName, name }) => { +const GroupModal = ({ + clickHandler, + setNewCollection, + btnName, + name, + title +}) => { function collectionAdded () { setNewCollection(true) clickHandler(false) } + const data = useSelector( + (state) => state.listCollection.collections.collection + ) + console.log('collection', data) + const dispatch = useDispatch() + + useEffect(() => { + dispatch(listCollections()) + }, [dispatch]) return ( <>
-
-

{name || 'Add members'}

- +

{title}

+
@@ -28,9 +46,12 @@ const GroupModal = ({ clickHandler, setNewCollection, data, btnName, name }) =>
- {btnName === 'add to collections' &&
-
} + {btnName === 'add to collections' && ( +
+ + +
+ )} diff --git a/src/components/groupUsers/GroupUsers.jsx b/src/components/groupUsers/GroupUsers.jsx index 6f3d4a861..33526eaca 100644 --- a/src/components/groupUsers/GroupUsers.jsx +++ b/src/components/groupUsers/GroupUsers.jsx @@ -3,17 +3,17 @@ import Radiobox from '../radioBox/Radiobox' import './GroupUsers.scss' import { groupUsersData } from '../../constants/sampleData' -const GroupUsers = () => { +const GroupUsers = ({ data }) => { return ( <> { - groupUsersData.map(user => ( + data.map(d => (
- users + users
-

{user.name}

+

{d.name}

diff --git a/src/constants/collectionConstants.js b/src/constants/collectionConstants.js new file mode 100644 index 000000000..e8cefed9f --- /dev/null +++ b/src/constants/collectionConstants.js @@ -0,0 +1,12 @@ +export const COLLECTION_LIST_REQUEST = 'COLLECTION_LIST_REQUEST' +export const COLLECTION_LIST_SUCCESS = 'COLLECTION_LIST_SUCCESS' +export const COLLECTION_LIST_FAIL = 'COLLECTION_LIST_FAIL' + +export const COLLECTION_SEARCH_REQUEST = 'COLLECTION_SEARCH_REQUEST' +export const COLLECTION_SEARCH_SUCCESS = 'COLLECTION_SEARCH_SUCCESS' +export const COLLECTION_SEARCH_FAIL = 'COLLECTION_SEARCH_FAIL' + +export const COLLECTION_CREATE_REQUEST = 'COLLECTION_CREATE_REQUEST' +export const COLLECTION_CREATE_SUCCESS = 'COLLECTION_CREATE_SUCCESS' +export const COLLECTION_CREATE_FAIL = 'COLLECTION_CREATE_FAIL' +export const COLLECTION_CREATE_RESET = 'COLLECTION_CREATE_RESET' diff --git a/src/reducers/collectionReducres.js b/src/reducers/collectionReducres.js new file mode 100644 index 000000000..c6ee33261 --- /dev/null +++ b/src/reducers/collectionReducres.js @@ -0,0 +1,57 @@ +import { + COLLECTION_LIST_REQUEST, + COLLECTION_LIST_SUCCESS, + COLLECTION_LIST_FAIL, + COLLECTION_SEARCH_REQUEST, + COLLECTION_SEARCH_SUCCESS, + COLLECTION_SEARCH_FAIL, + COLLECTION_CREATE_REQUEST, + COLLECTION_CREATE_SUCCESS, + COLLECTION_CREATE_FAIL, + COLLECTION_CREATE_RESET +} from '../constants/collectionConstants' + +export const collectionListReducer = (state = { collections: [] }, action) => { + switch (action.type) { + case COLLECTION_LIST_REQUEST: + return { loading: true, collections: [] } + case COLLECTION_LIST_SUCCESS: + return { + loading: false, + collections: action.payload, + pages: action.payload.pages, + page: action.payload.page + + } + case COLLECTION_LIST_FAIL: + return { loading: false, error: action.payload } + case COLLECTION_SEARCH_REQUEST: + return { loading: true, collections: [] } + case COLLECTION_SEARCH_SUCCESS: + return { + loading: false, + searchCollections: action.payload.collections, + order: action.payload.order + } + case COLLECTION_SEARCH_FAIL: + return { loading: false, error: action.payload } + + default: + return state + } +} + +export const collectionCreateReducer = (state = {}, action) => { + switch (action.type) { + case COLLECTION_CREATE_REQUEST: + return { loading: true } + case COLLECTION_CREATE_SUCCESS: + return { loading: false, success: true, collection: action.payload } + case COLLECTION_CREATE_FAIL: + return { loading: false, error: action.payload } + case COLLECTION_CREATE_RESET: + return {} + default: + return state + } +} diff --git a/src/screens/library/Library.jsx b/src/screens/library/Library.jsx index de473ae53..5f398729c 100644 --- a/src/screens/library/Library.jsx +++ b/src/screens/library/Library.jsx @@ -37,6 +37,7 @@ const Library = () => { clickHandler={setModalActive} data={groupCollection} btnName='add to collections' setNewCollection={setNewCollection} + title='Collections' />} {newCollection && } diff --git a/src/store.js b/src/store.js index 203428a05..3e66bceb2 100644 --- a/src/store.js +++ b/src/store.js @@ -7,9 +7,11 @@ import { enterpriseListReducer } from './reducers/enterpriseReducers' import { groupListReducer, groupViewReducer } from './reducers/communityGroupReducers' import { userLoginReducer, userRegisterReducer } from './reducers/userReducers' import { eventListReducer } from './reducers/calendarEventReducer' +import { collectionListReducer } from './reducers/collectionReducres' const reducer = combineReducers({ listEvents: eventListReducer, + listCollection: collectionListReducer, groupView: groupViewReducer, listGroups: groupListReducer, listEnterprises: enterpriseListReducer, From 210e8d39a9e3d6300b15266284fed2b60d4f34f8 Mon Sep 17 00:00:00 2001 From: Dixit Sigdel Date: Mon, 31 May 2021 19:08:23 +0545 Subject: [PATCH 2/9] collection add files --- .../20210531094440-alter_collections.js | 10 +++ api/src/controllers/collectionController.js | 10 ++- api/src/models/collectionModel.js | 6 ++ api/src/routes/collectionRouter.js | 3 +- src/components/groupUsers/GroupUsers.jsx | 4 +- src/components/libraryCard/LibraryCard.jsx | 53 ++++++--------- .../libraryHeader/LibraryHeader.jsx | 4 +- src/components/listView/ListView.jsx | 67 ++++++++----------- src/screens/library/Library.jsx | 2 +- src/screens/library/collection/Collection.jsx | 22 ++++-- .../library/userCollection/UserCollection.jsx | 58 ++++++++-------- 11 files changed, 129 insertions(+), 110 deletions(-) create mode 100644 api/migrations/20210531094440-alter_collections.js diff --git a/api/migrations/20210531094440-alter_collections.js b/api/migrations/20210531094440-alter_collections.js new file mode 100644 index 000000000..28313998a --- /dev/null +++ b/api/migrations/20210531094440-alter_collections.js @@ -0,0 +1,10 @@ + +module.exports = { + up: async (queryInterface, Sequelize) => { + queryInterface.addColumn('collections', 'category', Sequelize.STRING) + }, + + down: async (queryInterface, Sequelize) => { + queryInterface.addColumn('collections', 'category', Sequelize.STRING) + } +} diff --git a/api/src/controllers/collectionController.js b/api/src/controllers/collectionController.js index 9a5fb4c8a..3fb23642f 100644 --- a/api/src/controllers/collectionController.js +++ b/api/src/controllers/collectionController.js @@ -53,12 +53,18 @@ const getCollectionById = (req, res) => { // @todo we have to work on relation mapping betweenn collection and resources const addcollection = (req, res) => { - const { name, docType, resourceType, linkId } = req.body + const { name, docType, resourceType, linkId, description } = req.body + let filename = '' + if (req.file) { + filename = req.file.filename + } Collection.create({ name, docType, resourceType, - linkId + linkId, + description, + filename }) .then(() => res.json({ message: 'Collection Created !!!' }).status(200)) .catch((err) => res.json({ error: err.message }).status(400)) diff --git a/api/src/models/collectionModel.js b/api/src/models/collectionModel.js index 50adce827..6b1a72131 100644 --- a/api/src/models/collectionModel.js +++ b/api/src/models/collectionModel.js @@ -20,6 +20,12 @@ const Collection = db.define( }, linkId: { type: Sequelize.INTEGER + }, + filename: { + type: Sequelize.STRING + }, + description: { + type: Sequelize.STRING } }, { timestamps: true } diff --git a/api/src/routes/collectionRouter.js b/api/src/routes/collectionRouter.js index e553ff28e..090e7736d 100644 --- a/api/src/routes/collectionRouter.js +++ b/api/src/routes/collectionRouter.js @@ -1,9 +1,10 @@ const express = require('express') const router = express.Router() const { addcollection, getCollection, deleteCollection, getCollectionById, updateCollection, searchCollectionTitle } = require('../controllers/collectionController') +const { upload } = require('../helpers/filehelpers') router.route('/').get(getCollection) -router.route('/add').post(addcollection) +router.route('/add').post(upload.single('collection'), addcollection) router.route('/search').get(searchCollectionTitle) router.route('/:id').get(getCollectionById).delete(deleteCollection).put(updateCollection) diff --git a/src/components/groupUsers/GroupUsers.jsx b/src/components/groupUsers/GroupUsers.jsx index 33526eaca..e6e66286f 100644 --- a/src/components/groupUsers/GroupUsers.jsx +++ b/src/components/groupUsers/GroupUsers.jsx @@ -7,18 +7,20 @@ const GroupUsers = ({ data }) => { return ( <> { + data.map(d => (
users
-

{d.name}

+

{d.name && d.name}

)) } + ) } diff --git a/src/components/libraryCard/LibraryCard.jsx b/src/components/libraryCard/LibraryCard.jsx index 092b907f2..1f00f03ff 100644 --- a/src/components/libraryCard/LibraryCard.jsx +++ b/src/components/libraryCard/LibraryCard.jsx @@ -5,41 +5,30 @@ import './LibraryCard.css' const LibraryCard = ({ data }) => { return ( <> - +
{ - data.map(item => { - return ( -
- -
- ) - }) - } - - - ) -} + data && data.map(item => { + return ( +
-const LibraryBackgroundCard = ({ item }) => { - return ( -
-
-
- -
-
-
{item.category}
-
{item.title}
-
+ +
+
{item.category}
+

{item.name}

+
+
+ ) + }) + }
-
+ ) } diff --git a/src/components/libraryHeader/LibraryHeader.jsx b/src/components/libraryHeader/LibraryHeader.jsx index e3ce525a9..17dbf4233 100644 --- a/src/components/libraryHeader/LibraryHeader.jsx +++ b/src/components/libraryHeader/LibraryHeader.jsx @@ -20,7 +20,7 @@ const data = [{ link: '/library/collection/saved' }] -const LibraryHeader = ({ setActive }) => { +const LibraryHeader = ({ setActive, btnName }) => { const [windowWidth, setWindowWidth] = useState(window.innerWidth) const userLogin = useSelector((state) => state.userLogin) const { userInfo } = userLogin @@ -70,7 +70,7 @@ const LibraryHeader = ({ setActive }) => {
-
+
diff --git a/src/components/listView/ListView.jsx b/src/components/listView/ListView.jsx index dbacf0aad..8ad981280 100644 --- a/src/components/listView/ListView.jsx +++ b/src/components/listView/ListView.jsx @@ -2,55 +2,42 @@ import { useState } from 'react' import CardLayout from '../../layout/cardLayout/CardLayout' import useSizeFinder from '../../utils/sizeFinder' import './ListView.css' +import { useParams } from 'react-router-dom' const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }) => { - const windowWidth = useSizeFinder() + const [active, setActive] = useState(false) + + function clickHandle (id) { + setActive(!active) + } + return ( <>

{title}

- { - windowWidth > 1000 - ? data && data.map(item => { - return ( - - ) - }) - : - {data && data.map(item => { - return ( - - ) - })} - - } + {data && data.map(item => { + return ( +
+
+ item.title +
+
+

{item.title}

+

{item.category}

+
+
+ Add to + + +
+
+ ) + })}
) } -const ListViewCardComponent = ({ item, modalActive, setModalActive }) => { - const [active, setActive] = useState(false) - return ( -
-
-
- item.title -
-
-

{item.title}

-

{item.category}jelroro

-
-
-
- Add to - - -
-
- ) -} - export default ListView diff --git a/src/screens/library/Library.jsx b/src/screens/library/Library.jsx index 5f398729c..d8d27f302 100644 --- a/src/screens/library/Library.jsx +++ b/src/screens/library/Library.jsx @@ -46,7 +46,7 @@ const Library = () => {
- + {['Articles', 'Videos'].map(type => (
{ const [newCollection, setNewCollection] = useState(false) const [active, setActive] = useState(false) const [modalActive, setModalActive] = useState(false) + + const data = useSelector( + (state) => state.listCollection.collections.collection + ) + + console.log('another', data) + function openAddCollection () { setModalActive(true) setActive(false) } return ( <> - {modalActive && } + {modalActive && } {newCollection && } + {active && }
- +

My library (files)

@@ -50,7 +64,7 @@ const Collection = () => {

My Collections

- +
diff --git a/src/screens/library/userCollection/UserCollection.jsx b/src/screens/library/userCollection/UserCollection.jsx index 60a619630..281490a95 100644 --- a/src/screens/library/userCollection/UserCollection.jsx +++ b/src/screens/library/userCollection/UserCollection.jsx @@ -1,4 +1,5 @@ -import { useState } from 'react' +import { useState, useEffect } from 'react' +import { useSelector, useDispatch } from 'react-redux' import './UserCollection.css' import LibraryHeader from '../../../components/libraryHeader/LibraryHeader' @@ -8,6 +9,7 @@ import SimpleModal from '../../../components/simpleModal/SimpleModal' import { farming, groupCollection } from '../CollectionData' import GroupModal from '../../../components/groupModal/GroupModal' import CardLayout from '../../../layout/cardLayout/CardLayout' +import { listCollections } from '../../../actions/collectionActions' const UserCollection = () => { const [active, setActive] = useState(false) @@ -16,6 +18,16 @@ const UserCollection = () => { const [groupModal, setGroupModal] = useState(false) const [newCollection, setNewCollection] = useState(false) + const data = useSelector( + (state) => state.listCollection.collections.collection + ) + console.log('collection', data) + const dispatch = useDispatch() + + useEffect(() => { + dispatch(listCollections()) + }, [dispatch]) + function openAddCollection () { setGroupModal(true) setModalActive(false) @@ -39,37 +51,29 @@ const UserCollection = () => {

Farming Collections

+
- { - farming.map(item => { - return ( -
- + data && data.map(item => { + return ( +
+ -
-
{item.category}
-

{item.title}

+
+
{item.category}
+

{item.name}

- -
-
- ) - }) + +
+
+ ) + }) } -
+
) From 2ec724ab5c45d191699ad54510622a331b28ad79 Mon Sep 17 00:00:00 2001 From: Dixit Sigdel Date: Tue, 1 Jun 2021 20:02:12 +0545 Subject: [PATCH 3/9] collection saved continuee --- ...210601084926-alternate_collection_table.js | 13 ++++++ api/src/controllers/collectionController.js | 23 +++++----- api/src/models/collectionModel.js | 6 +++ src/actions/collectionActions.js | 30 ++++++++++++- .../EnterprisesCollection.scss | 6 +-- src/components/libraryCard/LibraryCard.jsx | 2 +- src/constants/collectionConstants.js | 4 ++ .../savedCollection/SavedCollection.jsx | 36 +++++++++++---- .../library/userCollection/UserCollection.jsx | 45 +++++++++++-------- 9 files changed, 121 insertions(+), 44 deletions(-) create mode 100644 api/migrations/20210601084926-alternate_collection_table.js diff --git a/api/migrations/20210601084926-alternate_collection_table.js b/api/migrations/20210601084926-alternate_collection_table.js new file mode 100644 index 000000000..46c996cec --- /dev/null +++ b/api/migrations/20210601084926-alternate_collection_table.js @@ -0,0 +1,13 @@ + +module.exports = { + up: async (queryInterface, Sequelize) => { + queryInterface.addColumn('collections', 'status', { + type: Sequelize.BOOLEAN, + defaultValue: false + }) + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable('collections') + } +} diff --git a/api/src/controllers/collectionController.js b/api/src/controllers/collectionController.js index 3fb23642f..90380d92d 100644 --- a/api/src/controllers/collectionController.js +++ b/api/src/controllers/collectionController.js @@ -53,7 +53,7 @@ const getCollectionById = (req, res) => { // @todo we have to work on relation mapping betweenn collection and resources const addcollection = (req, res) => { - const { name, docType, resourceType, linkId, description } = req.body + const { name, docType, resourceType, linkId, description, category, status } = req.body let filename = '' if (req.file) { filename = req.file.filename @@ -64,7 +64,9 @@ const addcollection = (req, res) => { resourceType, linkId, description, - filename + filename, + category, + status }) .then(() => res.json({ message: 'Collection Created !!!' }).status(200)) .catch((err) => res.json({ error: err.message }).status(400)) @@ -75,20 +77,17 @@ const addcollection = (req, res) => { // @access Public const updateCollection = (req, res) => { - const { - name, docType, resourceType, linkId - } = req.body + // const { + // name, docType, resourceType, linkId,description,category,status + // } = req.body const id = req.params.id Collection.findByPk(id).then(collection => { if (collection) { const { id } = collection - Collection.update({ - name, - docType, - resourceType, - linkId - }, - { where: { id } }) + Collection.update( + req.body + , + { where: { id } }) .then(() => res.json({ message: 'Collection Updated !!!' }).status(200)) .catch((err) => res.json({ error: err.message }).status(400)) } diff --git a/api/src/models/collectionModel.js b/api/src/models/collectionModel.js index 6b1a72131..122c46371 100644 --- a/api/src/models/collectionModel.js +++ b/api/src/models/collectionModel.js @@ -26,6 +26,12 @@ const Collection = db.define( }, description: { type: Sequelize.STRING + }, + category: { + type: Sequelize.STRING + }, + status: { + type: Sequelize.BOOLEAN } }, { timestamps: true } diff --git a/src/actions/collectionActions.js b/src/actions/collectionActions.js index ce7b99b12..d18d85451 100644 --- a/src/actions/collectionActions.js +++ b/src/actions/collectionActions.js @@ -8,7 +8,10 @@ import { COLLECTION_SEARCH_FAIL, COLLECTION_CREATE_REQUEST, COLLECTION_CREATE_SUCCESS, - COLLECTION_CREATE_FAIL + COLLECTION_CREATE_FAIL, + COLLECTION_UPDATE_REQUEST, + COLLECTION_UPDATE_SUCCESS, + COLLECTION_UPDATE_FAIL } from '../constants/collectionConstants' export const listCollections = (sort = '', pageNumber = '') => async ( @@ -81,3 +84,28 @@ export const createCollection = (newCollection) => async (dispatch, getState) => dispatch({ type: COLLECTION_CREATE_FAIL, payload: message }) } } + +export const updateCollection = (updateCollection, id) => async (dispatch) => { + try { + dispatch({ + type: COLLECTION_UPDATE_REQUEST + }) + + const { data } = await axios.put( + `${process.env.REACT_APP_API_BASE_URL}/api/collection/${id}`, updateCollection + ) + dispatch({ + type: COLLECTION_UPDATE_SUCCESS, + payload: data + }) + } catch (error) { + const message = + error.response && error.response.data.message + ? error.response.data.message + : error.message + dispatch({ + type: COLLECTION_UPDATE_FAIL, + payload: message + }) + } +} diff --git a/src/components/enterprisesCollection/EnterprisesCollection.scss b/src/components/enterprisesCollection/EnterprisesCollection.scss index 80472f8c2..f478f4742 100644 --- a/src/components/enterprisesCollection/EnterprisesCollection.scss +++ b/src/components/enterprisesCollection/EnterprisesCollection.scss @@ -10,8 +10,8 @@ } .collection-modal-container > div { - width: 100%; - height: 100%; + /* width: 100%; */ + height: 80%; position: relative; overflow-y: scroll; margin-bottom: 100px; @@ -58,7 +58,7 @@ .drag-drop-container { width: 100%; - height: 100%; + height: 30%; position: relative; margin-bottom: 40px; } diff --git a/src/components/libraryCard/LibraryCard.jsx b/src/components/libraryCard/LibraryCard.jsx index 1f00f03ff..f8a8bfb49 100644 --- a/src/components/libraryCard/LibraryCard.jsx +++ b/src/components/libraryCard/LibraryCard.jsx @@ -7,7 +7,7 @@ const LibraryCard = ({ data }) => { <>
{ - data && data.map(item => { + data && data.filter(data => data.status === true).map(item => { return (
{ const [newCollection, setNewCollection] = useState(false) @@ -18,21 +20,39 @@ const SavedCollection = () => { setActive(false) } + const data = useSelector( + (state) => state.listCollection.collections.collection + ) + + const dispatch = useDispatch() + + useEffect(() => { + dispatch(listCollections()) + }, [dispatch]) + return ( <> - {modalActive && } + {modalActive && } {newCollection && } + {active && }
- {['Farming', 'Branding'].map((category) => -
-

{category} Collections

- -
- )} +
+

Farming Collections

+ +
+
+

Branding Collections

+ +
) diff --git a/src/screens/library/userCollection/UserCollection.jsx b/src/screens/library/userCollection/UserCollection.jsx index 281490a95..e40600868 100644 --- a/src/screens/library/userCollection/UserCollection.jsx +++ b/src/screens/library/userCollection/UserCollection.jsx @@ -9,7 +9,7 @@ import SimpleModal from '../../../components/simpleModal/SimpleModal' import { farming, groupCollection } from '../CollectionData' import GroupModal from '../../../components/groupModal/GroupModal' import CardLayout from '../../../layout/cardLayout/CardLayout' -import { listCollections } from '../../../actions/collectionActions' +import { listCollections, updateCollection } from '../../../actions/collectionActions' const UserCollection = () => { const [active, setActive] = useState(false) @@ -33,6 +33,13 @@ const UserCollection = () => { setModalActive(false) } + function handleClick (id) { + if (active == false) { + dispatch(updateCollection(id, ({ status: 'true' }))) + setActive(true) + } + } + return ( <> {groupModal && {
{ - data && data.map(item => { - return ( -
- - -
-
{item.category}
-

{item.name}

- - -
-
- ) - }) + data && data.map(item => { + return ( +
+ + +
+
{item.category}
+

{item.name}

+ + +
+
+ ) + }) }
From 18ef49ff97df01078e8a6bde28079369f8c0a976 Mon Sep 17 00:00:00 2001 From: Dixit Sigdel Date: Wed, 2 Jun 2021 19:38:02 +0545 Subject: [PATCH 4/9] collection and users and library manage --- api/controllers/collectionUserController.js | 30 ++++++++++++++ api/controllers/resourceUserController.js | 18 +++++++++ .../20210602063519-collection_users.js | 39 ++++++++++++++++++ .../20210602093915-resource_users.js | 40 +++++++++++++++++++ api/models/collectionUserModel.js | 33 +++++++++++++++ api/models/resourceUserModel.js | 32 +++++++++++++++ api/routes/collectionUserRouter.js | 7 ++++ api/routes/resourceUserRouter.js | 8 ++++ api/src/models/collectionModel.js | 7 ++++ api/src/models/userModel.js | 7 ++++ api/src/server.js | 4 ++ src/actions/resourceUserAction.js | 29 ++++++++++++++ src/components/listView/ListView.jsx | 16 +++++++- src/constants/resourceuserConstants.js | 3 ++ src/screens/library/collection/Collection.jsx | 2 + 15 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 api/controllers/collectionUserController.js create mode 100644 api/controllers/resourceUserController.js create mode 100644 api/migrations/20210602063519-collection_users.js create mode 100644 api/migrations/20210602093915-resource_users.js create mode 100644 api/models/collectionUserModel.js create mode 100644 api/models/resourceUserModel.js create mode 100644 api/routes/collectionUserRouter.js create mode 100644 api/routes/resourceUserRouter.js create mode 100644 src/actions/resourceUserAction.js create mode 100644 src/constants/resourceuserConstants.js diff --git a/api/controllers/collectionUserController.js b/api/controllers/collectionUserController.js new file mode 100644 index 000000000..3a4e5382e --- /dev/null +++ b/api/controllers/collectionUserController.js @@ -0,0 +1,30 @@ +const CollectionUser = require('../models/collectionUserModel') +const Sequelize = require('sequelize') +const Op = Sequelize.Op + +// @desc Fetch all collection_user +// @route Get/api/collection_user +// @access Private + +const paginate = ({ page, pageSize }) => { + const offset = page * pageSize + const limit = offset + pageSize + + return { + offset, + limit + } +} + +const addCollectionUser = (req, res) => { + const { userid, collection } = req.body + CollectionUser.create({ + userid, + collection + + }) + .then(() => res.json({ message: 'Collection User Created !!!' }).status(200)) + .catch((err) => res.json({ error: err.message }).status(400)) +} + +module.exports = { addCollectionUser } diff --git a/api/controllers/resourceUserController.js b/api/controllers/resourceUserController.js new file mode 100644 index 000000000..4fee8789b --- /dev/null +++ b/api/controllers/resourceUserController.js @@ -0,0 +1,18 @@ +const ResourceUser = require('../models/resourceUserModel') +const Sequelize = require('sequelize') +const Op = Sequelize.Op + +// @desc Add individual collection +// @route POST /api/resourceUser/add +// @access Private + +const addResourceUser = (req, res) => { + const { userId, resourceId } = req.body + ResourceUser.create({ + userId, resourceId + }) + .then(() => res.json({ message: 'Resource User Created !!!' }).this.status(200)) + .catch((err) => res.json({ error: err.message }).status(400)) +} + +module.exports = { addResourceUser } diff --git a/api/migrations/20210602063519-collection_users.js b/api/migrations/20210602063519-collection_users.js new file mode 100644 index 000000000..55d5d024c --- /dev/null +++ b/api/migrations/20210602063519-collection_users.js @@ -0,0 +1,39 @@ +module.exports = { + up: async (queryInterface, Sequelize) => { + queryInterface.createTable('collection_user', + { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + userid: { + type: Sequelize.INTEGER, + allowNull: false, + references: { + model: 'users', + key: 'id' + } + }, + collection: { + type: Sequelize.INTEGER, + allowNull: false, + references: { + model: 'collections', + key: 'id' + } + }, + createdAt: { + type: Sequelize.DATE + }, + updatedAt: { + type: Sequelize.DATE + } + } + ) + }, + + down: async (queryInterface, Sequelize) => { + queryInterface.dropTable('collection_user', {}) + } +} diff --git a/api/migrations/20210602093915-resource_users.js b/api/migrations/20210602093915-resource_users.js new file mode 100644 index 000000000..e4bc9819e --- /dev/null +++ b/api/migrations/20210602093915-resource_users.js @@ -0,0 +1,40 @@ + +module.exports = { + up: async (queryInterface, Sequelize) => { + queryInterface.createTable('resource_users', + { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + userId: { + type: Sequelize.INTEGER, + allowNull: false, + references: { + model: 'users', + key: 'id' + } + }, + resourceId: { + type: Sequelize.INTEGER, + allowNull: false, + references: { + model: 'resources', + key: 'id' + } + }, + createdAt: { + type: Sequelize.DATE + }, + updatedAt: { + type: Sequelize.DATE + } + } + ) + }, + + down: async (queryInterface, Sequelize) => { + queryInterface.dropTable('resource_users', {}) + } +} diff --git a/api/models/collectionUserModel.js b/api/models/collectionUserModel.js new file mode 100644 index 000000000..f603ad4b2 --- /dev/null +++ b/api/models/collectionUserModel.js @@ -0,0 +1,33 @@ +const Sequelize = require('sequelize') +const db = require('../config/database.js') + +const CollectionUser = db.define('collection_user', + { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + userid: { + type: Sequelize.INTEGER + }, + collection: { + type: Sequelize.INTEGER + } + + }, + { timestamps: true } +) + +CollectionUser.associate = (models) => { + CollectionUser.belongsTo(models.User, { + as: 'users', + foreignKey: 'userid' + }) + CollectionUser.belongsTo(models.Collection, { + as: 'collections', + foreignKey: 'collection' + }) +} + +module.exports = CollectionUser diff --git a/api/models/resourceUserModel.js b/api/models/resourceUserModel.js new file mode 100644 index 000000000..2f8df8817 --- /dev/null +++ b/api/models/resourceUserModel.js @@ -0,0 +1,32 @@ +const Sequelize = require('sequelize') +const db = require('../config/database.js') + +const ResourceUser = db.define('resource_users', + { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + userId: { + type: Sequelize.INTEGER + }, + resourceId: { + type: Sequelize.INTEGER + } + }, + { timestamps: true } +) + +ResourceUser.associate = (models) => { + ResourceUser.belongsTo(models.User, { + as: 'users', + foreignKey: 'userId' + }) + ResourceUser.belongsTo(models.Resource, { + as: 'resources', + foreignKey: 'resourceId' + }) +} + +module.exports = ResourceUser diff --git a/api/routes/collectionUserRouter.js b/api/routes/collectionUserRouter.js new file mode 100644 index 000000000..5a786ae5c --- /dev/null +++ b/api/routes/collectionUserRouter.js @@ -0,0 +1,7 @@ +const express = require('express') +const router = express.Router() +const {addCollectionUser} = require('../controllers/collectionUserController') + +router.route('/add').post(addCollectionUser) + +module.exports = router \ No newline at end of file diff --git a/api/routes/resourceUserRouter.js b/api/routes/resourceUserRouter.js new file mode 100644 index 000000000..dfd01f0bc --- /dev/null +++ b/api/routes/resourceUserRouter.js @@ -0,0 +1,8 @@ +const express = require('express') +const router = express.Router() + +const { addResourceUser } = require('../controllers/resourceUserController') + +router.route('/add').post(addResourceUser) + +module.exports = router diff --git a/api/src/models/collectionModel.js b/api/src/models/collectionModel.js index 122c46371..66c56e312 100644 --- a/api/src/models/collectionModel.js +++ b/api/src/models/collectionModel.js @@ -37,4 +37,11 @@ const Collection = db.define( { timestamps: true } ) +Collection.associate = function (models) { + Collection.hasMany(models.CollectionUser, { + as: 'collection_user', + foreignKey: 'collection' + }) +} + module.exports = Collection diff --git a/api/src/models/userModel.js b/api/src/models/userModel.js index e01e0a663..4e7049438 100644 --- a/api/src/models/userModel.js +++ b/api/src/models/userModel.js @@ -13,4 +13,11 @@ const User = db.define('users', { } }, { timestamps: false }) +User.associate = function (models) { + User.hasMany(models.CollectionUser, { + as: 'collection_user', + foreignKey: 'userid' + }) +} + module.exports = User diff --git a/api/src/server.js b/api/src/server.js index 9f5773194..4d3711852 100644 --- a/api/src/server.js +++ b/api/src/server.js @@ -9,6 +9,8 @@ const newsRoutes = require('./routes/newsRouter') const enterprisesRoutes = require('./routes/enterprisesRouter') const communityGroupsRoutes = require('./routes/communityGroupRouter') const calendarRoutes = require('./routes/calendarEventsRouter') +const collectionUserRoutes = require('./routes/collectionUserRouter') +const resourceUserRoutes = require('./routes/resourceUserRouter') const sequelize = require('./config/database.js') const cors = require('cors') const dotenv = require('dotenv') @@ -24,6 +26,8 @@ dotenv.config() app.use('/api/users', userRoutes) app.use('/api/resources', resourceRoutes) app.use('/api/collection', collectionRoutes) +app.use('/api/collectionUser', collectionUserRoutes) +app.use('/api/resourceUser', resourceUserRoutes) app.use('/api/enterprises', enterprisesRoutes) app.use('/api/groups', communityGroupsRoutes) app.use('/api/calendar', calendarRoutes) diff --git a/src/actions/resourceUserAction.js b/src/actions/resourceUserAction.js new file mode 100644 index 000000000..8ed1af9bd --- /dev/null +++ b/src/actions/resourceUserAction.js @@ -0,0 +1,29 @@ +import axios from 'axios' +import { + RESOURCE_USER_CREATE_REQUEST, + RESOURCE_USER_CREATE_SUCCESS, + RESOURCE_USER_CREATE_FAIL +} from '../constants/resourceuserConstants' + +export const createResourceUser = (newResourceUser) => async (dispatch) => { + try { + dispatch({ + type: RESOURCE_USER_CREATE_REQUEST + }) + + const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/resourceUser/add`, newResourceUser) + dispatch({ + type: RESOURCE_USER_CREATE_SUCCESS, + payload: data + }) + } catch (error) { + const message = + error.response && error.response.data.message + ? error.response.data.message + : error.message + dispatch({ + type: RESOURCE_USER_CREATE_FAIL, + payload: message + }) + } +} diff --git a/src/components/listView/ListView.jsx b/src/components/listView/ListView.jsx index 8ad981280..28d642a97 100644 --- a/src/components/listView/ListView.jsx +++ b/src/components/listView/ListView.jsx @@ -3,12 +3,24 @@ import CardLayout from '../../layout/cardLayout/CardLayout' import useSizeFinder from '../../utils/sizeFinder' import './ListView.css' import { useParams } from 'react-router-dom' +import { useDispatch, useSelector } from 'react-redux' +import { createResourceUser } from '../../actions/resourceUserAction' const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }) => { const [active, setActive] = useState(false) + const dispatch = useDispatch() + const userInfo = useSelector((state) => state.userLogin.userInfo.id) + function clickHandle (id) { - setActive(!active) + if (active === false) { + dispatch( + createResourceUser({ userId: userInfo, resourceId: id }) + ) + } + if (id) { + setActive(true) + } } return ( @@ -28,7 +40,7 @@ const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }
Add to
diff --git a/src/constants/resourceuserConstants.js b/src/constants/resourceuserConstants.js new file mode 100644 index 000000000..04ed42a56 --- /dev/null +++ b/src/constants/resourceuserConstants.js @@ -0,0 +1,3 @@ +export const RESOURCE_USER_CREATE_REQUEST = 'RESOURCE_USER_CREATE_REQUEST' +export const RESOURCE_USER_CREATE_SUCCESS = 'RESOURCE_USER_CREATE_SUCCESS' +export const RESOURCE_USER_CREATE_FAIL = 'RESOURCE_USER_CREATE_FAIL' diff --git a/src/screens/library/collection/Collection.jsx b/src/screens/library/collection/Collection.jsx index e2c8c4650..0ebd4ddcf 100644 --- a/src/screens/library/collection/Collection.jsx +++ b/src/screens/library/collection/Collection.jsx @@ -36,6 +36,8 @@ const Collection = () => { const data = useSelector( (state) => state.listCollection.collections.collection ) + const userInfo = useSelector((state) => state.userLogin) + console.log('userinfo', userInfo) console.log('another', data) From 73e5d2d550dd4ac9ec6c6cc41f470fc14d0ba086 Mon Sep 17 00:00:00 2001 From: Dixit Sigdel Date: Mon, 7 Jun 2021 18:35:14 +0545 Subject: [PATCH 5/9] add into my library --- api/controllers/collectionUserController.js | 30 -------------- api/controllers/resourceUserController.js | 18 --------- .../20210602063519-collection_users.js | 39 ------------------- api/routes/collectionUserRouter.js | 7 ---- .../controllers/collectionUserController.js | 29 ++++++++++++++ api/src/controllers/resourceUserController.js | 37 ++++++++++++++++++ .../20210530092345-alter_collections.js | 0 .../20210531094440-alter_collections.js | 0 ...210601084926-alternate_collection_table.js | 0 .../20210602093915-resource_users.js | 0 .../20210603071204-collection_users.js | 33 ++++++++++++++++ api/src/models/collectionModel.js | 4 +- api/{ => src}/models/collectionUserModel.js | 12 +++--- api/src/models/resourceModel.js | 8 ++++ api/{ => src}/models/resourceUserModel.js | 13 ++++--- api/src/models/userModel.js | 10 ++++- api/src/routes/collectionUserRouter.js | 8 ++++ api/{ => src}/routes/resourceUserRouter.js | 3 +- src/actions/resourceUserAction.js | 28 +++++++++++++ .../collectionModal/CollectionModal.jsx | 34 ++++++++++++++++ src/components/groupUsers/GroupUsers.jsx | 22 +++++------ src/components/listView/ListView.jsx | 10 ++--- src/constants/resourceuserConstants.js | 4 ++ 23 files changed, 222 insertions(+), 127 deletions(-) delete mode 100644 api/controllers/collectionUserController.js delete mode 100644 api/controllers/resourceUserController.js delete mode 100644 api/migrations/20210602063519-collection_users.js delete mode 100644 api/routes/collectionUserRouter.js create mode 100644 api/src/controllers/collectionUserController.js create mode 100644 api/src/controllers/resourceUserController.js rename api/{ => src}/migrations/20210530092345-alter_collections.js (100%) rename api/{ => src}/migrations/20210531094440-alter_collections.js (100%) rename api/{ => src}/migrations/20210601084926-alternate_collection_table.js (100%) rename api/{ => src}/migrations/20210602093915-resource_users.js (100%) create mode 100644 api/src/migrations/20210603071204-collection_users.js rename api/{ => src}/models/collectionUserModel.js (80%) rename api/{ => src}/models/resourceUserModel.js (67%) create mode 100644 api/src/routes/collectionUserRouter.js rename api/{ => src}/routes/resourceUserRouter.js (50%) diff --git a/api/controllers/collectionUserController.js b/api/controllers/collectionUserController.js deleted file mode 100644 index 3a4e5382e..000000000 --- a/api/controllers/collectionUserController.js +++ /dev/null @@ -1,30 +0,0 @@ -const CollectionUser = require('../models/collectionUserModel') -const Sequelize = require('sequelize') -const Op = Sequelize.Op - -// @desc Fetch all collection_user -// @route Get/api/collection_user -// @access Private - -const paginate = ({ page, pageSize }) => { - const offset = page * pageSize - const limit = offset + pageSize - - return { - offset, - limit - } -} - -const addCollectionUser = (req, res) => { - const { userid, collection } = req.body - CollectionUser.create({ - userid, - collection - - }) - .then(() => res.json({ message: 'Collection User Created !!!' }).status(200)) - .catch((err) => res.json({ error: err.message }).status(400)) -} - -module.exports = { addCollectionUser } diff --git a/api/controllers/resourceUserController.js b/api/controllers/resourceUserController.js deleted file mode 100644 index 4fee8789b..000000000 --- a/api/controllers/resourceUserController.js +++ /dev/null @@ -1,18 +0,0 @@ -const ResourceUser = require('../models/resourceUserModel') -const Sequelize = require('sequelize') -const Op = Sequelize.Op - -// @desc Add individual collection -// @route POST /api/resourceUser/add -// @access Private - -const addResourceUser = (req, res) => { - const { userId, resourceId } = req.body - ResourceUser.create({ - userId, resourceId - }) - .then(() => res.json({ message: 'Resource User Created !!!' }).this.status(200)) - .catch((err) => res.json({ error: err.message }).status(400)) -} - -module.exports = { addResourceUser } diff --git a/api/migrations/20210602063519-collection_users.js b/api/migrations/20210602063519-collection_users.js deleted file mode 100644 index 55d5d024c..000000000 --- a/api/migrations/20210602063519-collection_users.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = { - up: async (queryInterface, Sequelize) => { - queryInterface.createTable('collection_user', - { - id: { - type: Sequelize.INTEGER, - primaryKey: true, - autoIncrement: true - }, - userid: { - type: Sequelize.INTEGER, - allowNull: false, - references: { - model: 'users', - key: 'id' - } - }, - collection: { - type: Sequelize.INTEGER, - allowNull: false, - references: { - model: 'collections', - key: 'id' - } - }, - createdAt: { - type: Sequelize.DATE - }, - updatedAt: { - type: Sequelize.DATE - } - } - ) - }, - - down: async (queryInterface, Sequelize) => { - queryInterface.dropTable('collection_user', {}) - } -} diff --git a/api/routes/collectionUserRouter.js b/api/routes/collectionUserRouter.js deleted file mode 100644 index 5a786ae5c..000000000 --- a/api/routes/collectionUserRouter.js +++ /dev/null @@ -1,7 +0,0 @@ -const express = require('express') -const router = express.Router() -const {addCollectionUser} = require('../controllers/collectionUserController') - -router.route('/add').post(addCollectionUser) - -module.exports = router \ No newline at end of file diff --git a/api/src/controllers/collectionUserController.js b/api/src/controllers/collectionUserController.js new file mode 100644 index 000000000..7c357e60d --- /dev/null +++ b/api/src/controllers/collectionUserController.js @@ -0,0 +1,29 @@ +const CollectionUser = require('../models/collectionUserModel') +const Collection = require('../models/collectionModel') +const Sequelize = require('sequelize') +const User = require('../models/userModel') +const Op = Sequelize.Op + +// @desc Fetch all collection_user +// @route Get/api/collection_user +// @access Private +const getControllerUser = (res, req) => { + CollectionUser.findAll({ include: [{ model: Collection, as: 'collection' }, { model: User, as: 'user' }] }) + .then(items => { + res.json({ items }) + }) + .catch((err) => res.json({ err }).status(400)) +} + +const addCollectionUser = (req, res) => { + const { userId, collectionId } = req.body + CollectionUser.create({ + userId, + collectionId + + }) + .then(() => res.json({ message: 'Collection User Created !!!' }).status(200)) + .catch((err) => res.json({ error: err.message }).status(400)) +} + +module.exports = { addCollectionUser, getControllerUser } diff --git a/api/src/controllers/resourceUserController.js b/api/src/controllers/resourceUserController.js new file mode 100644 index 000000000..962c4c66d --- /dev/null +++ b/api/src/controllers/resourceUserController.js @@ -0,0 +1,37 @@ +const ResourceUser = require('../models/resourceUserModel') +const Resource = require('../models/resourceModel') +const Sequelize = require('sequelize') +const User = require('../models/userModel') +const Op = Sequelize.Op + +// @desc Fetch all course +// @route GET/api/courses +// @access Public + +const getResourceUser = (req, res) => { + const pageSize = 10 + const page = Number(req.query.pageNumber) || 1 + const order = req.query.order || 'ASC' + ResourceUser.findAll({ include: [Resource] }) + .then(items => { + res.json({ items }).status(200) + }) + .catch((error) => res.json({ error }).status(400)) +} + +// @desc Add individual collection +// @route POST /api/resourceUser/add +// @access Private + +const addResourceUser = (req, res) => { + const user = User.findOne({ where: { id: req.body.userId } }) + + const { resourceId } = req.body + ResourceUser.create({ + userId: user, resourceId + }) + .then(() => res.json({ message: 'Resource User Created !!!' }).this.status(200)) + .catch((err) => res.json({ error: err.message }).status(400)) +} + +module.exports = { addResourceUser, getResourceUser } diff --git a/api/migrations/20210530092345-alter_collections.js b/api/src/migrations/20210530092345-alter_collections.js similarity index 100% rename from api/migrations/20210530092345-alter_collections.js rename to api/src/migrations/20210530092345-alter_collections.js diff --git a/api/migrations/20210531094440-alter_collections.js b/api/src/migrations/20210531094440-alter_collections.js similarity index 100% rename from api/migrations/20210531094440-alter_collections.js rename to api/src/migrations/20210531094440-alter_collections.js diff --git a/api/migrations/20210601084926-alternate_collection_table.js b/api/src/migrations/20210601084926-alternate_collection_table.js similarity index 100% rename from api/migrations/20210601084926-alternate_collection_table.js rename to api/src/migrations/20210601084926-alternate_collection_table.js diff --git a/api/migrations/20210602093915-resource_users.js b/api/src/migrations/20210602093915-resource_users.js similarity index 100% rename from api/migrations/20210602093915-resource_users.js rename to api/src/migrations/20210602093915-resource_users.js diff --git a/api/src/migrations/20210603071204-collection_users.js b/api/src/migrations/20210603071204-collection_users.js new file mode 100644 index 000000000..9debf582e --- /dev/null +++ b/api/src/migrations/20210603071204-collection_users.js @@ -0,0 +1,33 @@ + +module.exports = { + up: async (queryInterface, Sequelize) => { + queryInterface.createTable('collection_users', + { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + userId: { + type: Sequelize.INTEGER, + allowNull: false + }, + collectionId: { + type: Sequelize.INTEGER, + allowNull: false + }, + createdAt: { + type: Sequelize.DATE + }, + updatedAt: { + type: Sequelize.DATE + } + + } + ) + }, + + down: async (queryInterface, Sequelize) => { + queryInterface.dropTable('collection_users',{}) + } +}; diff --git a/api/src/models/collectionModel.js b/api/src/models/collectionModel.js index 66c56e312..c3730c162 100644 --- a/api/src/models/collectionModel.js +++ b/api/src/models/collectionModel.js @@ -39,8 +39,8 @@ const Collection = db.define( Collection.associate = function (models) { Collection.hasMany(models.CollectionUser, { - as: 'collection_user', - foreignKey: 'collection' + as: 'collection', + foreignKey: 'collectionId' }) } diff --git a/api/models/collectionUserModel.js b/api/src/models/collectionUserModel.js similarity index 80% rename from api/models/collectionUserModel.js rename to api/src/models/collectionUserModel.js index f603ad4b2..1f3f48ad6 100644 --- a/api/models/collectionUserModel.js +++ b/api/src/models/collectionUserModel.js @@ -8,10 +8,10 @@ const CollectionUser = db.define('collection_user', primaryKey: true, autoIncrement: true }, - userid: { + userId: { type: Sequelize.INTEGER }, - collection: { + collectionId: { type: Sequelize.INTEGER } @@ -21,12 +21,12 @@ const CollectionUser = db.define('collection_user', CollectionUser.associate = (models) => { CollectionUser.belongsTo(models.User, { - as: 'users', - foreignKey: 'userid' + as: 'user', + foreignKey: 'userId' }) CollectionUser.belongsTo(models.Collection, { - as: 'collections', - foreignKey: 'collection' + as: 'collection', + foreignKey: 'collectionId' }) } diff --git a/api/src/models/resourceModel.js b/api/src/models/resourceModel.js index c03a96193..96e224e50 100644 --- a/api/src/models/resourceModel.js +++ b/api/src/models/resourceModel.js @@ -1,5 +1,6 @@ const Sequelize = require('sequelize') const db = require('../config/database.js') +const ResourceUser = require('./resourceUserModel.js') const Resources = db.define('resources', { @@ -91,4 +92,11 @@ const Resources = db.define('resources', { timestamps: false } ) +Resources.associate = function (models) { + Resources.belongsToMany(ResourceUser, { + as: 'resource', + foreignKey: 'id' + }) +} + module.exports = Resources diff --git a/api/models/resourceUserModel.js b/api/src/models/resourceUserModel.js similarity index 67% rename from api/models/resourceUserModel.js rename to api/src/models/resourceUserModel.js index 2f8df8817..4c1893c07 100644 --- a/api/models/resourceUserModel.js +++ b/api/src/models/resourceUserModel.js @@ -1,4 +1,5 @@ const Sequelize = require('sequelize') +const User = require('./userModel') const db = require('../config/database.js') const ResourceUser = db.define('resource_users', @@ -19,13 +20,13 @@ const ResourceUser = db.define('resource_users', ) ResourceUser.associate = (models) => { - ResourceUser.belongsTo(models.User, { - as: 'users', - foreignKey: 'userId' + ResourceUser.belongsToMany(models.User, { + foreignKey: 'userId', + as: 'user' }) - ResourceUser.belongsTo(models.Resource, { - as: 'resources', - foreignKey: 'resourceId' + ResourceUser.belongsToMany(models.Resource, { + foreignKey: 'resourceId', + as: 'resource' }) } diff --git a/api/src/models/userModel.js b/api/src/models/userModel.js index 4e7049438..1046f9987 100644 --- a/api/src/models/userModel.js +++ b/api/src/models/userModel.js @@ -15,8 +15,14 @@ const User = db.define('users', { User.associate = function (models) { User.hasMany(models.CollectionUser, { - as: 'collection_user', - foreignKey: 'userid' + as: 'user', + foreignKey: 'id' + }) +} +User.associate = function (models) { + User.hasMany(models.ResourceUser, { + as: 'user', + foreignKey: 'id' }) } diff --git a/api/src/routes/collectionUserRouter.js b/api/src/routes/collectionUserRouter.js new file mode 100644 index 000000000..785c5e686 --- /dev/null +++ b/api/src/routes/collectionUserRouter.js @@ -0,0 +1,8 @@ +const express = require('express') +const router = express.Router() +const { addCollectionUser, getControllerUser } = require('../controllers/collectionUserController') + +router.route('/add').post(addCollectionUser) +router.route('/').get(getControllerUser) + +module.exports = router diff --git a/api/routes/resourceUserRouter.js b/api/src/routes/resourceUserRouter.js similarity index 50% rename from api/routes/resourceUserRouter.js rename to api/src/routes/resourceUserRouter.js index dfd01f0bc..c565600de 100644 --- a/api/routes/resourceUserRouter.js +++ b/api/src/routes/resourceUserRouter.js @@ -1,8 +1,9 @@ const express = require('express') const router = express.Router() -const { addResourceUser } = require('../controllers/resourceUserController') +const { addResourceUser, getResourceUser } = require('../controllers/resourceUserController') +router.route('/').get(getResourceUser) router.route('/add').post(addResourceUser) module.exports = router diff --git a/src/actions/resourceUserAction.js b/src/actions/resourceUserAction.js index 8ed1af9bd..f73e4ff0a 100644 --- a/src/actions/resourceUserAction.js +++ b/src/actions/resourceUserAction.js @@ -1,10 +1,38 @@ import axios from 'axios' import { + RESOURCE_USER_LIST_REQUEST, + RESOURCE_USER_LIST_SUCCESS, + RESOURCE_USER_LIST_FAIL, RESOURCE_USER_CREATE_REQUEST, RESOURCE_USER_CREATE_SUCCESS, RESOURCE_USER_CREATE_FAIL } from '../constants/resourceuserConstants' +export const listCollectionUser = (sort = '', pageNumber = '') => async ( + dispatch +) => { + try { + dispatch({ type: RESOURCE_USER_LIST_REQUEST }) + const { data } = await axios.get( + `${process.env.REACT_APP_API_BASE_URL}/api/resourceUser` + ) + console.log('data', data) + dispatch({ + type: RESOURCE_USER_LIST_SUCCESS, + payload: data + }) + } catch (error) { + dispatch({ + type: RESOURCE_USER_LIST_FAIL, + payload: + error.response && error.response.data.message + ? error.response.data.message + : error.message + + }) + } +} + export const createResourceUser = (newResourceUser) => async (dispatch) => { try { dispatch({ diff --git a/src/components/collectionModal/CollectionModal.jsx b/src/components/collectionModal/CollectionModal.jsx index dfabdc3da..817fe54d7 100644 --- a/src/components/collectionModal/CollectionModal.jsx +++ b/src/components/collectionModal/CollectionModal.jsx @@ -4,6 +4,7 @@ import { useLocation } from 'react-router-dom' import { useDispatch } from 'react-redux' import { createResource } from '../../actions/resourceActions' import SimpleFilter from '../simpleFilter/SimpleFilter' +import { createCollection } from '../../actions/collectionActions' import { collectionFilterData } from '../../constants/sampleData' import CollectionModalHeader from '../newsCreateModal/CollectionModalHeader' import DragDrop from '../dragDrop/DragDrop' @@ -15,6 +16,9 @@ const CollectionModal = ({ setActive, openAddCollection, name }) => { const dispatch = useDispatch() const [resourceTitleError, setResourceTitleError] = useState(false) const [resourceDescriptionError, setResourceDescriptionError] = useState(false) + const [collectionTitle, setCollectionTitle] = useState('') + const [collectionTitleError, setCollectionTitleError] = useState(false) + const { pathname } = useLocation() const resourceTitleChange = (e) => { @@ -36,6 +40,19 @@ const CollectionModal = ({ setActive, openAddCollection, name }) => { setActive(false) } } + const collectionTitleChange = (e) => { + setCollectionTitle(e.target.value) + setCollectionTitleError(false) + } + const handleAddCollection = async (e) => { + e.preventDefault() + if (!collectionTitle) setCollectionTitleError(true) + + if (collectionTitle) { + dispatch(createCollection({ name: collectionTitle })) + setActive(false) + } + } return ( <> @@ -61,6 +78,23 @@ const CollectionModal = ({ setActive, openAddCollection, name }) => { }
+ + {pathname === '/library' + ? <> +
+ resourceTitleChange(e)} placeholder='Resource title' />
+ resourceDescriptionChange(e)} placeholder='Resource description' />
+
+ + + : <> +
+ collectionTitleChange(e)} placeholder='Collection title' />
+ +
+
openAddCollection()}>Add Files
+ + }
diff --git a/src/components/groupUsers/GroupUsers.jsx b/src/components/groupUsers/GroupUsers.jsx index e6e66286f..c704b40c4 100644 --- a/src/components/groupUsers/GroupUsers.jsx +++ b/src/components/groupUsers/GroupUsers.jsx @@ -8,17 +8,17 @@ const GroupUsers = ({ data }) => { <> { - data.map(d => ( -
-
-
- users -
-

{d.name && d.name}

-
- -
- )) + data && data.map(d => ( +
+
+
+ users +
+

{d.name && d.name}

+
+ +
+ )) } diff --git a/src/components/listView/ListView.jsx b/src/components/listView/ListView.jsx index 28d642a97..48d055612 100644 --- a/src/components/listView/ListView.jsx +++ b/src/components/listView/ListView.jsx @@ -8,6 +8,7 @@ import { createResourceUser } from '../../actions/resourceUserAction' const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }) => { const [active, setActive] = useState(false) + const [isAdded, setIsAdded] = useState() const dispatch = useDispatch() const userInfo = useSelector((state) => state.userLogin.userInfo.id) @@ -18,16 +19,15 @@ const ListView = ({ data, title, setNewCollection, setModalActive, modalActive } createResourceUser({ userId: userInfo, resourceId: id }) ) } - if (id) { - setActive(true) - } + + setActive(true) } return ( <>

{title}

- {data && data.map(item => { + {data && data.map((item, index) => { return (
@@ -39,7 +39,7 @@ const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }
Add to - diff --git a/src/constants/resourceuserConstants.js b/src/constants/resourceuserConstants.js index 04ed42a56..a314ab0db 100644 --- a/src/constants/resourceuserConstants.js +++ b/src/constants/resourceuserConstants.js @@ -1,3 +1,7 @@ +export const RESOURCE_USER_LIST_REQUEST = 'RESOURCE_USER_LIST_REQUEST' +export const RESOURCE_USER_LIST_SUCCESS = 'RESOURCE_USER_LIST_SUCCESS' +export const RESOURCE_USER_LIST_FAIL = 'RESOURCE_USER_LIST_FAIL' + export const RESOURCE_USER_CREATE_REQUEST = 'RESOURCE_USER_CREATE_REQUEST' export const RESOURCE_USER_CREATE_SUCCESS = 'RESOURCE_USER_CREATE_SUCCESS' export const RESOURCE_USER_CREATE_FAIL = 'RESOURCE_USER_CREATE_FAIL' From 412833d16b794a47b33bbd09ae64930d2c2f2b9e Mon Sep 17 00:00:00 2001 From: Dixit Sigdel Date: Wed, 9 Jun 2021 20:43:02 +0545 Subject: [PATCH 6/9] collection and resource --- .../controllers/collectionUserController.js | 43 ++++++++++++-- api/src/controllers/resourceUserController.js | 49 ++++++++++++++-- .../20210530092345-alter_collections.js | 4 +- .../20210531094440-alter_collections.js | 2 +- api/src/models/collectionModel.js | 2 +- api/src/models/collectionUserModel.js | 4 +- api/src/models/resourceModel.js | 7 ++- api/src/models/resourceUserModel.js | 12 ++-- api/src/models/userModel.js | 8 +-- api/src/routes/collectionUserRouter.js | 3 +- src/actions/collectionActions.js | 2 +- src/actions/collectionUserActions.js | 32 +++++++++++ src/actions/resourceUserAction.js | 2 +- src/components/libraryCard/LibraryCard.jsx | 10 ++-- src/components/listView/ListView.jsx | 20 +++---- src/constants/collectionUserConstants.js | 7 +++ src/reducers/resourceUserReducers.js | 24 ++++++++ src/screens/library/collection/Collection.jsx | 57 ++++++++++--------- .../savedCollection/SavedCollection.jsx | 18 +++--- .../library/userCollection/UserCollection.jsx | 14 +++-- src/store.js | 2 + 21 files changed, 230 insertions(+), 92 deletions(-) create mode 100644 src/actions/collectionUserActions.js create mode 100644 src/constants/collectionUserConstants.js create mode 100644 src/reducers/resourceUserReducers.js diff --git a/api/src/controllers/collectionUserController.js b/api/src/controllers/collectionUserController.js index 7c357e60d..b8f2c5775 100644 --- a/api/src/controllers/collectionUserController.js +++ b/api/src/controllers/collectionUserController.js @@ -7,14 +7,14 @@ const Op = Sequelize.Op // @desc Fetch all collection_user // @route Get/api/collection_user // @access Private -const getControllerUser = (res, req) => { - CollectionUser.findAll({ include: [{ model: Collection, as: 'collection' }, { model: User, as: 'user' }] }) +const getControllerUser = (req, res) => { + CollectionUser.findAll({ include: [{ model: Collection, as: 'collectionInfo' }, { model: User, as: 'user' }] }) .then(items => { - res.json({ items }) + res.json({ items }).status(200) }) .catch((err) => res.json({ err }).status(400)) } - +// @desc Add individual collection user const addCollectionUser = (req, res) => { const { userId, collectionId } = req.body CollectionUser.create({ @@ -26,4 +26,37 @@ const addCollectionUser = (req, res) => { .catch((err) => res.json({ error: err.message }).status(400)) } -module.exports = { addCollectionUser, getControllerUser } +// @desc Update a collection user + +const updateCollectionUser = (req, res) => { + CollectionUser.findByPk(id).then(collectionUser => { + if (collectionUser) { + const { id } = collectionUser + CollectionUser.update( + req.body, + { where: { id } }) + .then(() => res.json({ message: 'Collection user updated !!!' })) + .catch((err) => res.json({ error: err.message }).status(400)) + } + res.status(400) + throw new Error('Collection User not found') + }) +} + +// @desc Delete a collectionUser +const deleteController = (req, res) => { + const id = req.params.id + CollectionUser.findByPk(id).then(controllerUser => { + if (controllerUser) { + const { id } = controllerUser + CollectionUser.destroy({ where: { id } }) + .then(() => res.json({ message: 'Controller User Delete!!!' })) + .catch((err) => res.json({ err: err.message }).status(400)) + } else { + res.status(404) + throw new Error('Controller User not found') + } + }) +} + +module.exports = { addCollectionUser, getControllerUser, updateCollectionUser, deleteController } diff --git a/api/src/controllers/resourceUserController.js b/api/src/controllers/resourceUserController.js index 962c4c66d..4c08c29ea 100644 --- a/api/src/controllers/resourceUserController.js +++ b/api/src/controllers/resourceUserController.js @@ -12,26 +12,63 @@ const getResourceUser = (req, res) => { const pageSize = 10 const page = Number(req.query.pageNumber) || 1 const order = req.query.order || 'ASC' - ResourceUser.findAll({ include: [Resource] }) + ResourceUser.findAll({ include: [{ model: User, as: 'userfollower' }, { model: Resource, as: 'resourceInfo' }] }) .then(items => { res.json({ items }).status(200) }) .catch((error) => res.json({ error }).status(400)) } -// @desc Add individual collection +// @desc Add individual resource User // @route POST /api/resourceUser/add // @access Private const addResourceUser = (req, res) => { - const user = User.findOne({ where: { id: req.body.userId } }) + // const user = User.findOne({ where: { id: req.body.id } }) - const { resourceId } = req.body + const { userId, resourceId } = req.body ResourceUser.create({ - userId: user, resourceId + userId, resourceId }) .then(() => res.json({ message: 'Resource User Created !!!' }).this.status(200)) .catch((err) => res.json({ error: err.message }).status(400)) } -module.exports = { addResourceUser, getResourceUser } +// @desc Update a ResourceUser +// @route PUT /api/ResourceUser/:id +// @access Public + +const updateResourceUser = (req, res) => { + ResourceUser.findByPk(id).then(resourceUser => { + if (resourceUser) { + const { id } = resourceUser + ResourceUser.update( + req.body, + { where: { id } }) + .then(() => res.json({ message: 'Resource User updated !!' })) + .catch((err) => res.json({ error: err.message }).status(400)) + } + res.status(404) + throw new Error('Resource User not found') + }) +} + +// @desc Delete a resourceUser +// @route Delete /api/resourceUser/:id +// @access Public +const deleteResourceUser = (req, res) => { + const id = req.params.id + ResourceUser.findByPk(id).then(resourceUser => { + if (resourceUser) { + const { id } = resourceUser + ResourceUser.destroy({ where: { id } }) + .then(() => res.json({ message: 'Resource User Deleted !!!' })) + .catch((err) => res.json({ err: err.message }).status(400)) + } else { + res.status(404) + throw new Error('Resource User not found') + } + }) +} + +module.exports = { addResourceUser, getResourceUser, updateResourceUser, deleteResourceUser } diff --git a/api/src/migrations/20210530092345-alter_collections.js b/api/src/migrations/20210530092345-alter_collections.js index 07a081b71..5ad894a4a 100644 --- a/api/src/migrations/20210530092345-alter_collections.js +++ b/api/src/migrations/20210530092345-alter_collections.js @@ -6,7 +6,7 @@ module.exports = { }, down: async (queryInterface, Sequelize) => { - queryInterface.addColumn('collections', 'filename', Sequelize.STRING) - queryInterface.addColumn('collections', 'description', Sequelize.STRING) + queryInterface.removeColumn('collections', 'filename', Sequelize.STRING) + queryInterface.removeColumn('collections', 'description', Sequelize.STRING) } } diff --git a/api/src/migrations/20210531094440-alter_collections.js b/api/src/migrations/20210531094440-alter_collections.js index 28313998a..dc49a5d01 100644 --- a/api/src/migrations/20210531094440-alter_collections.js +++ b/api/src/migrations/20210531094440-alter_collections.js @@ -5,6 +5,6 @@ module.exports = { }, down: async (queryInterface, Sequelize) => { - queryInterface.addColumn('collections', 'category', Sequelize.STRING) + queryInterface.removeColumn('collections', 'category', Sequelize.STRING) } } diff --git a/api/src/models/collectionModel.js b/api/src/models/collectionModel.js index c3730c162..c9ac7ffe9 100644 --- a/api/src/models/collectionModel.js +++ b/api/src/models/collectionModel.js @@ -39,7 +39,7 @@ const Collection = db.define( Collection.associate = function (models) { Collection.hasMany(models.CollectionUser, { - as: 'collection', + as: 'collectionInfo', foreignKey: 'collectionId' }) } diff --git a/api/src/models/collectionUserModel.js b/api/src/models/collectionUserModel.js index 1f3f48ad6..79389d8d9 100644 --- a/api/src/models/collectionUserModel.js +++ b/api/src/models/collectionUserModel.js @@ -21,11 +21,11 @@ const CollectionUser = db.define('collection_user', CollectionUser.associate = (models) => { CollectionUser.belongsTo(models.User, { - as: 'user', + as: 'userfollower', foreignKey: 'userId' }) CollectionUser.belongsTo(models.Collection, { - as: 'collection', + as: 'collectionInfo', foreignKey: 'collectionId' }) } diff --git a/api/src/models/resourceModel.js b/api/src/models/resourceModel.js index 96e224e50..daa627ea8 100644 --- a/api/src/models/resourceModel.js +++ b/api/src/models/resourceModel.js @@ -93,9 +93,10 @@ const Resources = db.define('resources', ) Resources.associate = function (models) { - Resources.belongsToMany(ResourceUser, { - as: 'resource', - foreignKey: 'id' + Resources.hasMany(models.ResourceUser, { + as: 'resourceInfo', + foreignKey: 'resourceId' + }) } diff --git a/api/src/models/resourceUserModel.js b/api/src/models/resourceUserModel.js index 4c1893c07..9b30cf955 100644 --- a/api/src/models/resourceUserModel.js +++ b/api/src/models/resourceUserModel.js @@ -20,13 +20,11 @@ const ResourceUser = db.define('resource_users', ) ResourceUser.associate = (models) => { - ResourceUser.belongsToMany(models.User, { - foreignKey: 'userId', - as: 'user' - }) - ResourceUser.belongsToMany(models.Resource, { - foreignKey: 'resourceId', - as: 'resource' + ResourceUser.belongsTo(User) + + ResourceUser.belongsTo(models.Resource, { + foreignKey: 'resourceId' + }) } diff --git a/api/src/models/userModel.js b/api/src/models/userModel.js index 1046f9987..1bcf94e0c 100644 --- a/api/src/models/userModel.js +++ b/api/src/models/userModel.js @@ -15,14 +15,14 @@ const User = db.define('users', { User.associate = function (models) { User.hasMany(models.CollectionUser, { - as: 'user', - foreignKey: 'id' + as: 'userfollower', + foreignKey: 'userId' }) } User.associate = function (models) { User.hasMany(models.ResourceUser, { - as: 'user', - foreignKey: 'id' + as: 'userfollower', + foreignKey: 'userId' }) } diff --git a/api/src/routes/collectionUserRouter.js b/api/src/routes/collectionUserRouter.js index 785c5e686..86a9ce251 100644 --- a/api/src/routes/collectionUserRouter.js +++ b/api/src/routes/collectionUserRouter.js @@ -1,8 +1,9 @@ const express = require('express') const router = express.Router() +const { protect } = require('../middleware/authMiddleware') const { addCollectionUser, getControllerUser } = require('../controllers/collectionUserController') -router.route('/add').post(addCollectionUser) +router.route('/add').post(protect, addCollectionUser) router.route('/').get(getControllerUser) module.exports = router diff --git a/src/actions/collectionActions.js b/src/actions/collectionActions.js index d18d85451..2e89dd34e 100644 --- a/src/actions/collectionActions.js +++ b/src/actions/collectionActions.js @@ -74,7 +74,7 @@ export const createCollection = (newCollection) => async (dispatch, getState) => 'Content-Type': 'multipart/form-data' } } - const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/collection/add`, formData, config) + const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/collection/add`, formData) dispatch({ type: COLLECTION_CREATE_SUCCESS, payload: data }) } catch (error) { const message = diff --git a/src/actions/collectionUserActions.js b/src/actions/collectionUserActions.js new file mode 100644 index 000000000..e4b5213fd --- /dev/null +++ b/src/actions/collectionUserActions.js @@ -0,0 +1,32 @@ +import axios from 'axios' +import { + COLLECTION_USER_LIST_REQUEST, + COLLECTION_USER_LIST_SUCCESS, + COLLECTION_USER_LIST_FAIL, + COLLECTION_USER_CREATE_REQUEST, + COLLECTION_USER_CREATE_SUCCESS, + COLLECTION_USER_CREATE_FAIL +} from '../constants/collectionUserConstants' + +export const createCollectionUser = (newCollectionUser) => async (dispatch) => { + try { + dispatch({ + type: COLLECTION_USER_CREATE_REQUEST + }) + + const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/resourceUser/add`, newCollectionUser) + dispatch({ + type: COLLECTION_USER_CREATE_SUCCESS, + payload: data + }) + } catch (error) { + const message = + error.response && error.response.data.message + ? error.response.data.message + : error.message + dispatch({ + type: COLLECTION_USER_CREATE_FAIL, + payload: message + }) + } +} diff --git a/src/actions/resourceUserAction.js b/src/actions/resourceUserAction.js index f73e4ff0a..c39af79aa 100644 --- a/src/actions/resourceUserAction.js +++ b/src/actions/resourceUserAction.js @@ -8,7 +8,7 @@ import { RESOURCE_USER_CREATE_FAIL } from '../constants/resourceuserConstants' -export const listCollectionUser = (sort = '', pageNumber = '') => async ( +export const listResourceUser = (sort = '', pageNumber = '') => async ( dispatch ) => { try { diff --git a/src/components/libraryCard/LibraryCard.jsx b/src/components/libraryCard/LibraryCard.jsx index f8a8bfb49..8ac0cbac9 100644 --- a/src/components/libraryCard/LibraryCard.jsx +++ b/src/components/libraryCard/LibraryCard.jsx @@ -1,16 +1,18 @@ -import React from 'react' +import React, { useEffect } from 'react' import CardLayout from '../../layout/cardLayout/CardLayout' import './LibraryCard.css' +import { listResourceUser } from '../../actions/resourceUserAction' +import { useSelector, useDispatch } from 'react-redux' const LibraryCard = ({ data }) => { return ( <>
{ - data && data.filter(data => data.status === true).map(item => { + data && data.map((item) => { return (
{
{item.category}
-

{item.name}

+

{item.title}

) diff --git a/src/components/listView/ListView.jsx b/src/components/listView/ListView.jsx index 48d055612..4eb8d4852 100644 --- a/src/components/listView/ListView.jsx +++ b/src/components/listView/ListView.jsx @@ -7,20 +7,16 @@ import { useDispatch, useSelector } from 'react-redux' import { createResourceUser } from '../../actions/resourceUserAction' const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }) => { - const [active, setActive] = useState(false) - const [isAdded, setIsAdded] = useState() + const [active, setActive] = useState('') const dispatch = useDispatch() const userInfo = useSelector((state) => state.userLogin.userInfo.id) - + const [isAdded, setIsAdded] = useState() function clickHandle (id) { - if (active === false) { - dispatch( - createResourceUser({ userId: userInfo, resourceId: id }) - ) - } - - setActive(true) + dispatch( + createResourceUser({ userId: userInfo, resourceId: id }) + ) + setIsAdded(isAdded => ({ [id]: !isAdded[id] })) } return ( @@ -39,8 +35,8 @@ const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }
Add to -
diff --git a/src/constants/collectionUserConstants.js b/src/constants/collectionUserConstants.js new file mode 100644 index 000000000..f5d58e57a --- /dev/null +++ b/src/constants/collectionUserConstants.js @@ -0,0 +1,7 @@ +export const COLLECTION_USER_LIST_REQUEST = 'COLLECTION_USER_LIST_REQUEST' +export const COLLECTION_USER_LIST_SUCCESS = 'COLLECTION_USER_LIST_SUCCESS' +export const COLLECTION_USER_LIST_FAIL = 'COLLECTION_USER_LIST_FAIL' + +export const COLLECTION_USER_CREATE_REQUEST = 'COLLECTION_USER_CREATE_REQUEST' +export const COLLECTION_USER_CREATE_SUCCESS = 'COLLECTION_USER_CREATE_SUCCESS' +export const COLLECTION_USER_CREATE_FAIL = 'COLLECTION_USER_CREATE_FAIL' diff --git a/src/reducers/resourceUserReducers.js b/src/reducers/resourceUserReducers.js new file mode 100644 index 000000000..043a43a05 --- /dev/null +++ b/src/reducers/resourceUserReducers.js @@ -0,0 +1,24 @@ +import { + RESOURCE_USER_LIST_REQUEST, + RESOURCE_USER_LIST_SUCCESS, + RESOURCE_USER_LIST_FAIL + +} from '../constants/resourceuserConstants' + +export const resourceUserListReducer = (state = { resourceUsers: [] }, action) => { + switch (action.type) { + case RESOURCE_USER_LIST_REQUEST: + return { loading: true, resourceUsers: [] } + case RESOURCE_USER_LIST_SUCCESS: + return { + loading: false, + resourceUsers: action.payload, + pages: action.payload.pages, + page: action.payload.page + } + case RESOURCE_USER_LIST_FAIL: + return { loading: false, error: action.payload } + default: + return state + } +} diff --git a/src/screens/library/collection/Collection.jsx b/src/screens/library/collection/Collection.jsx index 0ebd4ddcf..b516310b1 100644 --- a/src/screens/library/collection/Collection.jsx +++ b/src/screens/library/collection/Collection.jsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useState, useEffect } from 'react' import CollectionModal from '../../../components/collectionModal/CollectionModal' import GroupModal from '../../../components/groupModal/GroupModal' import LibraryCard from '../../../components/libraryCard/LibraryCard' @@ -7,39 +7,39 @@ import SimpleModal from '../../../components/simpleModal/SimpleModal' import DashboardLayout from '../../../layout/dashboardLayout/DashboardLayout' import { groupCollection, collections } from '../CollectionData' import { useSelector, useDispatch } from 'react-redux' +import { listResourceUser } from '../../../actions/resourceUserAction' +import Pagination from '../../../Components/Paginations/Paginations' +import { listResources } from '../../../actions/resourceActions' import './collection.css' -const library = [ - { - category: 'farming', - title: "How to farm in 2020 and don't lose you business", - img: '/img/man-cap.svg' - }, - { - category: 'farming', - title: "How to farm in 2020 and don't lose you business", - img: '/img/man-cap.svg' - }, - { - category: 'farming', - title: "How to farm in 2020 and don't lose you business", - img: '/img/man-cap.svg' - } -] - const Collection = () => { const [newCollection, setNewCollection] = useState(false) const [active, setActive] = useState(false) const [modalActive, setModalActive] = useState(false) + // const [pageNumber, setPageNumber] = useState(1) + const dispatch = useDispatch() + // const collectiondata = useSelector( + // (state) => state.listCollection.collections.collection + // ) + // const resourceList = useSelector((state) => state.listResources) + // const data = useSelector((state) => state.listResources) + // let resources = resourceList.searchResources ? resourceList.searchResources : resourceList.resources + // if (data) resources = data.resources - const data = useSelector( - (state) => state.listCollection.collections.collection - ) - const userInfo = useSelector((state) => state.userLogin) - console.log('userinfo', userInfo) + // const userInfo = useSelector((state) => state.userLogin) + + // const resourceUser = useSelector((state)=>state) + // console.log("uuuu",resourceUser) + // useEffect(() =>{ + // dispatch(listResourceUser()) + // },[dispatch]) - console.log('another', data) + // useEffect(() => { + // dispatch(listResources({ pageNumber })) + // }, [pageNumber, dispatch]) + + // console.log('userinfo', userInfo) function openAddCollection () { setModalActive(true) @@ -62,11 +62,14 @@ const Collection = () => {

My library (files)

- + + + + {/* */}

My Collections

- +
diff --git a/src/screens/library/savedCollection/SavedCollection.jsx b/src/screens/library/savedCollection/SavedCollection.jsx index b5c4004d8..9ce6098a4 100644 --- a/src/screens/library/savedCollection/SavedCollection.jsx +++ b/src/screens/library/savedCollection/SavedCollection.jsx @@ -20,15 +20,15 @@ const SavedCollection = () => { setActive(false) } - const data = useSelector( - (state) => state.listCollection.collections.collection - ) + // const data = useSelector( + // (state) => state.listCollection.collections.collection + // ) - const dispatch = useDispatch() + // const dispatch = useDispatch() - useEffect(() => { - dispatch(listCollections()) - }, [dispatch]) + // useEffect(() => { + // dispatch(listCollections()) + // }, [dispatch]) return ( <> @@ -47,11 +47,11 @@ const SavedCollection = () => {

Farming Collections

- +

Branding Collections

- +
diff --git a/src/screens/library/userCollection/UserCollection.jsx b/src/screens/library/userCollection/UserCollection.jsx index e40600868..402015c8b 100644 --- a/src/screens/library/userCollection/UserCollection.jsx +++ b/src/screens/library/userCollection/UserCollection.jsx @@ -10,9 +10,10 @@ import { farming, groupCollection } from '../CollectionData' import GroupModal from '../../../components/groupModal/GroupModal' import CardLayout from '../../../layout/cardLayout/CardLayout' import { listCollections, updateCollection } from '../../../actions/collectionActions' +import { createCollectionUser } from '../../../actions/collectionUserActions' const UserCollection = () => { - const [active, setActive] = useState(false) + const [active, setActive] = useState(true) const [modalActive, setModalActive] = useState(false) const [groupModal, setGroupModal] = useState(false) @@ -21,6 +22,8 @@ const UserCollection = () => { const data = useSelector( (state) => state.listCollection.collections.collection ) + const userInfo = useSelector((state) => state.userLogin.userInfo.id) + console.log('collection', data) const dispatch = useDispatch() @@ -34,10 +37,9 @@ const UserCollection = () => { } function handleClick (id) { - if (active == false) { - dispatch(updateCollection(id, ({ status: 'true' }))) - setActive(true) - } + dispatch( + createCollectionUser({ userId: userInfo, collectionId: id }) + ) } return ( @@ -73,7 +75,7 @@ const UserCollection = () => {

{item.name}

diff --git a/src/store.js b/src/store.js index 3e66bceb2..beaae805d 100644 --- a/src/store.js +++ b/src/store.js @@ -8,9 +8,11 @@ import { groupListReducer, groupViewReducer } from './reducers/communityGroupRed import { userLoginReducer, userRegisterReducer } from './reducers/userReducers' import { eventListReducer } from './reducers/calendarEventReducer' import { collectionListReducer } from './reducers/collectionReducres' +import { resourceUserListReducer } from './reducers/resourceUserReducers' const reducer = combineReducers({ listEvents: eventListReducer, + listResourceUser: resourceUserListReducer, listCollection: collectionListReducer, groupView: groupViewReducer, listGroups: groupListReducer, From 1dd42cd655abc64df21717eb4075998e7e36a1b3 Mon Sep 17 00:00:00 2001 From: Dixit Sigdel Date: Thu, 10 Jun 2021 19:40:30 +0545 Subject: [PATCH 7/9] collection file attachments and others --- .../controllers/collectionUserController.js | 24 +++++++++++++------ api/src/controllers/resourceUserController.js | 23 +++++++++++++----- api/src/helpers/filehelpers.js | 2 +- api/src/routes/collectionUserRouter.js | 2 +- api/src/routes/resourceRouter.js | 2 +- src/actions/collectionUserActions.js | 2 +- src/components/listView/ListView.jsx | 4 ++-- .../library/userCollection/UserCollection.jsx | 17 +++++++++---- 8 files changed, 53 insertions(+), 23 deletions(-) diff --git a/api/src/controllers/collectionUserController.js b/api/src/controllers/collectionUserController.js index b8f2c5775..5ae111d4d 100644 --- a/api/src/controllers/collectionUserController.js +++ b/api/src/controllers/collectionUserController.js @@ -15,15 +15,25 @@ const getControllerUser = (req, res) => { .catch((err) => res.json({ err }).status(400)) } // @desc Add individual collection user -const addCollectionUser = (req, res) => { +const addCollectionUser = async (req, res) => { const { userId, collectionId } = req.body - CollectionUser.create({ - userId, - collectionId + const userExists = await User.findOne({ where: { id: userId } }) + const collectionExits = await Collection.findOne({ where: { id: collectionId } }) + const collectionUserExists = await CollectionUser.findOne({ where: { collectionId, userId } }) + if (collectionUserExists) { + res.status(400).json({ error: 'User Already added collection' }) + } + if (userExists && collectionExits) { + CollectionUser.create({ + userId, + collectionId - }) - .then(() => res.json({ message: 'Collection User Created !!!' }).status(200)) - .catch((err) => res.json({ error: err.message }).status(400)) + }) + .then(() => res.json({ message: 'Collection User Created !!!' }).status(200)) + .catch((err) => res.json({ error: err.message }).status(400)) + } else { + res.status(400).json({ error: 'User Not Found' }) + } } // @desc Update a collection user diff --git a/api/src/controllers/resourceUserController.js b/api/src/controllers/resourceUserController.js index 4c08c29ea..495096395 100644 --- a/api/src/controllers/resourceUserController.js +++ b/api/src/controllers/resourceUserController.js @@ -23,15 +23,25 @@ const getResourceUser = (req, res) => { // @route POST /api/resourceUser/add // @access Private -const addResourceUser = (req, res) => { +const addResourceUser = async (req, res) => { // const user = User.findOne({ where: { id: req.body.id } }) const { userId, resourceId } = req.body - ResourceUser.create({ - userId, resourceId - }) - .then(() => res.json({ message: 'Resource User Created !!!' }).this.status(200)) - .catch((err) => res.json({ error: err.message }).status(400)) + const userExists = await User.findOne({ where: { id: userId } }) + const resourceExists = await Resource.findOne({ where: { id: resourceId } }) + const resourceUserExists = await ResourceUser.findOne({ where: { resourceId, userId } }) + if (resourceUserExists) { + res.status(400).json({ error: 'User Already added resource' }) + } + if (userExists && resourceExists) { + ResourceUser.create({ + userId, resourceId + }) + .then(() => res.json({ message: 'Resource User Created !!!' }).this.status(200)) + .catch((err) => res.json({ error: err.message }).status(400)) + } else { + res.status(400).json({ error: 'User Not Found' }) + } } // @desc Update a ResourceUser @@ -39,6 +49,7 @@ const addResourceUser = (req, res) => { // @access Public const updateResourceUser = (req, res) => { + const id = req.params.id ResourceUser.findByPk(id).then(resourceUser => { if (resourceUser) { const { id } = resourceUser diff --git a/api/src/helpers/filehelpers.js b/api/src/helpers/filehelpers.js index c99a0d2f9..41c154073 100644 --- a/api/src/helpers/filehelpers.js +++ b/api/src/helpers/filehelpers.js @@ -34,7 +34,7 @@ const upload = multer({ } }) -const multipleUpload = upload.fields([{ name: 'avatar' }, { name: 'attachment' }]) +const multipleUpload = upload.fields([{ name: 'file' }, { name: 'attachment' }]) const uploadArray = multer({ storage }).array('files') diff --git a/api/src/routes/collectionUserRouter.js b/api/src/routes/collectionUserRouter.js index 86a9ce251..e2ae1eb39 100644 --- a/api/src/routes/collectionUserRouter.js +++ b/api/src/routes/collectionUserRouter.js @@ -3,7 +3,7 @@ const router = express.Router() const { protect } = require('../middleware/authMiddleware') const { addCollectionUser, getControllerUser } = require('../controllers/collectionUserController') -router.route('/add').post(protect, addCollectionUser) +router.route('/add').post(addCollectionUser) router.route('/').get(getControllerUser) module.exports = router diff --git a/api/src/routes/resourceRouter.js b/api/src/routes/resourceRouter.js index c89ffb6a9..ff4625082 100644 --- a/api/src/routes/resourceRouter.js +++ b/api/src/routes/resourceRouter.js @@ -5,7 +5,7 @@ const multer = require('multer') const shortid = require('shortid') const path = require('path') const { protect } = require('../middleware/authMiddleware') -const { uploadArray, upload } = require('../helpers/filehelpers') +const { uploadArray, multipleUpload, upload } = require('../helpers/filehelpers') const { getResources, addResource, getResourcesById, deleteResources, updateResources, searchResourcesTitle } = require('../controllers/resourceController.js') diff --git a/src/actions/collectionUserActions.js b/src/actions/collectionUserActions.js index e4b5213fd..0aa5c60fb 100644 --- a/src/actions/collectionUserActions.js +++ b/src/actions/collectionUserActions.js @@ -14,7 +14,7 @@ export const createCollectionUser = (newCollectionUser) => async (dispatch) => { type: COLLECTION_USER_CREATE_REQUEST }) - const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/resourceUser/add`, newCollectionUser) + const { data } = await axios.post(`${process.env.REACT_APP_API_BASE_URL}/api/collectionUser/add`, newCollectionUser) dispatch({ type: COLLECTION_USER_CREATE_SUCCESS, payload: data diff --git a/src/components/listView/ListView.jsx b/src/components/listView/ListView.jsx index 4eb8d4852..22eb8ab28 100644 --- a/src/components/listView/ListView.jsx +++ b/src/components/listView/ListView.jsx @@ -16,7 +16,7 @@ const ListView = ({ data, title, setNewCollection, setModalActive, modalActive } dispatch( createResourceUser({ userId: userInfo, resourceId: id }) ) - setIsAdded(isAdded => ({ [id]: !isAdded[id] })) + setIsAdded(id) } return ( @@ -36,7 +36,7 @@ const ListView = ({ data, title, setNewCollection, setModalActive, modalActive }
Add to
diff --git a/src/screens/library/userCollection/UserCollection.jsx b/src/screens/library/userCollection/UserCollection.jsx index 402015c8b..bee07d5c4 100644 --- a/src/screens/library/userCollection/UserCollection.jsx +++ b/src/screens/library/userCollection/UserCollection.jsx @@ -11,10 +11,13 @@ import GroupModal from '../../../components/groupModal/GroupModal' import CardLayout from '../../../layout/cardLayout/CardLayout' import { listCollections, updateCollection } from '../../../actions/collectionActions' import { createCollectionUser } from '../../../actions/collectionUserActions' +import Pagination from '../../../Components/Paginations/Paginations' const UserCollection = () => { const [active, setActive] = useState(true) const [modalActive, setModalActive] = useState(false) + const [isAdded, setIsAdded] = useState() + const [pageNumber, setPageNumber] = useState(1) const [groupModal, setGroupModal] = useState(false) const [newCollection, setNewCollection] = useState(false) @@ -22,14 +25,17 @@ const UserCollection = () => { const data = useSelector( (state) => state.listCollection.collections.collection ) + + const dataCollection = useSelector( + (state) => state.listCollection + ) const userInfo = useSelector((state) => state.userLogin.userInfo.id) - console.log('collection', data) const dispatch = useDispatch() useEffect(() => { - dispatch(listCollections()) - }, [dispatch]) + dispatch(listCollections({ pageNumber })) + }, [pageNumber, dispatch]) function openAddCollection () { setGroupModal(true) @@ -40,6 +46,7 @@ const UserCollection = () => { dispatch( createCollectionUser({ userId: userInfo, collectionId: id }) ) + setIsAdded(id) } return ( @@ -75,7 +82,7 @@ const UserCollection = () => {

{item.name}

@@ -83,6 +90,8 @@ const UserCollection = () => { }) }
+ + ) From 83761077f7342d323c0c3de515e759e209bbbd04 Mon Sep 17 00:00:00 2001 From: Laxman Maharjan Date: Sat, 12 Jun 2021 08:32:33 +0545 Subject: [PATCH 8/9] rename --- .../controllers/collectionUserController.js | 1 + api/src/helpers/filehelpers.js | 2 +- api/src/models/collectionModel.js | 1 - api/src/models/collectionUserModel.js | 2 -- api/src/models/resourceModel.js | 2 -- api/src/models/userModel.js | 2 -- .../collectionModal/CollectionModal.jsx | 21 ++----------------- .../EnterprisesCollection.scss | 6 +++--- src/components/groupUsers/GroupUsers.jsx | 6 +++--- src/components/libraryCard/LibraryCard.jsx | 3 +-- src/screens/library/collection/Collection.jsx | 10 ++++----- .../savedCollection/SavedCollection.jsx | 4 ++-- .../library/userCollection/UserCollection.jsx | 4 ++-- 13 files changed, 20 insertions(+), 44 deletions(-) diff --git a/api/src/controllers/collectionUserController.js b/api/src/controllers/collectionUserController.js index 5ae111d4d..2e7d34aed 100644 --- a/api/src/controllers/collectionUserController.js +++ b/api/src/controllers/collectionUserController.js @@ -14,6 +14,7 @@ const getControllerUser = (req, res) => { }) .catch((err) => res.json({ err }).status(400)) } + // @desc Add individual collection user const addCollectionUser = async (req, res) => { const { userId, collectionId } = req.body diff --git a/api/src/helpers/filehelpers.js b/api/src/helpers/filehelpers.js index 41c154073..5c2000483 100644 --- a/api/src/helpers/filehelpers.js +++ b/api/src/helpers/filehelpers.js @@ -34,7 +34,7 @@ const upload = multer({ } }) -const multipleUpload = upload.fields([{ name: 'file' }, { name: 'attachment' }]) +const multipleUpload = upload.fields([{ name: 'file' }, { name: 'attachment' }, { name: 'avatar' }]) const uploadArray = multer({ storage }).array('files') diff --git a/api/src/models/collectionModel.js b/api/src/models/collectionModel.js index c9ac7ffe9..5975e68cc 100644 --- a/api/src/models/collectionModel.js +++ b/api/src/models/collectionModel.js @@ -39,7 +39,6 @@ const Collection = db.define( Collection.associate = function (models) { Collection.hasMany(models.CollectionUser, { - as: 'collectionInfo', foreignKey: 'collectionId' }) } diff --git a/api/src/models/collectionUserModel.js b/api/src/models/collectionUserModel.js index 79389d8d9..64b15ad46 100644 --- a/api/src/models/collectionUserModel.js +++ b/api/src/models/collectionUserModel.js @@ -21,11 +21,9 @@ const CollectionUser = db.define('collection_user', CollectionUser.associate = (models) => { CollectionUser.belongsTo(models.User, { - as: 'userfollower', foreignKey: 'userId' }) CollectionUser.belongsTo(models.Collection, { - as: 'collectionInfo', foreignKey: 'collectionId' }) } diff --git a/api/src/models/resourceModel.js b/api/src/models/resourceModel.js index daa627ea8..796bc28d4 100644 --- a/api/src/models/resourceModel.js +++ b/api/src/models/resourceModel.js @@ -94,9 +94,7 @@ const Resources = db.define('resources', Resources.associate = function (models) { Resources.hasMany(models.ResourceUser, { - as: 'resourceInfo', foreignKey: 'resourceId' - }) } diff --git a/api/src/models/userModel.js b/api/src/models/userModel.js index 1bcf94e0c..d8c0dea66 100644 --- a/api/src/models/userModel.js +++ b/api/src/models/userModel.js @@ -15,13 +15,11 @@ const User = db.define('users', { User.associate = function (models) { User.hasMany(models.CollectionUser, { - as: 'userfollower', foreignKey: 'userId' }) } User.associate = function (models) { User.hasMany(models.ResourceUser, { - as: 'userfollower', foreignKey: 'userId' }) } diff --git a/src/components/collectionModal/CollectionModal.jsx b/src/components/collectionModal/CollectionModal.jsx index 817fe54d7..b58a0cee3 100644 --- a/src/components/collectionModal/CollectionModal.jsx +++ b/src/components/collectionModal/CollectionModal.jsx @@ -71,30 +71,13 @@ const CollectionModal = ({ setActive, openAddCollection, name }) => { : <>
-
+ collectionTitleChange(e)} placeholder='Collection title' />
openAddCollection()}>Add Files
- + }
- - {pathname === '/library' - ? <> -
- resourceTitleChange(e)} placeholder='Resource title' />
- resourceDescriptionChange(e)} placeholder='Resource description' />
-
- - - : <> -
- collectionTitleChange(e)} placeholder='Collection title' />
- -
-
openAddCollection()}>Add Files
- - } diff --git a/src/components/enterprisesCollection/EnterprisesCollection.scss b/src/components/enterprisesCollection/EnterprisesCollection.scss index f478f4742..80472f8c2 100644 --- a/src/components/enterprisesCollection/EnterprisesCollection.scss +++ b/src/components/enterprisesCollection/EnterprisesCollection.scss @@ -10,8 +10,8 @@ } .collection-modal-container > div { - /* width: 100%; */ - height: 80%; + width: 100%; + height: 100%; position: relative; overflow-y: scroll; margin-bottom: 100px; @@ -58,7 +58,7 @@ .drag-drop-container { width: 100%; - height: 30%; + height: 100%; position: relative; margin-bottom: 40px; } diff --git a/src/components/groupUsers/GroupUsers.jsx b/src/components/groupUsers/GroupUsers.jsx index c704b40c4..950a02b77 100644 --- a/src/components/groupUsers/GroupUsers.jsx +++ b/src/components/groupUsers/GroupUsers.jsx @@ -8,13 +8,13 @@ const GroupUsers = ({ data }) => { <> { - data && data.map(d => ( + data && data.map(user => (
- users + users
-

{d.name && d.name}

+

{user.name && user.name}

diff --git a/src/components/libraryCard/LibraryCard.jsx b/src/components/libraryCard/LibraryCard.jsx index 8ac0cbac9..dd8ac210e 100644 --- a/src/components/libraryCard/LibraryCard.jsx +++ b/src/components/libraryCard/LibraryCard.jsx @@ -13,13 +13,12 @@ const LibraryCard = ({ data }) => { return (
-
{item.category}
diff --git a/src/screens/library/collection/Collection.jsx b/src/screens/library/collection/Collection.jsx index b516310b1..2f5532f4d 100644 --- a/src/screens/library/collection/Collection.jsx +++ b/src/screens/library/collection/Collection.jsx @@ -5,13 +5,13 @@ import LibraryCard from '../../../components/libraryCard/LibraryCard' import LibraryHeader from '../../../components/libraryHeader/LibraryHeader' import SimpleModal from '../../../components/simpleModal/SimpleModal' import DashboardLayout from '../../../layout/dashboardLayout/DashboardLayout' -import { groupCollection, collections } from '../CollectionData' +import { groupCollection, collections, library } from '../CollectionData' import { useSelector, useDispatch } from 'react-redux' import { listResourceUser } from '../../../actions/resourceUserAction' -import Pagination from '../../../Components/Paginations/Paginations' +import Pagination from '../../../Components/pagination/Pagination' import { listResources } from '../../../actions/resourceActions' -import './collection.css' +import './Collection.css' const Collection = () => { const [newCollection, setNewCollection] = useState(false) @@ -63,13 +63,13 @@ const Collection = () => {

My library (files)

- + {/* */}

My Collections

- +
diff --git a/src/screens/library/savedCollection/SavedCollection.jsx b/src/screens/library/savedCollection/SavedCollection.jsx index 9ce6098a4..92049b995 100644 --- a/src/screens/library/savedCollection/SavedCollection.jsx +++ b/src/screens/library/savedCollection/SavedCollection.jsx @@ -47,11 +47,11 @@ const SavedCollection = () => {

Farming Collections

- +

Branding Collections

- +
diff --git a/src/screens/library/userCollection/UserCollection.jsx b/src/screens/library/userCollection/UserCollection.jsx index bee07d5c4..0ac06b44c 100644 --- a/src/screens/library/userCollection/UserCollection.jsx +++ b/src/screens/library/userCollection/UserCollection.jsx @@ -11,7 +11,7 @@ import GroupModal from '../../../components/groupModal/GroupModal' import CardLayout from '../../../layout/cardLayout/CardLayout' import { listCollections, updateCollection } from '../../../actions/collectionActions' import { createCollectionUser } from '../../../actions/collectionUserActions' -import Pagination from '../../../Components/Paginations/Paginations' +import Pagination from '../../../Components/pagination/Pagination' const UserCollection = () => { const [active, setActive] = useState(true) @@ -72,7 +72,7 @@ const UserCollection = () => { { data && data.map(item => { return ( -
+
From 4387e5e0906804ef98d143714a6edadc7841a0fe Mon Sep 17 00:00:00 2001 From: Laxman Maharjan Date: Thu, 17 Jun 2021 22:15:00 +0545 Subject: [PATCH 9/9] name convention --- src/screens/library/collection/Collection.jsx | 2 +- src/screens/library/userCollection/UserCollection.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/library/collection/Collection.jsx b/src/screens/library/collection/Collection.jsx index 2f5532f4d..53ea95870 100644 --- a/src/screens/library/collection/Collection.jsx +++ b/src/screens/library/collection/Collection.jsx @@ -8,7 +8,7 @@ import DashboardLayout from '../../../layout/dashboardLayout/DashboardLayout' import { groupCollection, collections, library } from '../CollectionData' import { useSelector, useDispatch } from 'react-redux' import { listResourceUser } from '../../../actions/resourceUserAction' -import Pagination from '../../../Components/pagination/Pagination' +import Pagination from '../../../components/pagination/Pagination' import { listResources } from '../../../actions/resourceActions' import './Collection.css' diff --git a/src/screens/library/userCollection/UserCollection.jsx b/src/screens/library/userCollection/UserCollection.jsx index 0ac06b44c..1f52aa8f5 100644 --- a/src/screens/library/userCollection/UserCollection.jsx +++ b/src/screens/library/userCollection/UserCollection.jsx @@ -11,7 +11,7 @@ import GroupModal from '../../../components/groupModal/GroupModal' import CardLayout from '../../../layout/cardLayout/CardLayout' import { listCollections, updateCollection } from '../../../actions/collectionActions' import { createCollectionUser } from '../../../actions/collectionUserActions' -import Pagination from '../../../Components/pagination/Pagination' +import Pagination from '../../../components/pagination/Pagination' const UserCollection = () => { const [active, setActive] = useState(true)