-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Port List functionality to TypeScript #243
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
542cdd8
Setup lists feature in TypeScript
pixeldesu d3d4644
Port list membership actions from CoffeeScript to TypeScript
pixeldesu 4a94638
Port deleting lists from CoffeeScript to TypeScript
pixeldesu d848917
Port creating lists from CoffeeScript to TypeScript
pixeldesu 493451c
Remove legacy list CoffeeScript
pixeldesu 6df040e
Fix missing translation when deleting lists
pixeldesu 06e31bb
Apply review suggestion from @raccube
pixeldesu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
import Rails from '@rails/ujs'; | ||
import I18n from '../../../legacy/i18n'; | ||
|
||
export function createListHandler(event: Event): void { | ||
const button = event.target as HTMLButtonElement; | ||
const input = document.querySelector<HTMLInputElement>('input#new-list-name'); | ||
|
||
Rails.ajax({ | ||
url: '/ajax/create_list', | ||
type: 'POST', | ||
data: new URLSearchParams({ | ||
name: input.value, | ||
user: button.dataset.user | ||
}).toString(), | ||
success: (data) => { | ||
if (data.success) { | ||
document.querySelector('#lists-list ul.list-group').insertAdjacentHTML('beforeend', data.render); | ||
} | ||
|
||
window['showNotification'](data.message, data.success); | ||
}, | ||
error: (data, status, xhr) => { | ||
console.log(data, status, xhr); | ||
window['showNotification'](I18n.translate('frontend.error.message'), false); | ||
} | ||
}); | ||
} | ||
|
||
export function createListInputHandler(event: KeyboardEvent): void { | ||
if (event.which === 13) { | ||
event.preventDefault(); | ||
document.querySelector<HTMLButtonElement>('button#create-list').click(); | ||
} | ||
} |
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,43 @@ | ||
import Rails from '@rails/ujs'; | ||
import swal from 'sweetalert'; | ||
import I18n from '../../../legacy/i18n'; | ||
|
||
export function destroyListHandler(event: Event): void { | ||
event.preventDefault(); | ||
const button = event.target as HTMLButtonElement; | ||
const list = button.dataset.list; | ||
|
||
swal({ | ||
title: I18n.translate('frontend.list.confirm.title'), | ||
text: I18n.translate('frontend.list.confirm.text'), | ||
type: "warning", | ||
showCancelButton: true, | ||
confirmButtonColor: "#DD6B55", | ||
confirmButtonText: I18n.translate('views.actions.delete'), | ||
cancelButtonText: I18n.translate('views.actions.cancel'), | ||
closeOnConfirm: true | ||
}, () => { | ||
Rails.ajax({ | ||
url: '/ajax/destroy_list', | ||
type: 'POST', | ||
data: new URLSearchParams({ | ||
list: list | ||
}).toString(), | ||
success: (data) => { | ||
if (data.success) { | ||
const element = document.querySelector(`li.list-group-item#list-${list}`); | ||
|
||
if (element) { | ||
element.remove(); | ||
} | ||
} | ||
|
||
window['showNotification'](data.message, data.success); | ||
}, | ||
error: (data, status, xhr) => { | ||
console.log(data, status, xhr); | ||
window['showNotification'](I18n.translate('frontend.error.message'), false); | ||
} | ||
}); | ||
}); | ||
} |
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,11 @@ | ||
import { on } from 'retrospring/utilities/on'; | ||
import { createListHandler, createListInputHandler } from './create'; | ||
import { destroyListHandler } from './destroy'; | ||
import { listMembershipHandler } from './membership'; | ||
|
||
export default (): void => { | ||
on('click', 'input[type=checkbox][name=gm-list-check]', listMembershipHandler); | ||
on('click', 'button#create-list', createListHandler); | ||
on('click', 'a#delete-list', destroyListHandler); | ||
on('keyup', 'input#new-list-name', createListInputHandler); | ||
} |
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,37 @@ | ||
import Rails from '@rails/ujs'; | ||
import I18n from '../../../legacy/i18n'; | ||
|
||
export function listMembershipHandler(event: Event): void { | ||
const checkbox = event.target as HTMLInputElement; | ||
const list = checkbox.dataset.list; | ||
let memberCount = Number(document.querySelector(`span#${list}-members`).innerHTML); | ||
|
||
checkbox.setAttribute('disabled', 'disabled'); | ||
|
||
memberCount += checkbox.checked ? 1 : -1; | ||
|
||
Rails.ajax({ | ||
url: '/ajax/list_membership', | ||
type: 'POST', | ||
data: new URLSearchParams({ | ||
list: list, | ||
user: checkbox.dataset.user, | ||
add: String(checkbox.checked) | ||
}).toString(), | ||
success: (data) => { | ||
if (data.success) { | ||
checkbox.checked = data.checked; | ||
document.querySelector(`span#${list}-members`).innerHTML = memberCount.toString(); | ||
} | ||
|
||
window['showNotification'](data.message, data.success); | ||
}, | ||
error: (data, status, xhr) => { | ||
console.log(data, status, xhr); | ||
window['showNotification'](I18n.translate('frontend.error.message'), false); | ||
}, | ||
complete: () => { | ||
checkbox.removeAttribute('disabled'); | ||
} | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment of what key this is would be nice