-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Private section in profile does not show all Private vizzes
- Loading branch information
Showing
21 changed files
with
203 additions
and
121 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...ollers/src/apiController/visualizationAPIController/getPrivateVisualizationsController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { GetSearchResultsPageData } from 'vizhub-use-cases'; | ||
import { userIdFromReq } from '../../userIdFromReq'; | ||
|
||
export const getPrivateVisualizationsController = (expressApp, gateways) => { | ||
const getSearchResultsPageData = new GetSearchResultsPageData(gateways); | ||
expressApp.post('/api/visualization/get/private', async (req, res) => { | ||
try { | ||
const { owner, offset = 0 } = req.body; | ||
if (userIdFromReq(req) !== owner) { | ||
return res | ||
.status(403) | ||
.json({ error: 'Getting private visualizations is allowed only for visualizations owner' }); | ||
} | ||
|
||
const data = await getSearchResultsPageData.execute({ | ||
offset, | ||
owner, | ||
onlyPrivate: true | ||
}); | ||
res.json(data); | ||
} catch (error) { | ||
console.log(error); | ||
res.json({ error }); | ||
} | ||
}); | ||
}; |
18 changes: 18 additions & 0 deletions
18
...rollers/src/apiController/visualizationAPIController/getPublicVisualizationsController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { GetSearchResultsPageData } from 'vizhub-use-cases'; | ||
|
||
export const getPublicVisualizationsController = (expressApp, gateways) => { | ||
const getSearchResultsPageData = new GetSearchResultsPageData(gateways); | ||
expressApp.post('/api/visualization/get/public', async (req, res) => { | ||
try { | ||
const { owner, offset = 0 } = req.body; | ||
const data = await getSearchResultsPageData.execute({ | ||
offset, | ||
owner, | ||
}); | ||
res.json(data); | ||
} catch (error) { | ||
console.log(error); | ||
res.json({ error }); | ||
} | ||
}); | ||
}; |
6 changes: 3 additions & 3 deletions
6
...r/getGetSharedVisualizationsController.js → ...ller/getSharedVisualizationsController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// The number of vizzes shown in a page of content. | ||
// Infinite scroll pagination fetches the next page. | ||
export const pageSize = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/neoFrontend/src/pages/ProfilePage/Body/usePrivateVizFetcher.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useCallback , useEffect, useState} from 'react'; | ||
|
||
export const usePrivateVizFetcher = (userId, vizType) => { | ||
const [state, setState] = useState(false); | ||
|
||
useEffect(() => { | ||
if(vizType === 'private') setState(true) | ||
}, [vizType]) | ||
|
||
const fetchData = useCallback( | ||
async (offset) => { | ||
if (!userId) return; | ||
|
||
const response = await fetch('/api/visualization/get/private', { | ||
method: 'POST', | ||
mode: 'cors', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ offset, owner: userId }), | ||
}); | ||
return await response.json(); | ||
}, | ||
[userId] | ||
); | ||
|
||
return state ? fetchData : null; | ||
}; |
33 changes: 0 additions & 33 deletions
33
packages/neoFrontend/src/pages/ProfilePage/Body/useProfileData.js
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
packages/neoFrontend/src/pages/ProfilePage/Body/useProfileVizzes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
import { useMemo } from 'react'; | ||
import { usePaginatedVizzes } from '../../../VizzesGrid/usePaginatedVizzes'; | ||
import { usePublicVizFetcher } from './usePublicVizFetcher'; | ||
import { usePrivateVizFetcher } from './usePrivateVizFetcher'; | ||
import { useSharedWithMeVizFetcher } from './useSharedWithMeVizFetcher'; | ||
|
||
export const useProfileVizzes = ({ me, vizType, initialVisualizationInfos }) => { | ||
const publicInitialState = useMemo(() => { | ||
return { | ||
visualizationInfos: initialVisualizationInfos, | ||
isFetchingNextPage: false, | ||
currentPage: 1, | ||
fetchedAllPages: false, | ||
usersById: {[me.id]: me}, | ||
error: null, | ||
} | ||
}, [me, initialVisualizationInfos]) | ||
|
||
const publicVizFetcher = usePublicVizFetcher(me.id, vizType) | ||
const publicData = usePaginatedVizzes(publicVizFetcher, publicInitialState) | ||
|
||
const privateVizFetcher = usePrivateVizFetcher(me.id, vizType) | ||
const privateData = usePaginatedVizzes(privateVizFetcher) | ||
|
||
const sharedWithMeVizFetcher = useSharedWithMeVizFetcher(me.id, vizType) | ||
const sharedData = usePaginatedVizzes(sharedWithMeVizFetcher); | ||
|
||
if (vizType === 'shared') { | ||
return sharedData; | ||
} else if (vizType === 'private') { | ||
return privateData | ||
} else { | ||
return publicData | ||
} | ||
}; |
26 changes: 26 additions & 0 deletions
26
packages/neoFrontend/src/pages/ProfilePage/Body/usePublicVizFetcher.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useCallback , useEffect, useState} from 'react'; | ||
|
||
export const usePublicVizFetcher = (userId, vizType) => { | ||
const [state, setState] = useState(false); | ||
|
||
useEffect(() => { | ||
if(vizType === 'public') setState(true) | ||
}, [vizType]) | ||
|
||
const fetchData = useCallback( | ||
async (offset) => { | ||
if (!userId) return; | ||
|
||
const response = await fetch('/api/visualization/get/public', { | ||
method: 'POST', | ||
mode: 'cors', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ offset, owner: userId }), | ||
}); | ||
return await response.json(); | ||
}, | ||
[userId] | ||
); | ||
|
||
return state ? fetchData : null; | ||
}; |
Oops, something went wrong.