Skip to content

Instantly share code, notes, and snippets.

@colorfield
Last active June 13, 2017 14:27
Show Gist options
  • Save colorfield/7b7df89a52c22ce7a58e47d443ca9666 to your computer and use it in GitHub Desktop.
Save colorfield/7b7df89a52c22ce7a58e47d443ca9666 to your computer and use it in GitHub Desktop.
AudioGuide demo - React audio_page route
import React from 'react';
import { REST_HOST_NAME } from '../../constants';
import Layout from '../../components/Layout';
import AudioContentPage from '../../components/AudioContentPage';
export default {
path: '/audio/:id',
async action({ params }) {
// @todo add language
const nodeEndpoint = `${REST_HOST_NAME}/jsonapi/node/audio/${params.id}`;
const nodeResponse = await fetch(nodeEndpoint).then(response => response.json());
// @todo simply replace by an include like
// const nodeEndpoint = `${REST_HOST_NAME}/jsonapi/node/audio/${params.id}?include=field_mp3`;
const fileUUID = nodeResponse.data.relationships.field_mp3.data.id;
const fileEndpoint = `${REST_HOST_NAME}/jsonapi/file/file/${fileUUID}`;
const fileResponse = await fetch(fileEndpoint).then(response => response.json());
const data = { node: nodeResponse, mp3File: fileResponse };
return {
title: nodeResponse.data.attributes.title,
chunk: 'audio_page',
component: <Layout><AudioContentPage {...data} /></Layout>,
};
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment