forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
231 additions
and
56 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// @ts-check | ||
/* eslint-disable react/prop-types */ | ||
import React, { useEffect } from 'react'; | ||
import { StudioFooter } from '@edx/frontend-component-footer'; | ||
import { Tab, Tabs } from '@openedx/paragon'; | ||
import { | ||
Routes, Route, useLocation, useNavigate, | ||
} from 'react-router-dom'; | ||
|
||
import Header from '../header'; | ||
import NotFoundAlert from '../generic/NotFoundAlert'; | ||
import LibraryComponents from './LibraryComponents'; | ||
import LibraryCollections from './LibraryCollections'; | ||
import LibraryHome from './LibraryHome'; | ||
|
||
const TAB_LIST = { | ||
home: '', | ||
components: 'components', | ||
collections: 'collections', | ||
}; | ||
|
||
/** | ||
* @type {React.FC} | ||
*/ | ||
const LibraryAuthoringPage = () => { | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const [tabKey, setTabKey] = React.useState(TAB_LIST.home); | ||
|
||
// FIXME: These values should be fetched from the backend | ||
const libraryTitle = 'Library Title'; | ||
const libraryNumber = '001'; | ||
const libraryOrg = 'Library Org'; | ||
const libraryId = 'lib:org1:libafter1'; | ||
|
||
useEffect(() => { | ||
const currentPath = location.pathname.split('/').pop(); | ||
if (currentPath && Object.values(TAB_LIST).includes(currentPath)) { | ||
setTabKey(currentPath); | ||
} | ||
}, [location]); | ||
|
||
/** Handle tab change | ||
* @param {string} key | ||
*/ | ||
const handleTabChange = (key) => { | ||
setTabKey(key); | ||
navigate(key); | ||
}; | ||
|
||
return ( | ||
<div className="bg-white"> | ||
<Header | ||
number={libraryNumber} | ||
title={libraryTitle} | ||
org={libraryOrg} | ||
contentId={libraryId} | ||
isLibrary | ||
/> | ||
<Tabs | ||
variant="tabs" | ||
activeKey={tabKey} | ||
onSelect={handleTabChange} | ||
> | ||
<Tab eventKey={TAB_LIST.home} title="Home" /> | ||
<Tab eventKey={TAB_LIST.components} title="Components" /> | ||
<Tab eventKey={TAB_LIST.collections} title="Collections" /> | ||
</Tabs> | ||
<Routes> | ||
<Route | ||
path={TAB_LIST.home} | ||
element={<LibraryHome libraryId={libraryId} />} | ||
/> | ||
<Route | ||
path={TAB_LIST.components} | ||
element={<LibraryComponents />} | ||
/> | ||
<Route | ||
path={TAB_LIST.collections} | ||
element={<LibraryCollections />} | ||
/> | ||
<Route | ||
path="*" | ||
element={<NotFoundAlert />} | ||
/> | ||
</Routes> | ||
<StudioFooter /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LibraryAuthoringPage; |
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,14 @@ | ||
// @ts-check | ||
/* eslint-disable react/prop-types */ | ||
import React from 'react'; | ||
|
||
/** | ||
* @type {React.FC} | ||
*/ | ||
const LibraryCollections = () => ( | ||
<div> | ||
Coming soon | ||
</div> | ||
); | ||
|
||
export default LibraryCollections; |
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,14 @@ | ||
// @ts-check | ||
/* eslint-disable react/prop-types */ | ||
import React from 'react'; | ||
|
||
/** | ||
* @type {React.FC} | ||
*/ | ||
const LibraryComponents = () => ( | ||
<div> | ||
Library components will be displayed here. | ||
</div> | ||
); | ||
|
||
export default LibraryComponents; |
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,66 @@ | ||
// @ts-check | ||
/* eslint-disable react/prop-types */ | ||
import React from 'react'; | ||
import { MeiliSearch } from 'meilisearch'; | ||
|
||
import { useContentSearchConnection, useContentSearchResults } from '../search-modal'; | ||
import LibraryCollections from './LibraryCollections'; | ||
import LibraryComponents from './LibraryComponents'; | ||
|
||
/** | ||
* @type {React.FC<{ | ||
* title: string, | ||
* children: React.ReactNode, | ||
* }>} | ||
*/ | ||
const Section = ({ title, children }) => ( | ||
<div className="bg-gray-100 mx-3 mt-3 mb-4 p-3"> | ||
<h2>{title}</h2> | ||
{children} | ||
</div> | ||
); | ||
|
||
/** | ||
* @type {React.FC<{ | ||
* libraryId: string, | ||
* }>} | ||
*/ | ||
const LibraryHome = ({ libraryId }) => { | ||
// Meilisearch code to get Collection and Component counts | ||
const { data: connectionDetails } = useContentSearchConnection(); | ||
const indexName = connectionDetails?.indexName; | ||
const client = React.useMemo(() => { | ||
if (connectionDetails?.apiKey === undefined || connectionDetails?.url === undefined) { | ||
return undefined; | ||
} | ||
return new MeiliSearch({ host: connectionDetails.url, apiKey: connectionDetails.apiKey }); | ||
}, [connectionDetails?.apiKey, connectionDetails?.url]); | ||
|
||
const searchKeywords = ''; | ||
const libFilter = `context_key = "${libraryId}"`; | ||
|
||
const { totalHits: componentCount } = useContentSearchResults({ | ||
client, | ||
indexName, | ||
searchKeywords, | ||
extraFilter: [libFilter], // ToDo: Add filter for components when collection is implemented | ||
}); | ||
|
||
const collectionsCount = 0; // ToDo: Implement collections count | ||
|
||
return ( | ||
<> | ||
<Section title="Recently Modified"> | ||
Recently modified components and collections will be displayed here. | ||
</Section> | ||
<Section title={`Collections (${collectionsCount})`}> | ||
<LibraryCollections /> | ||
</Section> | ||
<Section title={`Components (${componentCount})`}> | ||
<LibraryComponents /> | ||
</Section> | ||
</> | ||
); | ||
}; | ||
|
||
export default LibraryHome; |
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 @@ | ||
// @ts-check | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as LibraryAuthoringPage } from './LibraryAuthoringPage'; |
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 @@ | ||
// @ts-check | ||
export { default as SearchModal } from './SearchModal'; | ||
export { useContentSearchConnection, useContentSearchResults } from './data/apiHooks'; |