-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor training pages to allow rendering on client-side instead of …
…server-side
- Loading branch information
1 parent
ecc9396
commit a82227e
Showing
13 changed files
with
334 additions
and
88 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
22 changes: 22 additions & 0 deletions
22
app/assets/javascripts/training/components/search_results.jsx
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,22 @@ | ||
import React from 'react'; | ||
|
||
const SearchResults = ({ slides }) => { | ||
if (slides && slides.length > 0) { | ||
return ( | ||
<ul className="training-libraries no-bullets no-margin action-card-text"> | ||
{slides.map((slide, index) => ( | ||
<li key={index}> | ||
<a href={`https://dashboard.wikiedu.org/training/${slide.path}`} target="_blank"> | ||
<span dangerouslySetInnerHTML={{ __html: slide.title }} /> ({slide.module_name}) | ||
</a> | ||
<br /> | ||
<div dangerouslySetInnerHTML={{ __html: slide.excerpt }} /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export default SearchResults; |
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
97 changes: 97 additions & 0 deletions
97
app/assets/javascripts/training/components/training_libraries_list.jsx
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,97 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import SearchResults from './search_results.jsx'; | ||
import { fetchTrainingLibraries, searchTrainingLibraries } from '../../actions/training_actions'; | ||
|
||
const TrainingLibraries = () => { | ||
const libraries = useSelector(state => state.training.libraries); | ||
const focusedLibrarySlug = useSelector(state => state.training.focusedLibrarySlug); | ||
const slides = useSelector(state => state.training.slides); | ||
const [search, setSearch] = useState(''); | ||
const [showSearchResults, setShowSearchResults] = useState(false); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(fetchTrainingLibraries()); | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
setShowSearchResults(showSearchResults); | ||
}, [slides]); | ||
|
||
const handleSearch = (e) => { | ||
setSearch(e.target.value); | ||
}; | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
dispatch(searchTrainingLibraries(search)); | ||
setShowSearchResults(true); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>Training Libraries</h1> | ||
<div className="search-bar" style={{ position: 'relative' }}> | ||
<form onSubmit={handleSubmit}> | ||
<input | ||
type="text" | ||
value={search} | ||
onChange={e => handleSearch(e)} | ||
placeholder="Search for training resources" | ||
style={{ width: '100%', height: '3rem', fontSize: '15px' }} | ||
/> | ||
<button type="submit" id="training_search_button" style={{ position: 'absolute', right: '20px', top: '10px' }}> | ||
<i className="icon icon-search" /> | ||
</button> | ||
</form> | ||
</div> | ||
{showSearchResults ? ( | ||
<SearchResults slides={slides} message="No training resources match your search." /> | ||
) : ( | ||
<ul className="training-libraries no-bullets no-margin"> | ||
{libraries | ||
.filter(library => !library.exclude_from_index) | ||
.map((library, index) => { | ||
const isFocused = focusedLibrarySlug === library.slug; | ||
let libraryClass = 'training-libraries__individual-library no-left-margin'; | ||
if (isFocused) { | ||
libraryClass += ' training-library-focus'; | ||
} else if (focusedLibrarySlug) { | ||
libraryClass += ' training-library-defocus'; | ||
} | ||
|
||
return ( | ||
<li key={index} className={libraryClass}> | ||
<a href={`/training/${library.slug}`} className="action-card action-card-index"> | ||
<header className="action-card-header"> | ||
<h3 className="action-card-title">{library.name}</h3> | ||
<span className="icon-container"> | ||
<i className="action-card-icon icon icon-rt_arrow" /> | ||
</span> | ||
</header> | ||
</a> | ||
<div className="action-card-text"> | ||
<h3>Included Modules:</h3> | ||
<ul> | ||
{library.categories.map(category => | ||
category.modules.map((trainingModule, moduleIndex) => ( | ||
<li key={moduleIndex}> | ||
<a href={`/training/${library.slug}/${trainingModule.slug}`} target="_blank"> | ||
{trainingModule.name} | ||
</a> | ||
</li> | ||
)) | ||
)} | ||
</ul> | ||
</div> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TrainingLibraries; |
70 changes: 70 additions & 0 deletions
70
app/assets/javascripts/training/components/training_library.jsx
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,70 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useParams } from 'react-router-dom'; | ||
import { fetchTrainingLibrary } from '../../actions/training_actions'; | ||
|
||
const TrainingLibrary = () => { | ||
const { library_id } = useParams(); | ||
const library = useSelector(state => state.training.library); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(fetchTrainingLibrary(library_id)); | ||
}, | ||
[dispatch, library_id]); | ||
if (!library) { | ||
return <div>Loading...</div>; | ||
} | ||
return ( | ||
<div className="training__section-overview container"> | ||
<section className="training__header"> | ||
<h1>{library.name}</h1> | ||
<p>{library.introduction}</p> | ||
</section> | ||
{library.categories ? ( | ||
<ul className="training__categories"> | ||
{library.categories.map((libCategory, index) => ( | ||
<li key={index}> | ||
<div className="training__category__header"> | ||
<h1 className="h3">{libCategory.title}</h1> | ||
<p>{libCategory.description}</p> | ||
{library.wiki_page && ( | ||
<div className="training__category__source"> | ||
<a href={`https://meta.wikimedia.org/wiki/${library.wiki_page}`}> | ||
View Library Source | ||
</a> | ||
</div> | ||
)} | ||
</div> | ||
<ul className="training__categories__modules"> | ||
{libCategory.modules.map((libModule, moduleIndex) => ( | ||
<li key={moduleIndex}> | ||
<a href={`/training/${library.slug}/${libModule.slug}`} className="action-card"> | ||
|
||
<header className="action-card-header"> | ||
<h3 className="action-card-title">{libModule.name}</h3> | ||
<span className="pull-right action-card-title__completion"> | ||
{libModule.percent_complete} | ||
</span> | ||
<span className="icon-container"> | ||
<i className="action-card-icon icon icon-rt_arrow" /> | ||
</span> | ||
</header> | ||
<p className="action-card-text"> | ||
<span>{libModule.description}</span> | ||
</p> | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
</li> | ||
))} | ||
</ul> | ||
) : ( | ||
<p>No categories available.</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TrainingLibrary; |
Oops, something went wrong.