Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions src/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ span.Allowlist__url {
font-size: 0.8em;
}

.BulkImport__optionsBody {
display: flex;
gap: 3rem;
align-items: baseline;
margin: 1rem;
}

.file-name {
Copy link
Owner

Choose a reason for hiding this comment

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

let's keep the naming convention of BulkImportModal__fileName

max-width: 11rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

/* Color picker */
.picker_editor input {
font-family: BlinkMacSystemFont, -apple-system, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
Expand Down
46 changes: 31 additions & 15 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,37 @@ <h1 class="title">
<button id="BulkImportModal__close" class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body">
<div class="field">
<label class="label">Import Type</label>
<div class="control">
<div class="select">
<select id="BulkImportModal__typesSelect">
<option id="BulkImportModal__typesSelect--ImportAsNew" value="ImportAsNew">
Import as new lists
</option>
<option id="BulkImportModal__typesSelect--ImportAndMerge" value="ImportAndMerge">
Import and merge lists
</option>
<option id="BulkImportModal__typesSelect--Replace" value="Replace">
Replace existing lists
</option>
</select>
<div class="BulkImport__optionsBody">
<div class="field">
<label class="label">Import Type</label>
<div class="control">
<div class="select">
<select id="BulkImportModal__typesSelect">
<option id="BulkImportModal__typesSelect--ImportAsNew" value="ImportAsNew">
Import as new lists
</option>
<option id="BulkImportModal__typesSelect--ImportAndMerge" value="ImportAndMerge">
Import and merge lists
</option>
<option id="BulkImportModal__typesSelect--Replace" value="Replace">
Replace existing lists
</option>
</select>
</div>
</div>
</div>
<div class="field">
<label class="label">Import from File</label>
<div id="BulkImport__file" class="file is-normal">
<label class="file-label">
<input class="file-input" type="file" accept=".json, .txt" name="resume">
Copy link
Owner

Choose a reason for hiding this comment

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

name probably doesn't do anything here

Copy link
Owner

Choose a reason for hiding this comment

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

we can add an ID here BulkImportModal__fileInput

<span class="file-cta">
<span class="file-label">
Choose a file…
</span>
</span>
<span class="file-name" style="display: none"></span>
</label>
</div>
</div>
</div>
Expand Down
28 changes: 28 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,30 @@ $(function () {
$('#BulkImportPreviewModal__optionName').text(importName);
});

$('.file-input').on('change', (e) => {
const file = e.target.files[0];
if (!file) return;

const allowedExtensions = ['txt', 'json'];
const fileName = file.name;
const fileExtension = fileName.split('.').pop().toLowerCase();

if (!allowedExtensions.includes(fileExtension)) {
alert('Please upload a file with .txt or .json extension.');
return;
}

const reader = new FileReader();
reader.onload = function (e) {
const contents = e.target.result;
$('#BulkImport__file').removeClass('is-normal');
$('#BulkImport__file').addClass('has-name');
$('.file-name').text(fileName).show();
$('#BulkImportModal__body').val(contents);
};
reader.readAsText(file);
});

$('#BulkImportModal__previewImport').on('click', (e) => {
const importType = $('#BulkImportModal__typesSelect').val();
const importBody = $('#BulkImportModal__body').val();
Expand Down Expand Up @@ -717,6 +741,10 @@ $(function () {
$('#BulkExportModal').removeClass('is-active');
});
$('#BulkImportModal__cancel, #BulkImportModal__close').on('click', (e) => {
$('.file-input').val('');
Copy link
Owner

Choose a reason for hiding this comment

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

Should use convention

$('.file-name').text('').hide();
$('#BulkImport__file').removeClass('has-name');
$('#BulkImport__file').addClass('is-normal');
$('#BulkImportModal').removeClass('is-active');
});
$('#BulkImportPreviewModal__cancel, #BulkImportPreviewModal__close').on('click', (e) => {
Expand Down