Skip to content

Commit

Permalink
Update lesson list (#2582)
Browse files Browse the repository at this point in the history
* Update progress bar color

* Update the position of "All my courses"

* Update the position of the progress bar and its label

* Update progress bar label color

* Update progress bar height

* Update course outline module header style

* do not display lesson title

* Update status color

* Update the course completed checking function

* render in progress status by half-filled-circle

* Update the styles of the lesson without a module

* Add locked icon

* fix sign in button style

* Add border-radius

* Move js files into src.

* add comments

* fix unstarted course icon border thickness

* update styles

- reduce space between lessons
- give unstarted course a thicker border

* Update the color of the progress bar on My Courses

* Use icons from wordpress library.

* update comments and remove the use of sensei icon

* Fix linting errors

* fix preview button style

* change to use @wordpress/element

* make code more concise

* Fix logged out not displaying icon error

* fix styles of moduled lesson items

* update style value
  • Loading branch information
renintw authored Jul 3, 2024
1 parent 4eaec88 commit 5dc3767
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 17 deletions.
1 change: 1 addition & 0 deletions wp-content/themes/pub/wporg-learn-2024/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// Block files
require_once __DIR__ . '/src/course-grid/index.php';
require_once __DIR__ . '/src/course-outline/index.php';
require_once __DIR__ . '/src/learning-pathway-cards/index.php';
require_once __DIR__ . '/src/learning-pathway-header/index.php';
require_once __DIR__ . '/src/lesson-grid/index.php';
Expand Down
4 changes: 3 additions & 1 deletion wp-content/themes/pub/wporg-learn-2024/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"private": true,
"devDependencies": {
"@wordpress/scripts": "27.2.0",
"rtlcss-webpack-plugin": "4.0.7"
"rtlcss-webpack-plugin": "4.0.7",
"@wordpress/icons": "^10.2.0",
"react-dom": "^18.3.1"
},
"eslintConfig": {
"extends": "../../../../.eslintrc.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<!-- wp:post-excerpt {"showMoreOnNewLine":false,"excerptLength":16,"style":{"typography":{"lineHeight":1.6},"layout":{"selfStretch":"fill","flexSize":null}}} /-->

<!-- wp:sensei-lms/course-progress {"barColor":"blueberry-1","defaultBarColor":"blueberry-1","barBackgroundColor":"blueberry-3","height":8,"className":"wporg-learn-sidebar-course-progress"} /-->
<!-- wp:sensei-lms/course-progress {"customBarColor":"var(--wp--custom--color--green-50)","height":8,"className":"wporg-learn-sidebar-course-progress"} /-->

<!-- wp:spacer {"height":"0px","style":{"layout":{"selfStretch":"fixed","flexSize":"0px"}}} -->
<div style="height:0px" aria-hidden="true" class="wp-block-spacer"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
* Inserter: no
*/

use function WPOrg_Learn\Sensei\{get_my_courses_page_url}
use function WPOrg_Learn\Sensei\{get_my_courses_page_url};

$completed_course = Sensei_Utils::user_completed_course( get_the_ID() );

?>

<!-- wp:group {"align":"full","className":"wporg-learn-sidebar-meta-info","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull wporg-learn-sidebar-meta-info">

<!-- wp:sensei-lms/course-progress {<?php echo ( $completed_course ? '"customTextColor":"var(--wp--custom--color--green-50)",' : '' ); ?>"customBarColor":"var(--wp--custom--color--green-50)","height":10,"className":"wporg-learn-sidebar-course-progress"} /-->

<?php if ( Sensei_Course::is_user_enrolled( get_the_ID() ) ) : ?>
<!-- wp:paragraph {"style":{"elements":{"link":{"color":{"text":"var:preset|color|blueberry-1"}}},"typography":{"fontStyle":"normal","fontWeight":"400","lineHeight":26px}},"textColor":"blueberry-1","fontSize":"normal","fontFamily":"inter","className":""wporg-learn-sidebar-all-courses"} -->
<p class="has-blueberry-1-color has-text-color has-link-color has-inter-font-family has-normal-font-size wporg-learn-sidebar-all-courses" style="font-style:normal;font-weight:400;line-height:26px">
<!-- wp:paragraph {"style":{"spacing":{"margin":{"bottom":"40px","top":"10px"}},"elements":{"link":{"color":{"text":"var:preset|color|blueberry-1"}}},"typography":{"fontStyle":"normal","fontWeight":"400","lineHeight":26px}},"textColor":"blueberry-1","fontSize":"normal","fontFamily":"inter","className":""wporg-learn-sidebar-all-courses"} -->
<p class="has-blueberry-1-color has-text-color has-link-color has-inter-font-family has-normal-font-size wporg-learn-sidebar-all-courses" style="font-style:normal;font-weight:400;line-height:26px;margin-top:10px;margin-bottom:40px">
<a href="<?php echo esc_url( get_my_courses_page_url() ); ?>">
<?php esc_html_e( 'All My Courses', 'wporg-learn' ); ?>
</a>
</p>
<!-- /wp:paragraph -->
<?php endif; ?>

<!-- wp:sensei-lms/course-progress {"barColor":"blueberry-1","barBackgroundColor":"blueberry-3","height":8,"className":"wporg-learn-sidebar-course-progress"} /-->

<!-- wp:sensei-lms/button-take-course {"align":"full","borderRadius":2,"className":"is-style-default"} -->
<div class="wp-block-sensei-lms-button-take-course is-style-default wp-block-sensei-button wp-block-button has-text-align-full">
<button class="wp-block-button__link" style="border-radius:2px">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"script": "file:./index.js"
}
28 changes: 28 additions & 0 deletions wp-content/themes/pub/wporg-learn-2024/src/course-outline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global wporgCourseOutlineData */

import { Icon, drafts, lockOutline } from '@wordpress/icons';
import { renderToString } from '@wordpress/element';

document.addEventListener( 'DOMContentLoaded', () => {
wporgCourseOutlineData[ 'in-progress' ]?.forEach( ( title ) => {
const lessonLinks = document.querySelectorAll( '.wp-block-sensei-lms-course-outline-lesson' );
lessonLinks.forEach( ( link ) => {
const span = link.querySelector( 'span' );
if ( span && span.textContent.trim() === title ) {
const statusIcon = link.querySelector( '.wp-block-sensei-lms-course-outline-lesson__status' );
if ( statusIcon ) {
statusIcon.outerHTML = renderToString( <Icon icon={ drafts } transform={ 'scale(1.5)' } /> );
}
}
} );
} );
wporgCourseOutlineData.locked?.forEach( ( title ) => {
const lessonLinks = document.querySelectorAll( '.wp-block-sensei-lms-course-outline-lesson' );
lessonLinks.forEach( ( link ) => {
const span = link.querySelector( 'span' );
if ( span && span.textContent.trim() === title ) {
span.insertAdjacentHTML( 'afterend', renderToString( <Icon icon={ lockOutline } /> ) );
}
} );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* Enqueue scripts and styles.
*/
function enqueue_assets() {
$script_asset_path = get_stylesheet_directory() . '/build/course-outline/index.asset.php';
if ( ! file_exists( $script_asset_path ) ) {
wp_die( 'You need to run `yarn start` or `yarn build` to build the required assets.' );
}

$script_asset = require( $script_asset_path );
wp_enqueue_script(
'wporg-learn-2024-course-outline',
get_stylesheet_directory_uri() . '/build/course-outline/index.js',
$script_asset['dependencies'],
$script_asset['version'],
true
);

if ( is_singular( 'course' ) ) {
$lesson_data = get_lesson_data();
wp_localize_script(
'wporg-learn-2024-course-outline',
'wporgCourseOutlineData',
$lesson_data
);
}
}
add_action( 'wp_enqueue_scripts', 'enqueue_assets' );

/**
* Get the titles of specific status lessons.
*
* The returned array $lesson_data has the following structure:
* [
* 'in-progress' => [ (string) The title of the lesson, ... ],
* 'locked' => [ (string) The title of the lesson, ... ],
* ]
*
* @return array $lesson_data Array of lesson data.
*/
function get_lesson_data() {
$lesson_data = array();
$lesson_ids = Sensei()->course->course_lessons( get_the_ID(), 'publish', 'ids' );

foreach ( $lesson_ids as $lesson_id ) {
$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
$lesson_title = get_the_title( $lesson_id );
$is_preview_lesson = Sensei_Utils::is_preview_lesson( $lesson_id );

// Add in-progress lesson title to lesson data
if ( $user_lesson_status ) {
$lesson_status = $user_lesson_status->comment_approved;
if ( 'in-progress' === $lesson_status ) {
$lesson_data['in-progress'][] = $lesson_title;
}
}

// Add previewable and prerequisite-required lesson title to lesson data
if ( ( ! $is_preview_lesson && ! Sensei_Course::is_user_enrolled( get_the_ID() ) )
|| ! Sensei_Lesson::is_prerequisite_complete( $lesson_id, get_current_user_id() )
) {
$lesson_data['locked'][] = $lesson_title;
}
}

return $lesson_data;
}
97 changes: 97 additions & 0 deletions wp-content/themes/pub/wporg-learn-2024/src/style/_sensei.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,103 @@ body.sensei {
font-size: var(--wp--preset--font-size--heading-2);
}
}

section.wp-block-sensei-lms-course-outline {
> section.wp-block-sensei-lms-course-outline-module-bordered {
border: 1px solid var(--wp--preset--color--light-grey-1) !important;
border-radius: 2px;

header {
background-color: var(--wp--preset--color--light-grey-2) !important;
color: var(--wp--preset--color--charcoal-1) !important;
padding: var(--wp--preset--spacing--20);

h2 {
font-size: var(--wp--preset--font-size--heading-6);
font-weight: 600;
}

div.wp-block-sensei-lms-course-outline-module__progress-indicator {
border-radius: 2px;

&.completed {
color: var(--wp--custom--color--green-50) !important;
}

.wp-block-sensei-lms-course-outline-module__progress-indicator__text {
font-family: "SF Pro Text", sans-serif;
font-size: 11px;
font-weight: 600;
line-height: var(--wp--custom--body--huge--typography--line-height);
margin: 4px 8px;
}
}
}

.wp-block-sensei-lms-course-outline-module__lessons-title {
display: none;
}

.wp-block-sensei-lms-collapsible {
// lesson item that belongs to a module
> .wp-block-sensei-lms-course-outline-lesson:first-of-type {
padding-top: 5px;
}

> .wp-block-sensei-lms-course-outline-lesson:last-of-type {
padding-bottom: 5px;
}
}
}

// every lesson item
.wp-block-sensei-lms-course-outline-lesson {
> span:first-of-type {
line-height: var(--wp--custom--body--short-text--typography--line-height);
padding: 15px var(--wp--preset--spacing--10);
}

> svg {
margin-left: var(--wp--preset--spacing--20);
}

> .wp-block-sensei-lms-course-outline-lesson__status {
border: 2px solid var(--wp--preset--color--charcoal-1);
}

> .wp-block-sensei-lms-course-outline-lesson__status:has(use) {
border-color: var(--wp--custom--color--green-50);
background: var(--wp--preset--color--acid-green-3);
color: var(--wp--custom--color--green-50);
}

> .wp-block-sensei-lms-course-outline-lesson__status--in-progress {
width: 24px;
height: 24px;
}

> .wp-block-sensei-lms-course-outline-lesson__status--locked {
width: 24px;
height: 24px;
}
}

// lesson item that doesn't belong to a module
> .wp-block-sensei-lms-course-outline-lesson {
padding-top: 5px;
padding-bottom: 5px;
border: 1px solid var(--wp--preset--color--light-grey-1) !important;
margin-bottom: var(--wp--preset--spacing--20) !important;
border-radius: 2px;
}
}

// sign in button on the lesson page when user is logged out
.sensei-course-theme-locked-lesson-notice__actions {
.is-secondary.sensei-course-theme__button {
border: solid 1px var(--sensei-secondary-color);
}
}
}

.course:not(body) {
Expand Down
11 changes: 1 addition & 10 deletions wp-content/themes/pub/wporg-learn-2024/src/style/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
}

.wporg-learn-sidebar-course-progress {
margin-top: 16px;
margin-bottom: 40px;
display: flex;
flex-direction: column;

.sensei-progress-bar__label {
order: 1;
margin-bottom: 0;
margin-top: 16px;
}
margin-bottom: unset;
}
}
1 change: 1 addition & 0 deletions wp-content/themes/pub/wporg-learn-2024/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"custom": {
"color": {
"border": "var(--wp--preset--color--light-grey-1)",
"green-50": "#008A20",
"green-70": "#005C12"
},
"form": {
Expand Down
Loading

0 comments on commit 5dc3767

Please sign in to comment.