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

Add Kino.Download #174

Merged
merged 17 commits into from
Aug 5, 2022
Merged

Conversation

TylerPachal
Copy link
Contributor

@TylerPachal TylerPachal commented Jul 27, 2022

Attempts to address #19.

I am new to Kino, and not a Javascript exeprt, so I would appreciate some feedback on this.

The Javascript code was mostly taken from this jsfiddle.

I tested it in my local livebook instance like this:

Screen Shot 2022-07-27 at 5 13 58 PM

Copy link
Member

@jonatanklosko jonatanklosko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @TylerPachal, thanks for the PR :) A couple comments, since we need a bit different approach.

lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
test/kino/download_test.exs Outdated Show resolved Hide resolved
"""
export function init(ctx, data) {
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:attachment/text,' + encodeURI(data.content);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more generic, we can receive any binary from the server, then encode it as base64 and use data:application/octet-stream;base64;${dataBase64}. If we need to customize the content type explicitly, we can make it an option in Elixir, but I think we should be fine with application/octet-stream, especially that we specify the file name.

hiddenElement.click();
});

// Create the Download button
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: Not sure if there is any styling we can add 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can use any CSS we want, but don't worry about it, I can add some Livebook-matching style later :)

lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
lib/kino/download.ex Outdated Show resolved Hide resolved
@TylerPachal
Copy link
Contributor Author

Thanks for your help & feedback Jonatan! I am going to leave this here for now while we wait on #171

@jonatanklosko
Copy link
Member

Sounds good, thanks :)

@jonatanklosko
Copy link
Member

We have send_event/4 now, so I made final adjustments :)

image

@josevalim wdyt?

@josevalim
Copy link
Contributor

We should also add a label option. The text that we show should be: opts[:label] || opts[:filename] || "Download". other than that, it looks great to me!

@jonatanklosko jonatanklosko changed the title Create Kino.Download Add Kino.Download Aug 5, 2022
@jonatanklosko jonatanklosko merged commit c582ea2 into livebook-dev:main Aug 5, 2022
@TylerPachal TylerPachal deleted the kino-download branch August 8, 2022 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants