-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMS-34: Add park name audio collection
- Loading branch information
Showing
13 changed files
with
214 additions
and
8 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/cms/src/api/park-name-audio/content-types/park-name-audio/schema.json
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,35 @@ | ||
{ | ||
"kind": "collectionType", | ||
"collectionName": "park_name_audios", | ||
"info": { | ||
"singularName": "park-name-audio", | ||
"pluralName": "park-name-audios", | ||
"displayName": "Park-name-audio", | ||
"description": "" | ||
}, | ||
"options": { | ||
"draftAndPublish": true | ||
}, | ||
"attributes": { | ||
"title": { | ||
"type": "string", | ||
"required": true | ||
}, | ||
"url": { | ||
"type": "string", | ||
"required": true | ||
}, | ||
"credit": { | ||
"type": "string" | ||
}, | ||
"transcript": { | ||
"type": "text" | ||
}, | ||
"protectedArea": { | ||
"type": "relation", | ||
"relation": "oneToOne", | ||
"target": "api::protected-area.protected-area", | ||
"inversedBy": "parkNameAudio" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/cms/src/api/park-name-audio/controllers/park-name-audio.js
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,9 @@ | ||
'use strict'; | ||
|
||
/** | ||
* park-name-audio controller | ||
*/ | ||
|
||
const { createCoreController } = require('@strapi/strapi').factories; | ||
|
||
module.exports = createCoreController('api::park-name-audio.park-name-audio'); |
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,9 @@ | ||
'use strict'; | ||
|
||
/** | ||
* park-name-audio router | ||
*/ | ||
|
||
const { createCoreRouter } = require('@strapi/strapi').factories; | ||
|
||
module.exports = createCoreRouter('api::park-name-audio.park-name-audio'); |
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,9 @@ | ||
'use strict'; | ||
|
||
/** | ||
* park-name-audio service | ||
*/ | ||
|
||
const { createCoreService } = require('@strapi/strapi').factories; | ||
|
||
module.exports = createCoreService('api::park-name-audio.park-name-audio'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useState, useEffect, useRef } from "react" | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" | ||
import { | ||
faVolumeHigh, | ||
faChevronUp, | ||
faChevronDown, | ||
} from "@fortawesome/free-solid-svg-icons" | ||
import "../styles/audioButton.scss" | ||
|
||
export default function AudioButton({ audio }) { | ||
const audioRef = useRef(null) | ||
const [trackSrc, setTrackSrc] = useState("") | ||
const [expanded, setExpanded] = useState(false) | ||
|
||
const handlePlay = () => { | ||
if (audioRef.current) { | ||
audioRef.current.play() | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
// convert transcript to vtt format | ||
const vttContent = `WEBVTT\n\n1\n00:00:00.000 --> 00:00:10.000\n${audio.transcript}` | ||
// create a blob from the vtt content | ||
const blob = new Blob([vttContent], { type: "text/vtt" }) | ||
const url = URL.createObjectURL(blob) | ||
setTrackSrc(url) | ||
return () => { | ||
URL.revokeObjectURL(url) | ||
} | ||
}, [audio.transcript]) | ||
|
||
return ( | ||
<div className="audio-container"> | ||
<div className="audio-container--left"> | ||
<button | ||
aria-label="Play park name audio" | ||
onClick={handlePlay} | ||
className="btn-audio" | ||
> | ||
<FontAwesomeIcon icon={faVolumeHigh} /> | ||
</button> | ||
<audio ref={audioRef} src={audio.url}> | ||
<track kind="captions" srcLang="en" src={trackSrc} /> | ||
</audio> | ||
</div> | ||
<div className="audio-container--right"> | ||
<p> | ||
<b>{audio.title}</b> | ||
</p> | ||
<p> | ||
<small> | ||
Spoken in {audio.credit} pronounced by {audio.credit} | ||
</small> | ||
</p> | ||
{expanded && ( | ||
<div className="mb-3"> | ||
<p> | ||
<small> | ||
<b>Transcript</b> | ||
</small> | ||
</p> | ||
<small>{audio.transcript}</small> | ||
</div> | ||
)} | ||
{audio.transcript && ( | ||
<button | ||
aria-label={expanded ? "Hide transcript" : "Show transcript"} | ||
onClick={() => setExpanded(!expanded)} | ||
className="btn btn-link expand-icon transcript-link" | ||
> | ||
{expanded ? ( | ||
<> | ||
Hide transcript <FontAwesomeIcon icon={faChevronUp} /> | ||
</> | ||
) : ( | ||
<> | ||
Show transcript <FontAwesomeIcon icon={faChevronDown} /> | ||
</> | ||
)} | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@import "variables.scss"; | ||
|
||
.audio-container { | ||
max-width: 600px; | ||
display: flex; | ||
&--left { | ||
margin-right: 16px; | ||
} | ||
} |
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