Skip to content

Commit

Permalink
move no libraries message to react side
Browse files Browse the repository at this point in the history
  • Loading branch information
sharon-odhiambo committed Nov 3, 2023
1 parent 3f9188d commit 56afa0f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ const TrainingLibraries = () => {
const slides = useSelector(state => state.training.slides);
const [search, setSearch] = useState('');
const [showSearchResults, setShowSearchResults] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const dispatch = useDispatch();

useEffect(() => {
dispatch(fetchTrainingLibraries());
}, [dispatch]);
}, [dispatch]);

useEffect(() => {
setShowSearchResults(showSearchResults);
}, [slides]);

useEffect(() => {
if (libraries.length > 0) {
setIsLoading(false);
}
}, [libraries]);

const handleSearch = (e) => {
setSearch(e.target.value);
};
Expand All @@ -28,6 +35,35 @@ const TrainingLibraries = () => {
dispatch(searchTrainingLibraries(search));
setShowSearchResults(true);
};

if (isLoading) {
return (
<div className="container">
<div className="loading__spinner" />
</div>
);
}
if (libraries.length === 0) {
if (Features.wikiEd) {
return (
<div>
<p
dangerouslySetInnerHTML={{
__html: I18n.t('training.no_training_library_records_wiki_ed_mode', {
url: '/reload_trainings?module=all',
}),
}}
/>
</div>
);
}

return (
<div>
{I18n.t('training.no_training_library_records_non_wiki_ed_mode')}
</div>
);
}
return (
<div>
<h1>Training Libraries</h1>
Expand Down
1 change: 0 additions & 1 deletion app/controllers/training_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class TrainingController < ApplicationController

def index
@libraries = @query_object.all_libraries
render 'no_training_module' if @libraries.empty?
respond_to do |format|
format.html { render 'index' }
format.json { handle_json_request }
Expand Down

0 comments on commit 56afa0f

Please sign in to comment.