Skip to content

Commit

Permalink
update npm dependencies and style/syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alcohol committed Sep 30, 2019
1 parent 794ea9b commit 5d2b590
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 138 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"devDependencies": {
"@symfony/webpack-encore": "^0.20.0",
"@symfony/webpack-encore": "^0.28.0",
"bootstrap": "^4.1.3",
"date-fns": "^1.29.0",
"date-fns": "^2.0.0",
"jquery": "^3.3.1",
"node-sass": "^4.9.4",
"popper.js": "^1.14.3",
"sass-loader": "^7.1.0"
"sass-loader": "^8.0.0"
},
"license": "MIT",
"private": true,
Expand Down
35 changes: 19 additions & 16 deletions views/assets/js/App/DateDistance.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import { formatDistanceToNow } from 'date-fns'
import { enUS } from 'date-fns/locale'

class DateDistance {
static calculate(elements) {
if (typeof elements === 'string') {
elements = document.querySelectorAll(elements);
}
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
let datetime = element.attributes.datetime.value;
let date = new Date(datetime);
let distance = distanceInWordsToNow(date, {
addSuffix: true
});

element.textContent = distance;
}
static calculate(elements) {
if (typeof elements === 'string') {
elements = document.querySelectorAll(elements)
}

for (let i = 0; i < elements.length; i++) {
let element = elements[i]
let datetime = element.attributes.datetime.value
let date = new Date(datetime)
let distance = formatDistanceToNow(date, {
addSuffix: true,
locale: enUS
})

element.textContent = distance
}
}
}

export default DateDistance;
export default DateDistance
99 changes: 49 additions & 50 deletions views/assets/js/App/PackageFilter.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
import $ from 'jquery';
import $ from 'jquery'

class PackageFilter {
constructor(input, list, listItem) {
this.input = $(input);
this.list = $(list);
this.listItemSelector = listItem;
this.packages = this.list.find(listItem);
this.inputTimeout = null;
constructor(input, list, listItem) {
this.input = $(input)
this.list = $(list)
this.listItemSelector = listItem
this.packages = this.list.find(listItem)
this.inputTimeout = null
this.readHash = this.readHash.bind(this)
this.updateHash = this.updateHash.bind(this)
this.filterPackages = this.filterPackages.bind(this)

this.readHash = this.readHash.bind(this);
this.updateHash = this.updateHash.bind(this);
this.filterPackages = this.filterPackages.bind(this);
this.init()
}

this.init();
}

readHash() {
let hash = window.decodeURIComponent(window.location.hash.substr(1));

if (hash.length > 0) {
this.input.val(hash);
this.filterPackages();
}
};
readHash() {
let hash = window.decodeURIComponent(window.location.hash.substr(1))

updateHash() {
window.location.hash = window.encodeURIComponent(this.input.val());
};
if (hash.length > 0) {
this.input.val(hash)
this.filterPackages()
}
}

filterPackages() {
var needle = this.input.val().toLowerCase(),
closestSelector = this.listItemSelector;
updateHash() {
window.location.hash = window.encodeURIComponent(this.input.val())
}

this.list.hide();
filterPackages() {
let needle = this.input.val().toLowerCase()
let closestSelector = this.listItemSelector

this.packages.each(function () {
$(this).closest(closestSelector).toggle(
$(this).text().toLowerCase().indexOf(needle) !== -1
);
});
this.list.hide()

this.list.show();
};
this.packages.each(function () {
$(this).closest(closestSelector).toggle(
$(this).text().toLowerCase().indexOf(needle) !== -1
)
})

init() {
var instance = this;
this.list.show()
}

instance.input.keyup(function () {
instance.updateHash();
window.clearTimeout(instance.inputTimeout);
instance.inputTimeout = window.setTimeout(instance.filterPackages, 350);
});
init() {
var instance = this

$(window).keyup(function (event) {
if (event.keyCode === 27) { // "ESC" keyCode
instance.input.val('');
instance.filterPackages();
}
});
instance.input.keyup(function () {
instance.updateHash()
window.clearTimeout(instance.inputTimeout)
instance.inputTimeout = window.setTimeout(instance.filterPackages, 350)
})

instance.readHash();
$(window).keyup(function (event) {
if (event.keyCode === 27) { // "ESC" keyCode
instance.input.val('')
instance.filterPackages()
}
})

instance.readHash()
}
}

export default PackageFilter;
export default PackageFilter
21 changes: 9 additions & 12 deletions views/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import $ from 'jquery';
// import 'bootstrap';
// import 'popper.js';
import 'bootstrap/js/dist/collapse';
import DateDistance from './App/DateDistance';
import PackageFilter from './App/PackageFilter';
import $ from 'jquery'
import 'bootstrap/js/dist/collapse'
import DateDistance from './App/DateDistance'
import PackageFilter from './App/PackageFilter'

function updateTimeElements () {
DateDistance.calculate('time')
DateDistance.calculate('time')
};

$(document).ready(function() {
new PackageFilter('input#search', '#package-list', '.card');

updateTimeElements();
window.setInterval(updateTimeElements, 5000);
$(function() {
new PackageFilter('input#search', '#package-list', '.card')
updateTimeElements()
window.setInterval(updateTimeElements, 5000)
});
33 changes: 23 additions & 10 deletions views/build/app.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions views/build/entrypoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"entrypoints": {
"app": {
"js": [
"/build/app.js"
]
},
"style": {
"css": [
"/build/style.css"
]
}
}
}
2 changes: 1 addition & 1 deletion views/build/style.css

Large diffs are not rendered by default.

59 changes: 13 additions & 46 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,15 @@
var Encore = require('@symfony/webpack-encore');
const Encore = require('@symfony/webpack-encore')

Encore
// directory where compiled assets will be stored
.setOutputPath('views/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
// .setManifestKeyPrefix('assets/')

/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if you JavaScript imports CSS.
*/
.addEntry('app', './views/assets/js/app.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/page2.js')
.addStyleEntry('style', './views/assets/css/style.scss')

/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
// .enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
// .enableVersioning(Encore.isProduction())

// enables Sass/SCSS support
.enableSassLoader()

// uncomment if you use TypeScript
//.enableTypeScriptLoader()

// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();
.addEntry('app', './views/assets/js/app.js')
.addStyleEntry('style', './views/assets/css/style.scss')
.cleanupOutputBeforeBuild()
.disableSingleRuntimeChunk()
.enableSassLoader()
.enableSourceMaps(!Encore.isProduction())
.setOutputPath('views/build/')
.setPublicPath('/build')

const config = Encore.getWebpackConfig()

module.exports = config

0 comments on commit 5d2b590

Please sign in to comment.