Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmescript #18

Merged
merged 28 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
60bca49
Refactoring some more on the Sortable Elements
Sep 1, 2019
3345a29
Testing out programmescript refactor
Sep 2, 2019
0f5f7aa
Update stories
Sep 2, 2019
c2769b1
Updating stories for programme script
Sep 6, 2019
165c01e
Merge branch 'master' into programmescript
Sep 9, 2019
5f2b2c6
Refactoring, getting most of it to work together
Sep 9, 2019
a3f7dbe
Getting the storybooks to render elemts but not reorder corrently
Sep 9, 2019
c7d02e4
Temp commit
Sep 10, 2019
c0b0af3
Fixed programme elements
Sep 11, 2019
fb982d0
Removing insert as a separate component
Sep 11, 2019
067f1c7
Removed import
Sep 11, 2019
d3878e0
Updating the layout of the code
Sep 11, 2019
5937eaf
Removed comments
Sep 11, 2019
bde824c
refactor voice over
Sep 11, 2019
8a77a9c
moving sortable list to inside the programme script
Sep 11, 2019
564bbe8
simplifying sortable list
Sep 11, 2019
6d600e4
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 11, 2019
13b1716
Update packages/components/ProgrammeScriptContainer/stories/index.sto…
emettely Sep 11, 2019
a8bc602
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
30b09c4
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
43ac53d
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
5099b33
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
0ad35f3
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
9baa644
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
1664144
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
d8b85e2
Update packages/components/ProgrammeScriptContainer/ProgrammeElements…
emettely Sep 12, 2019
babf61c
Refactoring the number of arguments passed in into the Sortable Items
Sep 12, 2019
35d1e08
Merge branch 'programmescript' of https://github.com/bbc/digital-pape…
Sep 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@fortawesome/free-brands-svg-icons": "^5.8.2",
"@fortawesome/free-solid-svg-icons": "^5.10.1",
"@fortawesome/react-fontawesome": "^0.1.4",
"array-move": "^2.1.0",
"bootstrap": "^4.3.1",
"bootstrap-css-only": "^4.3.1",
"chroma-js": "^2.0.3",
Expand All @@ -47,6 +48,7 @@
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.0.1",
"react-select": "^2.4.3",
"react-sortable-hoc": "^1.10.1",
"sass-loader": "^7.1.0",
"save": "^2.4.0",
"style-loader": "^0.23.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStickyNote } from '@fortawesome/free-solid-svg-icons';
import PropTypes from 'prop-types';

const Note = (props) => (
<p className={ 'text-secondary' }>
<FontAwesomeIcon icon={ faStickyNote } /> { props.text }
</p>
);

Note.propTypes = {
text: PropTypes.any
};

export default Note;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import cuid from 'cuid';
import Col from 'react-bootstrap/Col';
import Row from 'react-bootstrap/Row';
import PropTypes from 'prop-types';

const PaperCut = (props) => {
let words;
if (props.words) {
// TODO could wrap words in span and add timecodes
// to make it cliccable on programme script
words = props.words.map((w) => {
return (
<span
key={ cuid() }
className="words"
title={ `stat: ${ w.start }- end: ${ w.end }` }
data-start={ w.start }
data-end={ w.end }
>
{w.text}
</span>
);
});
}

return (
<>
<Row>
<Col sm={ 3 } className={ 'text-truncate text-muted' }
// TODO: could add timecode from eg - ${ shortTimecode(this.props.words[0].start) }
// TODO: Could add transcript name along side the timecode for the paper-cut
title={ `${ props.speaker.toUpperCase() }` }
style={ { userSelect: 'none' } }>
<strong>{props.speaker.toUpperCase()}</strong>
{/* <br/> */}
{/* <u style={ { cursor: 'pointer' } }>00:01:20</u> */}
{/* <br/> */}
{/* <FontAwesomeIcon icon={ faTag } />TagExample */}
</Col>
<Col sm={ 9 }>
{ words }
</Col>
</Row>
</>
);
};

PaperCut.propTypes = {
speaker: PropTypes.any,
words: PropTypes.any
};

export default PaperCut;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import {
sortableHandle
} from 'react-sortable-hoc';

import {
faGripLines,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

const SortableHandle = sortableHandle(() => (
<span>
<FontAwesomeIcon icon={ faGripLines } />
</span>)
);

export default SortableHandle;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { SortableElement } from 'react-sortable-hoc';

import Col from 'react-bootstrap/Col';
import Row from 'react-bootstrap/Row';

import {
faPen,
faTrash,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import SortableHandle from './SortableHandle';

const SortableItem = SortableElement(({ value, index, handleDelete, handleEdit, backgroundColour, textColour }) => {

const EditIcon = (
<FontAwesomeIcon
className={ 'text-muted' }
icon={ faPen }
onClick={ () => { handleEdit(index); } }>
</FontAwesomeIcon>
);

const DeleteIcon = (
<FontAwesomeIcon
className={ 'text-muted' }
icon={ faTrash }
onClick={ () => { handleDelete(index); } }>
</FontAwesomeIcon>
);

return (
<li style={ { listStyle: 'none' } }>
<Row style={ { backgroundColor: backgroundColour } }>
<Col xs={ 1 } sm={ 1 } md={ 1 } ld={ 1 } xl={ 1 } >
<SortableHandle />
</Col>
<Col xs={ 8 } sm={ 9 } md={ 9 } ld={ 9 } xl={ 9 } >
<span style={ { color: textColour } }>
{value}
</span>
</Col>
<Col xs={ 1 } sm={ 1 } md={ 1 } ld={ 1 } xl={ 1 } >
{handleEdit ? EditIcon : null}
</Col>
<Col xs={ 1 } sm={ 1 } md={ 1 } ld={ 1 } xl={ 1 } >
{handleDelete ? DeleteIcon : null}
</Col>
</Row>
</li>
);
});

export default SortableItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const TitleHeading = ({ text }) => <h4>{text}</h4>;

export default TitleHeading;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faMicrophoneAlt } from '@fortawesome/free-solid-svg-icons';

const VoiceOver = ({ text }) =>
<p className={ 'text-muted' }>
<FontAwesomeIcon icon={ faMicrophoneAlt } />
{ text }
</p>;

export default VoiceOver;
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react';
import cuid from 'cuid';

import VoiceOver from './VoiceOver';
import PaperCut from './PaperCut';
import TitleHeading from './TitleHeading';
import Note from './Note';

import SortableItem from './SortableItem';

const adaptAddedElement = (type, text) => {
switch (type) {
case 'title':
return (<TitleHeading text={ text } />);
case 'voice-over':
return <VoiceOver text={ text } />;
case 'note':
return <Note text={ text } />;
default:
console.error('invalid added element type: ', type, text);

return null;
}
};

const ProgrammeElements = (elements, handleEdit, handleDelete) => {
return elements.map((el, index) => {
const key = cuid();
const type = el.type;
const text = el.text;

if (type === 'insert') {
return (
<SortableItem
key={ key }
index={ index }
value={ text }
backgroundColour="orange"
textColour="white"
/>
);

}

if (type === 'paper-cut') {
return (
<SortableItem
key={ key }
index={ index }
value={
<PaperCut
speaker={ el.speaker }
words={ el.words }
/>
}
handleDelete={ handleDelete }
handleEdit={ null }
/>);
}

return (
<SortableItem
key={ key }
index={ index }
value={ adaptAddedElement(type, text) }
handleDelete={ handleDelete }
handleEdit={ handleEdit }
/>
);
});
};

export default ProgrammeElements;
38 changes: 38 additions & 0 deletions packages/components/ProgrammeScriptContainer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import arrayMove from 'array-move';
import { SortableContainer, } from 'react-sortable-hoc';
import ProgrammeElements from './ProgrammeElements';

const ProgrammeScriptContainer = (props) => {
const programmeElements = ProgrammeElements(props.items, props.handleEdit, props.handleDelete);
const [ elements, setElements ] = useState(programmeElements);

const onSortEnd = ({ oldIndex, newIndex }) => {
const result = arrayMove(elements, oldIndex, newIndex);
props.handleReorder(result);
setElements(result);
};

const SortableList = SortableContainer(({ children }) =>
<ul style={ { listStyle: 'none', padding: '0px' } }>
{children}
</ul>
);

return (
<SortableList useDragHandle onSortEnd={ onSortEnd }>
{elements}
</SortableList>
);

};

ProgrammeScriptContainer.propTypes = {
items: PropTypes.any,
handleDelete: PropTypes.func,
handleEdit: PropTypes.func,
handleReorder: PropTypes.func
};

export default ProgrammeScriptContainer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';

import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import ProgrammeScriptContainer from '../index.js';

export const handleReorderActions = action('Handle reorder');
export const handleDeleteActions = action('Handle delete');
export const handleEditActions = action('Handle edit');

const items = [
{
type: 'title',
text: 'An immense Achievement'
},
{
type: 'paper-cut',
id: 1,
speaker: 'Mr Loud',
words: [ { text:'Greatest day of my life was when I wrote this text.', start: 0, end: 1 } ]
},
{
type: 'note',
text: 'Maybe a little bit obnoxious'
},
{
type: 'insert',
text: 'Insert New Selection here'
},
{
type: 'paper-cut',
id: 2,
speaker: 'Mrs Loud',
words: [ { text:'Greatest day of my life was when I spoke this text.', start: 0, end: 1 } ]
},
{
type: 'voice-over',
text: 'link: wonderful times of the Loud family'
},
];


storiesOf('ProgrammeScript', module)
.add('Default', () =>
<ProgrammeScriptContainer
items={ items }
handleDelete={ handleDeleteActions }
handleEdit={ handleEditActions }
handleReorder={ handleReorderActions }
/>
);
8 changes: 6 additions & 2 deletions packages/components/SimpleCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ const SimpleCard = (props) => {
const confirmDeleteText = "Click OK if you wish to delete or cancel if you don't";
const cancelDeleteText = 'All is good, it was not deleted';
const confirmationPrompt = window.confirm(confirmDeleteText);

if (confirmationPrompt) {
props.handleDelete ? props.handleDelete(props.id) : alert(cancelDeleteText);
if (props.handleDelete) {
props.handleDelete(props.id);
} else {
alert(cancelDeleteText);
}
}
};

Expand Down