Skip to content

Commit

Permalink
Remove exceptions for require-jsdoc rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Oct 11, 2019
1 parent 64e8fb9 commit b184437
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable require-jsdoc */
/**
* WordPress dependencies
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable require-jsdoc */
/**
* WordPress dependencies
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable require-jsdoc */
/**
* External dependencies
*/
Expand All @@ -11,22 +10,12 @@ import { __experimentalGetSettings } from '@wordpress/date';
import { addQueryArgs } from '@wordpress/url';
import apiFetch from '@wordpress/api-fetch';

export async function getDataFromAPI() {
const data = await fetchFromAPI();
const sessions = data[ 0 ].map( ( session ) => {
const terms = flatten( get( session, '_embedded[wp:term]', [] ) );
return {
...session,
terms: keyBy( terms, 'id' ),
};
} );

const tracks = data[ 1 ];

return getSessions( { sessions, tracks } );
}

export function fetchFromAPI() {
/**
* Fetch data from REST API for sessions and tracks.
*
* @return {Promise} A promise that will resolve when both sessions and tracks are fetched.
*/
function fetchFromAPI() {
const sessionPath = addQueryArgs( `wp/v2/sessions`, {
per_page: -1,
status: 'publish',
Expand All @@ -43,7 +32,12 @@ export function fetchFromAPI() {
] );
}

export function getSessions( { sessions, tracks } ) {
/**
* Given sessions, tracks, and the current time, find out which tracks are currently running, and which are next.
*
* @return {Array} A list of objects, `{track, now, next}`.
*/
function getSessions( { sessions, tracks } ) {
const tzOffset = __experimentalGetSettings().timezone.offset * ( 60 * 60 * 1000 );
const nowUTC = window.WordCampBlocks[ 'live-schedule' ].nowOverride || Date.now();
const nowLocal = new Date( nowUTC );
Expand All @@ -69,3 +63,24 @@ export function getSessions( { sessions, tracks } ) {
};
} );
}

/**
* Async function to get session and tracks data from the REST API, formatted into currently running sessions
* per track.
*
* @return {Promise}
*/
export async function getDataFromAPI() {
const data = await fetchFromAPI();
const sessions = data[ 0 ].map( ( session ) => {
const terms = flatten( get( session, '_embedded[wp:term]', [] ) );
return {
...session,
terms: keyBy( terms, 'id' ),
};
} );

const tracks = data[ 1 ];

return getSessions( { sessions, tracks } );
}

0 comments on commit b184437

Please sign in to comment.