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
How to use timeline in REACT? #633
Comments
We have not done any work to integrate TimelineJS with React. By far, our development has been focused on making it work well as an iframe embed. To begin, you probably couldn't use it as an iframe embed. Messaging between iframes and their hosts when the pages are served from different servers is complex and requires development we haven't done. You could instantiate the timeline on a page yourself in JavaScript. This, in itself, doesn't relate to React. However, the timeline should be sending events as various interactions happen, which, in principle, React or other JavaScript could listen for. This, too, is not something we've focused on or tested heavily, so for now, it would require looking through the code and working out a lot of things for yourself. Formally developing, testing, and documenting Timeline's event system for deeper integration is not currently on our roadmap. |
There is a very basic React example in the contrib folder here: https://github.com/NUKnightLab/TimelineJS3/blob/master/contrib/examples/react.html It might be dated at this point, and we don't use React much in the lab, so no promises really, but the example should provide an idea of how to get started. |
Based on @Granado's comment on the NPM issue #573, here's another approach to use the timeline in a Download the compiled version of
Create the
Make a React component,
|
However, there's a problem with displaying media when using the timeline in a React component. Images load OK but videos fail. Seems to be a problem with adding DOM elements. |
I believe React.useEffect(() => {
if (timelineEl.current) {
const timeline = new TL.Timeline(timelineEl.current, { events: [] });
}
}, []); Otherwise |
Using @benfoley 's explanation I got it to work for my (React Typescript) project and I thought I'd save other people the trouble by packaging it on npm. If you guys have any problem with me packaging your library like this, let me know, I just thought it would be handy to have it as a ready-to-use React component like |
Since we don't do a lot of React development, I'm happy to have someone who does be responsible for maintaining a library which works. Note that, based on discussion in #705, beginning with TimelineJS 3.8.18 it should be more straightforward to import the |
This commit adds the timelinejs npm module and imports it into the VisualizationsPage component. I found some notes on how to wire things up in this issue: NUKnightLab/TimelineJS3#633 Since I'm not familiar with the original it's hard for me to say if it's working completely, but at least it appears to be loading. Since TimelineJS CSS uses less I needed to install & add gatsby-plugin-less. Also, in order to get the build to work I needed to remove timelinejs from the server side build since it wanted to access the global navigator which is only available in the browser: https://www.gatsbyjs.com/docs/debugging-html-builds/#fixing-third-party-modules
Hey @benfoley Getting following errors. Can you please help out? |
hi, these all look like ESLint errors. Looks like you need to work through your code to clean it up according to the lint rules you are using. |
Thankyou so much for quick reply, now the errors have gone. @benfoley
|
Yes you should be able to import data from json file and use that data in events. Look here for an example. |
Thanks @benfoley for assisting me through this, can you please share the example of data you used to run the timeline? Which means that the Timeline is not getting data in a particular format Vine Test ","asset": { "media": "https://vine.co/v/b55LOA1dgJU", "credit": "", "caption": "" } }, { "startDate": "2012,1,26", "endDate": "2012,1,27", "headline": "Sht Politicians Say", "text": " In true political fashion, his character rattles off common jargon heard from people running for office. ","asset": { "media": "http://youtu.be/u4XpeU9erbg", "credit": "", "caption": "" } }, { "startDate": "2012,1,10", "headline": "Sh*t Nobody Says", "text": " Have you ever heard someone say “can I burn a copy of your Nickelback CD?” or “my Bazooka gum still has flavor!” Nobody says that. ","asset": { "media": "http://youtu.be/f-x8t0JOnVw", "credit": "", "caption": "" } }, ] } } |
Hi,
The data you shared is not valid JSON, so it is probably causing the import to fail.
Try using an online JSON validator such https://jsonlint.com/ <https://jsonlint.com/> as to check and correct your data format.
Also, note that you can’t include multi line text in JSON. See https://stackoverflow.com/a/2392888 <https://stackoverflow.com/a/2392888> for more info. Rather than using \n as suggested at that link, we used <br> tags which Timeline.js parses as HTML line breaks.
B
… On 19 Aug 2021, at 4:41 pm, shreyaagrawal0809 ***@***.***> wrote:
Thanks @benfoley <https://github.com/benfoley> for assisting me through this, can you please share the example of data you used to run the timeline?
No matter how I am giving the data getting this error
TypeError: Cannot read property 'Timeline' of undefined
Which means that the Timeline is not getting data in a particular format
My data looks like this:
[
{
"timeline": {
"headline": "Sht People Say",
"type": "default",
"title": "hello",
"text": "People say stuff",
"startDate": "2012,1,26",
"date": [
{
"startDate": "2011,12,12",
"endDate": "2012,1,27",
"headline": "Vine",
"text": "
Vine Test
",
"asset": {
"media": "https://vine.co/v/b55LOA1dgJU",
"credit": "",
"caption": ""
}
},
{
"startDate": "2012,1,26",
"endDate": "2012,1,27",
"headline": "Sht Politicians Say",
"text": "
In true political fashion, his character rattles off common jargon heard from people running for office.
",
"asset": {
"media": "http://youtu.be/u4XpeU9erbg",
"credit": "",
"caption": ""
}
},
{
"startDate": "2012,1,10",
"headline": "Sh*t Nobody Says",
"text": "
Have you ever heard someone say “can I burn a copy of your Nickelback CD?” or “my Bazooka gum still has flavor!” Nobody says that.
",
"asset": {
"media": "http://youtu.be/f-x8t0JOnVw",
"credit": "",
"caption": ""
}
},
]
}
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#633 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABLD5GFJIRDA2QBYMKT6DXTT5SRQBANCNFSM4L3IQF7Q>.
|
This is the format of our title JSON data:
This is the format of the events JSON we use.
|
For example, I want to switch different React components when I change the timeline node
The text was updated successfully, but these errors were encountered: