Skip to content

Commit

Permalink
Merge pull request #168 from jaredmoody/standard-js
Browse files Browse the repository at this point in the history
Fixes #157 - Replace eslint with standard js
  • Loading branch information
aidewoode authored Jun 6, 2022
2 parents d70b16e + 02dcbcb commit c513ac0
Show file tree
Hide file tree
Showing 25 changed files with 1,331 additions and 1,095 deletions.
40 changes: 0 additions & 40 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
bundler-cache: true
- uses: actions/setup-node@v2
with:
node-version: 12.20.0
node-version: 12.22.0
cache: 'yarn'
- run: yarn install
- name: Test and Lint
Expand Down
8 changes: 4 additions & 4 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@hotwired/turbo-rails';
import './controllers';
import '@hotwired/turbo-rails'
import './controllers'

import Player from './player';
import Player from './player'

window.App = { player: new Player() };
window.App = { player: new Player() }
10 changes: 5 additions & 5 deletions app/javascript/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Application } from '@hotwired/stimulus';
import { Application } from '@hotwired/stimulus'

const application = Application.start();
const application = Application.start()

// Configure Stimulus development experience
application.debug = false;
window.Stimulus = application;
application.debug = false
window.Stimulus = application

export { application };
export { application }
28 changes: 14 additions & 14 deletions app/javascript/controllers/dialog_controller.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { Controller } from '@hotwired/stimulus';
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static values = {
isShown: Boolean
}

initialize() {
initialize () {
if (this.isShownValue) {
this.show();
this.show()
} else {
this.hide();
this.hide()
}
}

connect() {
this.element.addEventListener('dialog:hide', this.hide);
this.element.addEventListener('dialog:show', this.show);
connect () {
this.element.addEventListener('dialog:hide', this.hide)
this.element.addEventListener('dialog:show', this.show)
}

disconnect() {
this.element.removeEventListener('dialog:hide', this.hide);
this.element.removeEventListener('dialog:show', this.show);
disconnect () {
this.element.removeEventListener('dialog:hide', this.hide)
this.element.removeEventListener('dialog:show', this.show)
}

show = () => {
document.querySelector('#js-overlay').classList.remove('u-display-none');
this.element.classList.remove('u-display-none');
document.querySelector('#js-overlay').classList.remove('u-display-none')
this.element.classList.remove('u-display-none')
}

hide = () => {
document.querySelector('#js-overlay').classList.add('u-display-none');
this.element.classList.add('u-display-none');
document.querySelector('#js-overlay').classList.add('u-display-none')
this.element.classList.add('u-display-none')
}
}
12 changes: 6 additions & 6 deletions app/javascript/controllers/dropdown_controller.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Controller } from '@hotwired/stimulus';
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['list'];
static targets = ['list']

show() {
this.listTarget.classList.remove('u-display-none');
show () {
this.listTarget.classList.remove('u-display-none')

document.addEventListener('click', () => {
this.listTarget.classList.add('u-display-none');
}, { once: true, capture: true });
this.listTarget.classList.add('u-display-none')
}, { once: true, capture: true })
}
}
16 changes: 8 additions & 8 deletions app/javascript/controllers/flash_controller.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Controller } from '@hotwired/stimulus';
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static values = {
timeout: { type: Number, default: 4000 }
}

connect() {
setTimeout(this._removeFlash.bind(this), this.timeoutValue);
connect () {
setTimeout(this._removeFlash.bind(this), this.timeoutValue)
}

_removeFlash() {
this.element.addEventListener('animationend', function removeFlashElement() {
this.remove();
}, { once: true });
_removeFlash () {
this.element.addEventListener('animationend', function removeFlashElement () {
this.remove()
}, { once: true })

this.element.classList.add('o-animation-fadeOutUp');
this.element.classList.add('o-animation-fadeOutUp')
}
}
6 changes: 3 additions & 3 deletions app/javascript/controllers/form_controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from '@hotwired/stimulus';
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
reset() {
this.element.reset();
reset () {
this.element.reset()
}
}
58 changes: 29 additions & 29 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

import { application } from './application';
import { application } from './application'

import DialogController from './dialog_controller.js';
import DialogController from './dialog_controller.js'

application.register('dialog', DialogController);
import DropdownController from './dropdown_controller.js'

import DropdownController from './dropdown_controller.js';
import FlashController from './flash_controller.js'

application.register('dropdown', DropdownController);
import FormController from './form_controller.js'

import FlashController from './flash_controller.js';
import InfiniteScrollController from './infinite_scroll_controller.js'

application.register('flash', FlashController);
import LoaderController from './loader_controller.js'

import FormController from './form_controller.js';
import MediaSessionController from './media_session_controller.js'

application.register('form', FormController);
import MiniPlayerController from './mini_player_controller.js'

import InfiniteScrollController from './infinite_scroll_controller.js';
import PlayerController from './player_controller.js'

application.register('infinite-scroll', InfiniteScrollController);
import PlaylistController from './playlist_controller.js'

import LoaderController from './loader_controller.js';
import PlaylistSongsController from './playlist_songs_controller.js'

application.register('loader', LoaderController);
import PlaylistSortableController from './playlist_sortable_controller.js'

import MediaSessionController from './media_session_controller.js';
import SearchController from './search_controller.js'

application.register('media-session', MediaSessionController);
import ThemeController from './theme_controller.js'

import MiniPlayerController from './mini_player_controller.js';
application.register('dialog', DialogController)

application.register('mini-player', MiniPlayerController);
application.register('dropdown', DropdownController)

import PlayerController from './player_controller.js';
application.register('flash', FlashController)

application.register('player', PlayerController);
application.register('form', FormController)

import PlaylistController from './playlist_controller.js';
application.register('infinite-scroll', InfiniteScrollController)

application.register('playlist', PlaylistController);
application.register('loader', LoaderController)

import PlaylistSongsController from './playlist_songs_controller.js';
application.register('media-session', MediaSessionController)

application.register('playlist-songs', PlaylistSongsController);
application.register('mini-player', MiniPlayerController)

import PlaylistSortableController from './playlist_sortable_controller.js';
application.register('player', PlayerController)

application.register('playlist-sortable', PlaylistSortableController);
application.register('playlist', PlaylistController)

import SearchController from './search_controller.js';
application.register('playlist-songs', PlaylistSongsController)

application.register('search', SearchController);
application.register('playlist-sortable', PlaylistSortableController)

import ThemeController from './theme_controller.js';
application.register('search', SearchController)

application.register('theme', ThemeController);
application.register('theme', ThemeController)
44 changes: 22 additions & 22 deletions app/javascript/controllers/infinite_scroll_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller } from '@hotwired/stimulus';
import { fetchTurboStream } from '../helper';
import { Controller } from '@hotwired/stimulus'
import { fetchTurboStream } from '../helper'

export default class extends Controller {
static targets = ['trigger']
Expand All @@ -10,53 +10,53 @@ export default class extends Controller {
totalPages: Number
}

initialize() {
this.page = 2;
initialize () {
this.page = 2
}

connect() {
if (!this.hasNextPage) { return; }
connect () {
if (!this.hasNextPage) { return }

this.observer = new IntersectionObserver(this._handleNextPageLoad.bind(this), {
root: this.hasContainerValue ? document.querySelector(this.containerValue) : document,
rootMargin: '0px',
threshold: 1.0
});
})

this.observer.observe(this.triggerTarget);
this.observer.observe(this.triggerTarget)
}

disconnect() {
disconnect () {
if (this.observer) {
this.observer.disconnect();
this.observer.disconnect()
}
}

_handleNextPageLoad(entries) {
_handleNextPageLoad (entries) {
entries.forEach((entry) => {
if (!entry.intersectionRatio == 1) { return; }
if (!entry.intersectionRatio === 1) { return }

if (!this.hasNextPage) {
this.triggerTarget.classList.add('u-display-none');
return;
this.triggerTarget.classList.add('u-display-none')
return
}

if (this.abortController) {
// Abort previous fetch request.
this.abortController.abort();
this.abortController.abort()
}

this.abortController = new AbortController();
this.abortController = new AbortController()

const nextUrl = `${this.urlValue}?page=${this.page}`;
const nextUrl = `${this.urlValue}?page=${this.page}`

fetchTurboStream(nextUrl, { signal: this.abortController.signal }, () => {
this.page += 1;
});
});
this.page += 1
})
})
}

get hasNextPage() {
return this.page <= this.totalPagesValue;
get hasNextPage () {
return this.page <= this.totalPagesValue
}
}
Loading

0 comments on commit c513ac0

Please sign in to comment.