From 82bb10ae2463ab13250ef4dea5900a297db748db Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 01:05:33 +0900 Subject: [PATCH 01/17] =?UTF-8?q?SourceMap=E3=81=8C=E6=AC=B2=E3=81=97?= =?UTF-8?q?=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webpack.mix.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/webpack.mix.js b/webpack.mix.js index 6fe6635..1baf0c4 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -1,5 +1,6 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires const mix = require('laravel-mix'); -require('laravel-mix-bundle-analyzer') +require('laravel-mix-bundle-analyzer'); /* |-------------------------------------------------------------------------- @@ -22,17 +23,23 @@ mix.ts('resources/assets/js/app.ts', 'public/js') .ts('resources/assets/js/checkin.ts', 'public/js') .sass('resources/assets/sass/app.scss', 'public/css') .autoload({ - 'jquery': ['$', 'jQuery', 'window.jQuery'] + jquery: ['$', 'jQuery', 'window.jQuery'], }) .extract(['jquery', 'bootstrap']) .extract(['chart.js', 'chartjs-color', 'color-name', 'moment', 'cal-heatmap', 'd3'], 'public/js/vendor/chart') .version() - .webpackConfig(webpack => ({ + .webpackConfig((_webpack) => ({ externals: { - moment: 'moment' - } + moment: 'moment', + }, })); if (process.argv.includes('-a')) { mix.bundleAnalyzer({ analyzerMode: 'static' }); } + +if (!mix.inProduction()) { + mix.webpackConfig({ + devtool: 'source-map', + }); +} From 8f1a4d3e88a413a5ce50751d0d34a13c7da29a5b Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 01:26:11 +0900 Subject: [PATCH 02/17] =?UTF-8?q?=E3=81=93=E3=82=8C=E3=81=A7=E3=81=84?= =?UTF-8?q?=E3=81=91=E3=82=8B=E3=81=98=E3=82=83=E3=82=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webpack.mix.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/webpack.mix.js b/webpack.mix.js index 1baf0c4..3e1a6dd 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -39,7 +39,5 @@ if (process.argv.includes('-a')) { } if (!mix.inProduction()) { - mix.webpackConfig({ - devtool: 'source-map', - }); + mix.sourceMaps(); } From 87c97d27a8d7837013b95006a459327a12f841d0 Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 01:27:47 +0900 Subject: [PATCH 03/17] generateForProduction: false --- webpack.mix.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/webpack.mix.js b/webpack.mix.js index 3e1a6dd..16ed4e0 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -28,6 +28,7 @@ mix.ts('resources/assets/js/app.ts', 'public/js') .extract(['jquery', 'bootstrap']) .extract(['chart.js', 'chartjs-color', 'color-name', 'moment', 'cal-heatmap', 'd3'], 'public/js/vendor/chart') .version() + .sourceMaps(false) .webpackConfig((_webpack) => ({ externals: { moment: 'moment', @@ -37,7 +38,3 @@ mix.ts('resources/assets/js/app.ts', 'public/js') if (process.argv.includes('-a')) { mix.bundleAnalyzer({ analyzerMode: 'static' }); } - -if (!mix.inProduction()) { - mix.sourceMaps(); -} From 422891e237c12c508cc4c57ac200e49ba84572b7 Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 02:26:51 +0900 Subject: [PATCH 04/17] fetch wrapper --- package.json | 4 +- resources/assets/js/fetch.ts | 57 +++++++++++++++++++++++++++++ resources/assets/js/tissue.ts | 69 ++++++++++++++++++----------------- yarn.lock | 10 +++++ 4 files changed, 106 insertions(+), 34 deletions(-) create mode 100644 resources/assets/js/fetch.ts diff --git a/package.json b/package.json index 9f6056f..af8a402 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@types/chart.js": "^2.9.22", "@types/jquery": "^3.3.38", "@types/js-cookie": "^2.2.0", + "@types/qs": "^6.9.4", "@typescript-eslint/eslint-plugin": "^3.1.0", "@typescript-eslint/parser": "^3.1.0", "bootstrap": "^4.5.0", @@ -37,6 +38,7 @@ "open-iconic": "^1.1.1", "popper.js": "^1.14.7", "prettier": "^2.0.5", + "qs": "^6.9.4", "resolve-url-loader": "^3.1.1", "sass": "^1.26.8", "sass-loader": "^7.1.0", @@ -62,7 +64,7 @@ "stylelint --fix", "git add" ], - "*.{ts,js,vue}" : [ + "*.{ts,js,vue}": [ "eslint --fix", "git add" ], diff --git a/resources/assets/js/fetch.ts b/resources/assets/js/fetch.ts new file mode 100644 index 0000000..d683e62 --- /dev/null +++ b/resources/assets/js/fetch.ts @@ -0,0 +1,57 @@ +import { stringify } from 'qs'; + +const token = document.head.querySelector('meta[name="csrf-token"]'); +if (!token) { + console.error('CSRF token not found'); +} + +const headers = { + 'X-CSRF-TOKEN': token?.content ?? '', +}; + +type QueryParams = { [key: string]: string }; + +const joinParamsToPath = (path: string, params: QueryParams) => + Object.keys(params).length === 0 ? path : `${path}?${stringify(params)}`; + +const fetchWrapper = (path: string, options: RequestInit = {}) => + fetch(path, { + credentials: 'same-origin', + headers, + ...options, + }); + +const fetchWithJson = (path: string, body: any, options: RequestInit = {}) => + fetchWrapper(path, { + body: JSON.stringify(body), + headers: { 'Content-Type': 'application/json' }, + ...options, + }); + +const fetchWithForm = (path: string, body: any, options: RequestInit = {}) => + fetchWrapper(path, { + body: stringify(body), + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + ...options, + }); + +export const fetchGet = (path: string, params: QueryParams = {}, options: RequestInit = {}) => + fetchWrapper(joinParamsToPath(path, params), { method: 'GET', ...options }); + +export const fetchPostJson = (path: string, body: any, options: RequestInit = {}) => + fetchWithJson(path, body, { method: 'POST', ...options }); + +export const fetchPostForm = (path: string, body: any, options: RequestInit = {}) => + fetchWithForm(path, body, { method: 'POST', ...options }); + +export const fetchPutJson = (path: string, body: any, options: RequestInit = {}) => + fetchWithJson(path, body, { method: 'PUT', ...options }); + +export const fetchPutForm = (path: string, body: any, options: RequestInit = {}) => + fetchWithForm(path, body, { method: 'PUT', ...options }); + +export const fetchDeleteJson = (path: string, body: any, options: RequestInit = {}) => + fetchWithJson(path, body, { method: 'DELETE', ...options }); + +export const fetchDeleteForm = (path: string, body: any, options: RequestInit = {}) => + fetchWithForm(path, body, { method: 'DELETE', ...options }); diff --git a/resources/assets/js/tissue.ts b/resources/assets/js/tissue.ts index 1b7fe32..e059c75 100644 --- a/resources/assets/js/tissue.ts +++ b/resources/assets/js/tissue.ts @@ -1,3 +1,5 @@ +import { fetchGet } from './fetch'; + (function ($) { $.fn.linkCard = function (options) { const settings = $.extend( @@ -9,43 +11,44 @@ return this.each(function () { const $this = $(this); - $.ajax({ - url: settings.endpoint, - method: 'get', - type: 'json', - data: { - url: $this.find('a').attr('href'), - }, - }).then(function (data) { - const $metaColumn = $this.find('.col-12:last-of-type'); - const $imageColumn = $this.find('.col-12:first-of-type'); - const $title = $this.find('.card-title'); - const $desc = $this.find('.card-text'); - const $image = $imageColumn.find('img'); - if (data.title === '') { - $title.hide(); - } else { - $title.text(data.title); - } + const url = $this.find('a').attr('href'); + if (!url) { + return; + } - if (data.description === '') { - $desc.hide(); - } else { - $desc.text(data.description); - } + fetchGet(settings.endpoint, { url }) + .then((response) => response.json()) + .then((data) => { + const $metaColumn = $this.find('.col-12:last-of-type'); + const $imageColumn = $this.find('.col-12:first-of-type'); + const $title = $this.find('.card-title'); + const $desc = $this.find('.card-text'); + const $image = $imageColumn.find('img'); - if (data.image === '') { - $imageColumn.hide(); - $metaColumn.removeClass('col-md-6'); - } else { - $image.attr('src', data.image); - } + if (data.title === '') { + $title.hide(); + } else { + $title.text(data.title); + } - if (data.title !== '' || data.description !== '' || data.image !== '') { - $this.removeClass('d-none'); - } - }); + if (data.description === '') { + $desc.hide(); + } else { + $desc.text(data.description); + } + + if (data.image === '') { + $imageColumn.hide(); + $metaColumn.removeClass('col-md-6'); + } else { + $image.attr('src', data.image); + } + + if (data.title !== '' || data.description !== '' || data.image !== '') { + $this.removeClass('d-none'); + } + }); }); }; diff --git a/yarn.lock b/yarn.lock index 96ceb48..95f4a21 100644 --- a/yarn.lock +++ b/yarn.lock @@ -849,6 +849,11 @@ resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8" integrity sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw== +"@types/qs@^6.9.4": + version "6.9.4" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.4.tgz#a59e851c1ba16c0513ea123830dd639a0a15cb6a" + integrity sha512-+wYo+L6ZF6BMoEjtf8zB2esQsqdV6WsjRK/GP9WOgLPrq87PbNWgIxS76dS5uvl/QXtHGakZmwTznIfcPXcKlQ== + "@types/sizzle@*": version "2.3.2" resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47" @@ -6684,6 +6689,11 @@ qs@6.7.0: resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc" integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== +qs@^6.9.4: + version "6.9.4" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687" + integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ== + querystring-es3@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" From 126e44bcd937360e86bbf83a3c9cbe8ccd713a00 Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 09:08:37 +0900 Subject: [PATCH 05/17] =?UTF-8?q?=E4=BB=8A=E6=97=A5=E3=81=8B=E3=82=89jQuer?= =?UTF-8?q?y.ajax=E7=A6=81=E6=AD=A2=E3=81=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 4 +++- package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 315b9d6..9c54f9b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,10 +19,12 @@ module.exports = { parser: '@typescript-eslint/parser', sourceType: 'module', }, - plugins: ['prettier', 'vue', '@typescript-eslint'], + plugins: ['prettier', 'vue', '@typescript-eslint', 'jquery'], rules: { '@typescript-eslint/explicit-module-boundary-types': 0, '@typescript-eslint/no-explicit-any': 0, '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], + 'jquery/no-ajax': 2, + 'jquery/no-ajax-events': 2, }, }; diff --git a/package.json b/package.json index af8a402..ccaf01b 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "date-fns": "^1.30.1", "eslint": "^7.2.0", "eslint-config-prettier": "^6.11.0", + "eslint-plugin-jquery": "^1.5.1", "eslint-plugin-prettier": "^3.1.4", "eslint-plugin-vue": "^6.2.2", "husky": "^1.3.1", diff --git a/yarn.lock b/yarn.lock index 95f4a21..34ff6b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3035,6 +3035,11 @@ eslint-config-prettier@^6.11.0: dependencies: get-stdin "^6.0.0" +eslint-plugin-jquery@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-jquery/-/eslint-plugin-jquery-1.5.1.tgz#d6bac643acf9484ce76394e27e2b07baca06662e" + integrity sha512-L7v1eaK5t80C0lvUXPFP9MKnBOqPSKhCOYyzy4LZ0+iK+TJwN8S9gAkzzP1AOhypRIwA88HF6phQ9C7jnOpW8w== + eslint-plugin-prettier@^3.1.4: version "3.1.4" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz#168ab43154e2ea57db992a2cd097c828171f75c2" From 77620c1699f0080b39f0b67405d070524438ca09 Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 09:53:50 +0900 Subject: [PATCH 06/17] =?UTF-8?q?x-csrf-token=E3=81=8C=E9=80=81=E3=82=89?= =?UTF-8?q?=E3=82=8C=E3=81=AD=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/app.ts | 73 +++++++++++++++--------------------- resources/assets/js/fetch.ts | 40 +++++++++++++------- 2 files changed, 58 insertions(+), 55 deletions(-) diff --git a/resources/assets/js/app.ts b/resources/assets/js/app.ts index 7267f57..1196678 100644 --- a/resources/assets/js/app.ts +++ b/resources/assets/js/app.ts @@ -1,5 +1,5 @@ import * as Cookies from 'js-cookie'; -import jqXHR = JQuery.jqXHR; +import { fetchPostJson, fetchDeleteJson, ResponseError } from './fetch'; require('./bootstrap'); @@ -41,57 +41,46 @@ $(() => { const isLiked = $this.data('liked'); if (isLiked) { - const callback = (data: any) => { - $this.data('liked', false); - $this.find('.oi-heart').removeClass('text-danger'); - - const count = data.ejaculation ? data.ejaculation.likes_count : 0; - $this.find('.like-count').text(count ? count : ''); - }; - - $.ajax({ - url: '/api/likes/' + encodeURIComponent(targetId), - method: 'delete', - type: 'json', - }) - .then(callback) - .catch(function (xhr: jqXHR) { - if (xhr.status === 404) { - callback(JSON.parse(xhr.responseText)); - return; + fetchDeleteJson(`/api/likes/${encodeURIComponent(targetId)}`) + .then((response) => { + if (response.status === 200 || response.status === 404) { + return response.json(); } + throw new ResponseError(response); + }) + .then((data) => { + $this.data('liked', false); + $this.find('.oi-heart').removeClass('text-danger'); - console.error(xhr); + const count = data.ejaculation ? data.ejaculation.likes_count : 0; + $this.find('.like-count').text(count ? count : ''); + }) + .catch((e) => { + console.error(e); alert('いいねを解除できませんでした。'); }); } else { - const callback = (data: any) => { - $this.data('liked', true); - $this.find('.oi-heart').addClass('text-danger'); + fetchPostJson('/api/likes', { id: targetId }) + .then((response) => { + if (response.status === 200 || response.status === 409) { + return response.json(); + } + throw new ResponseError(response); + }) + .then((data) => { + $this.data('liked', true); + $this.find('.oi-heart').addClass('text-danger'); - const count = data.ejaculation ? data.ejaculation.likes_count : 0; - $this.find('.like-count').text(count ? count : ''); - }; - - $.ajax({ - url: '/api/likes', - method: 'post', - type: 'json', - data: { - id: targetId, - }, - }) - .then(callback) - .catch(function (xhr: jqXHR) { - if (xhr.status === 409) { - callback(JSON.parse(xhr.responseText)); - return; - } else if (xhr.status === 401) { + const count = data.ejaculation ? data.ejaculation.likes_count : 0; + $this.find('.like-count').text(count ? count : ''); + }) + .catch((e) => { + if (e instanceof ResponseError && e.response.status === 401) { alert('いいねするためにはログインしてください。'); return; } - console.error(xhr); + console.error(e); alert('いいねできませんでした。'); }); } diff --git a/resources/assets/js/fetch.ts b/resources/assets/js/fetch.ts index d683e62..128aec4 100644 --- a/resources/assets/js/fetch.ts +++ b/resources/assets/js/fetch.ts @@ -17,41 +17,55 @@ const joinParamsToPath = (path: string, params: QueryParams) => const fetchWrapper = (path: string, options: RequestInit = {}) => fetch(path, { credentials: 'same-origin', - headers, + headers: { ...headers, ...options.headers }, ...options, }); -const fetchWithJson = (path: string, body: any, options: RequestInit = {}) => +const fetchWithJson = (path: string, body?: any, options: RequestInit = {}) => fetchWrapper(path, { - body: JSON.stringify(body), - headers: { 'Content-Type': 'application/json' }, + body: body && JSON.stringify(body), + headers: { 'Content-Type': 'application/json', ...options.headers }, ...options, }); -const fetchWithForm = (path: string, body: any, options: RequestInit = {}) => +const fetchWithForm = (path: string, body?: any, options: RequestInit = {}) => fetchWrapper(path, { - body: stringify(body), - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: body && stringify(body), + headers: { 'Content-Type': 'application/x-www-form-urlencoded', ...options.headers }, ...options, }); export const fetchGet = (path: string, params: QueryParams = {}, options: RequestInit = {}) => fetchWrapper(joinParamsToPath(path, params), { method: 'GET', ...options }); -export const fetchPostJson = (path: string, body: any, options: RequestInit = {}) => +export const fetchPostJson = (path: string, body?: any, options: RequestInit = {}) => fetchWithJson(path, body, { method: 'POST', ...options }); -export const fetchPostForm = (path: string, body: any, options: RequestInit = {}) => +export const fetchPostForm = (path: string, body?: any, options: RequestInit = {}) => fetchWithForm(path, body, { method: 'POST', ...options }); -export const fetchPutJson = (path: string, body: any, options: RequestInit = {}) => +export const fetchPutJson = (path: string, body?: any, options: RequestInit = {}) => fetchWithJson(path, body, { method: 'PUT', ...options }); -export const fetchPutForm = (path: string, body: any, options: RequestInit = {}) => +export const fetchPutForm = (path: string, body?: any, options: RequestInit = {}) => fetchWithForm(path, body, { method: 'PUT', ...options }); -export const fetchDeleteJson = (path: string, body: any, options: RequestInit = {}) => +export const fetchDeleteJson = (path: string, body?: any, options: RequestInit = {}) => fetchWithJson(path, body, { method: 'DELETE', ...options }); -export const fetchDeleteForm = (path: string, body: any, options: RequestInit = {}) => +export const fetchDeleteForm = (path: string, body?: any, options: RequestInit = {}) => fetchWithForm(path, body, { method: 'DELETE', ...options }); + +export class ResponseError extends Error { + response: Response; + + constructor(response: Response, ...rest: any) { + super(...rest); + if (Error.captureStackTrace) { + Error.captureStackTrace(this, ResponseError); + } + + this.name = 'ResponseError'; + this.response = response; + } +} From 3a1ec763ea4897217192fcff16a291a028c5a566 Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 21:15:36 +0900 Subject: [PATCH 07/17] =?UTF-8?q?fetch:=20=E5=85=B1=E9=80=9Aheader?= =?UTF-8?q?=E3=81=8C=E9=80=81=E3=82=89=E3=82=8C=E3=81=A6=E3=81=AA=E3=81=8B?= =?UTF-8?q?=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/fetch.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/assets/js/fetch.ts b/resources/assets/js/fetch.ts index 128aec4..01e1431 100644 --- a/resources/assets/js/fetch.ts +++ b/resources/assets/js/fetch.ts @@ -17,22 +17,22 @@ const joinParamsToPath = (path: string, params: QueryParams) => const fetchWrapper = (path: string, options: RequestInit = {}) => fetch(path, { credentials: 'same-origin', - headers: { ...headers, ...options.headers }, ...options, + headers: { ...headers, ...options.headers }, }); const fetchWithJson = (path: string, body?: any, options: RequestInit = {}) => fetchWrapper(path, { + ...options, body: body && JSON.stringify(body), headers: { 'Content-Type': 'application/json', ...options.headers }, - ...options, }); const fetchWithForm = (path: string, body?: any, options: RequestInit = {}) => fetchWrapper(path, { + ...options, body: body && stringify(body), headers: { 'Content-Type': 'application/x-www-form-urlencoded', ...options.headers }, - ...options, }); export const fetchGet = (path: string, params: QueryParams = {}, options: RequestInit = {}) => From 7c32ab068d3c745147640e49d02e96224b6dfedf Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 21:31:53 +0900 Subject: [PATCH 08/17] =?UTF-8?q?jQuery.ajax=E3=81=AE=E6=9D=91=E3=82=92?= =?UTF-8?q?=E6=BB=85=E3=81=BC=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/checkin.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/resources/assets/js/checkin.ts b/resources/assets/js/checkin.ts index 7902965..4a1bf50 100644 --- a/resources/assets/js/checkin.ts +++ b/resources/assets/js/checkin.ts @@ -1,6 +1,7 @@ import Vue from 'vue'; import TagInput from './components/TagInput.vue'; import MetadataPreview from './components/MetadataPreview.vue'; +import { fetchGet, ResponseError } from './fetch'; export const bus = new Vue({ name: 'EventBus' }); @@ -47,19 +48,18 @@ new Vue({ fetchMetadata(url: string) { this.metadataLoadState = MetadataLoadState.Loading; - $.ajax({ - url: '/api/checkin/card', - method: 'get', - type: 'json', - data: { - url, - }, - }) + fetchGet('/api/checkin/card', { url }) + .then((response) => { + if (!response.ok) { + throw new ResponseError(response); + } + return response.json(); + }) .then((data) => { this.metadata = data; this.metadataLoadState = MetadataLoadState.Success; }) - .catch((_e) => { + .catch(() => { this.metadata = null; this.metadataLoadState = MetadataLoadState.Failed; }); From 1482c33448c37182bc2fa0fd55ed3575678fac53 Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 21:31:59 +0900 Subject: [PATCH 09/17] =?UTF-8?q?jQuery.ajax=E5=90=91=E3=81=91=E3=81=AECSR?= =?UTF-8?q?F=20Token=E8=A8=AD=E5=AE=9A=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/bootstrap.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/resources/assets/js/bootstrap.ts b/resources/assets/js/bootstrap.ts index 99d9e9b..fbfc914 100644 --- a/resources/assets/js/bootstrap.ts +++ b/resources/assets/js/bootstrap.ts @@ -1,17 +1,5 @@ // jQuery import './tissue'; -// Setup global request header -const token = document.head.querySelector('meta[name="csrf-token"]'); -if (!token) { - console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); -} else { - $.ajaxSetup({ - headers: { - 'X-CSRF-TOKEN': token.content, - }, - }); -} - // Bootstrap import 'bootstrap'; From a4fdd220ba259a3444c5fc3569454b50b4d7ddfa Mon Sep 17 00:00:00 2001 From: shibafu Date: Thu, 6 Aug 2020 01:09:25 +0900 Subject: [PATCH 10/17] =?UTF-8?q?pageSelector=E3=82=92Vanilla=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/@types/jquery-tissue.d.ts | 1 - resources/assets/js/app.ts | 3 ++- resources/assets/js/tissue.ts | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/resources/assets/js/@types/jquery-tissue.d.ts b/resources/assets/js/@types/jquery-tissue.d.ts index 3938ccb..5d49f3c 100644 --- a/resources/assets/js/@types/jquery-tissue.d.ts +++ b/resources/assets/js/@types/jquery-tissue.d.ts @@ -7,6 +7,5 @@ declare namespace JQueryTissue { interface JQuery { linkCard: (options?: JQueryTissue.LinkCardOptions) => this; - pageSelector: () => this; deleteCheckinModal: () => this; } diff --git a/resources/assets/js/app.ts b/resources/assets/js/app.ts index 1196678..6975556 100644 --- a/resources/assets/js/app.ts +++ b/resources/assets/js/app.ts @@ -1,5 +1,6 @@ import * as Cookies from 'js-cookie'; import { fetchPostJson, fetchDeleteJson, ResponseError } from './fetch'; +import { pageSelector } from './tissue'; require('./bootstrap'); @@ -20,7 +21,7 @@ $(() => { } $('[data-toggle="tooltip"]').tooltip(); $('.alert').alert(); - $('.tis-page-selector').pageSelector(); + document.querySelectorAll('.tis-page-selector').forEach(pageSelector); $('.link-card').linkCard(); const $deleteCheckinModal = $('#deleteCheckinModal').deleteCheckinModal(); diff --git a/resources/assets/js/tissue.ts b/resources/assets/js/tissue.ts index e059c75..6e12259 100644 --- a/resources/assets/js/tissue.ts +++ b/resources/assets/js/tissue.ts @@ -1,5 +1,12 @@ import { fetchGet } from './fetch'; +export function pageSelector(el: Element) { + if (!(el instanceof HTMLSelectElement)) return; + el.addEventListener('change', function () { + location.href = this.options[this.selectedIndex].dataset.href as string; + }); +} + (function ($) { $.fn.linkCard = function (options) { const settings = $.extend( @@ -52,12 +59,6 @@ import { fetchGet } from './fetch'; }); }; - $.fn.pageSelector = function () { - return this.on('change', function () { - location.href = $(this).find(':selected').data('href'); - }); - }; - $.fn.deleteCheckinModal = function () { return this.each(function () { $(this) From 65077571e7d86cede3ada3e6b1b4dec0cba383cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2020 14:24:53 +0000 Subject: [PATCH 11/17] Bump eslint from 7.2.0 to 7.6.0 (#456) --- package.json | 2 +- yarn.lock | 253 +++++++++++---------------------------------------- 2 files changed, 52 insertions(+), 203 deletions(-) diff --git a/package.json b/package.json index ccaf01b..63acde8 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "chart.js": "^2.7.1", "cross-env": "^5.2.0", "date-fns": "^1.30.1", - "eslint": "^7.2.0", + "eslint": "^7.6.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-jquery": "^1.5.1", "eslint-plugin-prettier": "^3.1.4", diff --git a/yarn.lock b/yarn.lock index 34ff6b3..e287e43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,20 +2,13 @@ # yarn lockfile v1 -"@babel/code-frame@^7.0.0": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.8.3": version "7.10.1" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.1.tgz#d5481c5095daa1c57e16e54c6f9198443afb49ff" integrity sha512-IGhtTmpjGbYzcEDOw7DcQtbQSXcG9ftmAXtWTu9V936vDye4xjjekktFAtgZsWpzTj/X01jocB46mTywm/4SZw== dependencies: "@babel/highlight" "^7.10.1" -"@babel/code-frame@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.8.3.tgz#33e25903d7481181534e12ec0a25f16b6fcf419e" - integrity sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g== - dependencies: - "@babel/highlight" "^7.8.3" - "@babel/compat-data@^7.8.0", "@babel/compat-data@^7.8.1": version "7.8.1" resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.8.1.tgz#fc0bbbb7991e4fb2b47e168e60f2cc2c41680be9" @@ -253,15 +246,6 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/highlight@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.8.3.tgz#28f173d04223eaaa59bc1d439a3836e6d1265797" - integrity sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg== - dependencies: - chalk "^2.0.0" - esutils "^2.0.2" - js-tokens "^4.0.0" - "@babel/parser@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.8.3.tgz#790874091d2001c9be6ec426c2eed47bc7679081" @@ -1118,11 +1102,16 @@ acorn@^6.0.7, acorn@^6.2.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.1.tgz#531e58ba3f51b9dacb9a6646ca4debf5b14ca474" integrity sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA== -acorn@^7.1.1, acorn@^7.2.0: +acorn@^7.1.1: version "7.2.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.2.0.tgz#17ea7e40d7c8640ff54a694c889c26f31704effe" integrity sha512-apwXVmYVpQ34m/i71vrApRrRKCWQnZZF1+npOD0WV5xZFfwWOmKGQ2RWlfdy9vWITsenisM8M0Qeq8agcFHNiQ== +acorn@^7.3.1: + version "7.4.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c" + integrity sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w== + adjust-sourcemap-loader@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/adjust-sourcemap-loader/-/adjust-sourcemap-loader-2.0.0.tgz#6471143af75ec02334b219f54bc7970c52fb29a4" @@ -1144,17 +1133,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1: resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.4.1.tgz#ef916e271c64ac12171fd8384eaae6b2345854da" integrity sha512-RO1ibKvd27e6FEShVFfPALuHI3WjSVNeK5FIsmme/LYRNxjKuNj+Dt7bucLa6NdSv3JcVTyMlm9kGR84z1XpaQ== -ajv@^6.1.0, ajv@^6.10.2: - version "6.11.0" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.11.0.tgz#c3607cbc8ae392d8a5a536f25b21f8e5f3f87fe9" - integrity sha512-nCprB/0syFYy9fVYU1ox1l2KN8S9I+tziH8D4zdZuLT3N6RMlGSGt5FSTpAiHB/Whv8Qs1cWHma1aMKZyaHRKA== - dependencies: - fast-deep-equal "^3.1.1" - fast-json-stable-stringify "^2.0.0" - json-schema-traverse "^0.4.1" - uri-js "^4.2.2" - -ajv@^6.10.0: +ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2: version "6.12.2" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd" integrity sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ== @@ -1174,18 +1153,16 @@ ansi-colors@^3.0.0: resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf" integrity sha512-hHUXGagefjN2iRrID63xckIvotOXOojhQKWIPUZ4mNUZ9nLZW+7FMNoE1lOkEhNWYsx/7ysGIuJYCiMAA9FnrA== +ansi-colors@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" + integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + ansi-escapes@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ== -ansi-escapes@^4.2.1: - version "4.3.1" - resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.1.tgz#a5c47cc43181f1f38ffd7076837700d395522a61" - integrity sha512-JWF7ocqNrp8u9oqpgV+wH5ftbt+cfvv+PTjOvKLT3AdYly/LmORARfEVT1iyjwN+4MqE5UmVKoAdIBqeoCHgLA== - dependencies: - type-fest "^0.11.0" - ansi-html@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.7.tgz#813584021962a9e9e6fd039f940d12f56ca7859e" @@ -1830,14 +1807,6 @@ chalk@^1.0.0, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4" - integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg== - dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" - chalk@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.0.0.tgz#6e98081ed2d17faab615eb52ac66ec1fe6209e72" @@ -1866,11 +1835,6 @@ character-reference-invalid@^1.0.0: resolved "https://registry.yarnpkg.com/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz#083329cda0eae272ab3dbbf37e9a382c13af1560" integrity sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg== -chardet@^0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" - integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== - charenc@~0.0.1: version "0.0.2" resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" @@ -1987,13 +1951,6 @@ cli-cursor@^2.0.0, cli-cursor@^2.1.0: dependencies: restore-cursor "^2.0.0" -cli-cursor@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307" - integrity sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw== - dependencies: - restore-cursor "^3.1.0" - cli-truncate@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/cli-truncate/-/cli-truncate-0.2.1.tgz#9f15cfbb0705005369216c626ac7d05ab90dd574" @@ -2002,11 +1959,6 @@ cli-truncate@^0.2.1: slice-ansi "0.0.4" string-width "^1.0.1" -cli-width@^2.0.0: - version "2.2.1" - resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.1.tgz#b0433d0b4e9c847ef18868a4ef16fd5fc8271c48" - integrity sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw== - cliui@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-4.1.0.tgz#348422dbe82d800b3022eef4f6ac10bf2e4d1b49" @@ -2887,11 +2839,6 @@ emoji-regex@^7.0.1: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== -emoji-regex@^8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" - integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== - emojis-list@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" @@ -2927,6 +2874,13 @@ enhanced-resolve@^4.0.0, enhanced-resolve@^4.1.0: memory-fs "^0.5.0" tapable "^1.0.0" +enquirer@^2.3.5: + version "2.3.6" + resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d" + integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== + dependencies: + ansi-colors "^4.1.1" + entities@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56" @@ -3072,22 +3026,22 @@ eslint-scope@^5.0.0, eslint-scope@^5.1.0: esrecurse "^4.1.0" estraverse "^4.1.1" -eslint-utils@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.0.0.tgz#7be1cc70f27a72a76cd14aa698bcabed6890e1cd" - integrity sha512-0HCPuJv+7Wv1bACm8y5/ECVfYdfsAm9xmVb7saeFlxjPYALefjhbYoCkBjPdPzGH8wWyTpAez82Fh3VKYEZ8OA== +eslint-utils@^2.0.0, eslint-utils@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27" + integrity sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg== dependencies: eslint-visitor-keys "^1.1.0" -eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa" - integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ== +eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" + integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== -eslint@^7.2.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.2.0.tgz#d41b2e47804b30dbabb093a967fb283d560082e6" - integrity sha512-B3BtEyaDKC5MlfDa2Ha8/D6DsS4fju95zs0hjS3HdGazw+LNayai38A25qMppK37wWGWNYSPOR6oYzlz5MHsRQ== +eslint@^7.6.0: + version "7.6.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.6.0.tgz#522d67cfaea09724d96949c70e7a0550614d64d6" + integrity sha512-QlAManNtqr7sozWm5TF4wIH9gmUm2hE3vNRUvyoYAa4y1l5/jxD/PQStEjBMQtCqZmSep8UxrcecI60hOpe61w== dependencies: "@babel/code-frame" "^7.0.0" ajv "^6.10.0" @@ -3095,10 +3049,11 @@ eslint@^7.2.0: cross-spawn "^7.0.2" debug "^4.0.1" doctrine "^3.0.0" + enquirer "^2.3.5" eslint-scope "^5.1.0" - eslint-utils "^2.0.0" - eslint-visitor-keys "^1.2.0" - espree "^7.1.0" + eslint-utils "^2.1.0" + eslint-visitor-keys "^1.3.0" + espree "^7.2.0" esquery "^1.2.0" esutils "^2.0.2" file-entry-cache "^5.0.1" @@ -3108,12 +3063,11 @@ eslint@^7.2.0: ignore "^4.0.6" import-fresh "^3.0.0" imurmurhash "^0.1.4" - inquirer "^7.0.0" is-glob "^4.0.0" js-yaml "^3.13.1" json-stable-stringify-without-jsonify "^1.0.1" levn "^0.4.1" - lodash "^4.17.14" + lodash "^4.17.19" minimatch "^3.0.4" natural-compare "^1.4.0" optionator "^0.9.1" @@ -3135,14 +3089,14 @@ espree@^6.2.1: acorn-jsx "^5.2.0" eslint-visitor-keys "^1.1.0" -espree@^7.1.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/espree/-/espree-7.1.0.tgz#a9c7f18a752056735bf1ba14cb1b70adc3a5ce1c" - integrity sha512-dcorZSyfmm4WTuTnE5Y7MEN1DyoPYy1ZR783QW1FJoenn7RailyWFsq/UL6ZAAA7uXurN9FIpYyUs3OfiIW+Qw== +espree@^7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/espree/-/espree-7.2.0.tgz#1c263d5b513dbad0ac30c4991b93ac354e948d69" + integrity sha512-H+cQ3+3JYRMEIOl87e7QdHX70ocly5iW4+dttuR8iYSPr/hXKFb+7dBsZ7+u1adC4VrnPlTkv0+OwuPnDop19g== dependencies: - acorn "^7.2.0" + acorn "^7.3.1" acorn-jsx "^5.2.0" - eslint-visitor-keys "^1.2.0" + eslint-visitor-keys "^1.3.0" esprima@^4.0.0: version "4.0.1" @@ -3316,15 +3270,6 @@ extend@^3.0.0: resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== -external-editor@^3.0.3: - version "3.1.0" - resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495" - integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== - dependencies: - chardet "^0.7.0" - iconv-lite "^0.4.24" - tmp "^0.0.33" - extglob@^2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/extglob/-/extglob-2.0.4.tgz#ad00fe4dc612a9232e8718711dc5cb5ab0285543" @@ -3420,13 +3365,6 @@ figures@^2.0.0: dependencies: escape-string-regexp "^1.0.5" -figures@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af" - integrity sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg== - dependencies: - escape-string-regexp "^1.0.5" - file-entry-cache@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-4.0.0.tgz#633567d15364aefe0b299e1e217735e8f3a9f6e8" @@ -3701,20 +3639,13 @@ glob-parent@^3.1.0: is-glob "^3.1.0" path-dirname "^1.0.0" -glob-parent@^5.0.0: +glob-parent@^5.0.0, glob-parent@~5.1.0: version "5.1.1" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229" integrity sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ== dependencies: is-glob "^4.0.1" -glob-parent@~5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.0.tgz#5f4c1d1e748d30cd73ad2944b3577a81b081e8c2" - integrity sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw== - dependencies: - is-glob "^4.0.1" - glob-to-regexp@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" @@ -4130,7 +4061,7 @@ husky@^1.3.1: run-node "^1.0.0" slash "^2.0.0" -iconv-lite@0.4.24, iconv-lite@^0.4.24: +iconv-lite@0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== @@ -4284,25 +4215,6 @@ ini@^1.3.4, ini@^1.3.5: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== -inquirer@^7.0.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.1.0.tgz#1298a01859883e17c7264b82870ae1034f92dd29" - integrity sha512-5fJMWEmikSYu0nv/flMc475MhGbB7TSPd/2IpFV4I4rMklboCH2rQjYY5kKiYGHqUF9gvaambupcJFFG9dvReg== - dependencies: - ansi-escapes "^4.2.1" - chalk "^3.0.0" - cli-cursor "^3.1.0" - cli-width "^2.0.0" - external-editor "^3.0.3" - figures "^3.0.0" - lodash "^4.17.15" - mute-stream "0.0.8" - run-async "^2.4.0" - rxjs "^6.5.3" - string-width "^4.1.0" - strip-ansi "^6.0.0" - through "^2.3.6" - internal-ip@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/internal-ip/-/internal-ip-4.3.0.tgz#845452baad9d2ca3b69c635a137acb9a0dad0907" @@ -4529,11 +4441,6 @@ is-fullwidth-code-point@^2.0.0: resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= -is-fullwidth-code-point@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" - integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== - is-glob@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a" @@ -5043,10 +4950,10 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.17.5: - version "4.17.15" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" - integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== +lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.17.5: + version "4.17.19" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" + integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== log-symbols@^1.0.2: version "1.0.2" @@ -5346,7 +5253,7 @@ mimic-fn@^1.0.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== -mimic-fn@^2.0.0, mimic-fn@^2.1.0: +mimic-fn@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== @@ -5467,11 +5374,6 @@ multicast-dns@^6.0.1: dns-packet "^1.3.1" thunky "^1.0.2" -mute-stream@0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" - integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== - nan@^2.12.1: version "2.14.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" @@ -5769,13 +5671,6 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" -onetime@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.0.tgz#fff0f3c91617fe62bb50189636e99ac8a6df7be5" - integrity sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q== - dependencies: - mimic-fn "^2.1.0" - open-iconic@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/open-iconic/-/open-iconic-1.1.1.tgz#9dcfc8c7cd3c61cdb4a236b1a347894c97adc0c6" @@ -5834,11 +5729,6 @@ os-locale@^3.0.0, os-locale@^3.1.0: lcid "^2.0.0" mem "^4.0.0" -os-tmpdir@~1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" - integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= - p-defer@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c" @@ -7082,14 +6972,6 @@ restore-cursor@^2.0.0: onetime "^2.0.0" signal-exit "^3.0.2" -restore-cursor@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e" - integrity sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA== - dependencies: - onetime "^5.1.0" - signal-exit "^3.0.2" - ret@~0.1.10: version "0.1.15" resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" @@ -7145,11 +7027,6 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^3.0.0" inherits "^2.0.1" -run-async@^2.4.0: - version "2.4.1" - resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" - integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ== - run-node@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/run-node/-/run-node-1.0.0.tgz#46b50b946a2aa2d4947ae1d886e9856fd9cabe5e" @@ -7169,13 +7046,6 @@ rxjs@^6.3.3: dependencies: tslib "^1.9.0" -rxjs@^6.5.3: - version "6.5.5" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec" - integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ== - dependencies: - tslib "^1.9.0" - safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" @@ -7697,15 +7567,6 @@ string-width@^3.0.0, string-width@^3.1.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" -string-width@^4.1.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.0.tgz#952182c46cc7b2c313d1596e623992bd163b72b5" - integrity sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.0" - string.prototype.trimleft@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/string.prototype.trimleft/-/string.prototype.trimleft-2.1.1.tgz#9bdb8ac6abd6d602b17a4ed321870d2f8dcefc74" @@ -8022,7 +7883,7 @@ through2@^2.0.0: readable-stream "~2.3.6" xtend "~4.0.1" -through@^2.3.6, through@~2.3.6: +through@~2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= @@ -8044,13 +7905,6 @@ timsort@^0.3.0: resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4" integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q= -tmp@^0.0.33: - version "0.0.33" - resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" - integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== - dependencies: - os-tmpdir "~1.0.2" - to-arraybuffer@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43" @@ -8168,11 +8022,6 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" -type-fest@^0.11.0: - version "0.11.0" - resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.11.0.tgz#97abf0872310fed88a5c466b25681576145e33f1" - integrity sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ== - type-fest@^0.8.1: version "0.8.1" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" From 8a0a29feefc6114008a3b951215d720210746054 Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 7 Aug 2020 00:25:43 +0900 Subject: [PATCH 12/17] =?UTF-8?q?linkCard=E3=82=92Vanilla=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/@types/jquery-tissue.d.ts | 6 -- resources/assets/js/app.ts | 4 +- resources/assets/js/tissue.ts | 98 +++++++++---------- 3 files changed, 49 insertions(+), 59 deletions(-) diff --git a/resources/assets/js/@types/jquery-tissue.d.ts b/resources/assets/js/@types/jquery-tissue.d.ts index 5d49f3c..0494a7b 100644 --- a/resources/assets/js/@types/jquery-tissue.d.ts +++ b/resources/assets/js/@types/jquery-tissue.d.ts @@ -1,11 +1,5 @@ // tissue.ts で定義されているjQuery Pluginの型定義 -declare namespace JQueryTissue { - interface LinkCardOptions { - endpoint: string; - } -} interface JQuery { - linkCard: (options?: JQueryTissue.LinkCardOptions) => this; deleteCheckinModal: () => this; } diff --git a/resources/assets/js/app.ts b/resources/assets/js/app.ts index 6975556..fda7cbf 100644 --- a/resources/assets/js/app.ts +++ b/resources/assets/js/app.ts @@ -1,6 +1,6 @@ import * as Cookies from 'js-cookie'; import { fetchPostJson, fetchDeleteJson, ResponseError } from './fetch'; -import { pageSelector } from './tissue'; +import { linkCard, pageSelector } from './tissue'; require('./bootstrap'); @@ -23,7 +23,7 @@ $(() => { $('.alert').alert(); document.querySelectorAll('.tis-page-selector').forEach(pageSelector); - $('.link-card').linkCard(); + document.querySelectorAll('.link-card').forEach(linkCard); const $deleteCheckinModal = $('#deleteCheckinModal').deleteCheckinModal(); $(document).on('click', '[data-target="#deleteCheckinModal"]', function (event) { event.preventDefault(); diff --git a/resources/assets/js/tissue.ts b/resources/assets/js/tissue.ts index 6e12259..0e0b945 100644 --- a/resources/assets/js/tissue.ts +++ b/resources/assets/js/tissue.ts @@ -1,5 +1,52 @@ import { fetchGet } from './fetch'; +function suicide(e: T) { + return function (): never { + throw e; + }; +} + +export function linkCard(el: Element) { + const url = el.querySelector('a')?.href; + if (!url) { + return; + } + + fetchGet('/api/checkin/card', { url }) + .then((response) => response.json()) + .then((data) => { + const die = suicide('Element not found!'); + const metaColumn = el.querySelector('.col-12:last-of-type') || die(); + const imageColumn = el.querySelector('.col-12:first-of-type') || die(); + const title = el.querySelector('.card-title') || die(); + const desc = el.querySelector('.card-text') || die(); + const image = imageColumn.querySelector('img') || die(); + + if (data.title === '') { + title.style.display = 'none'; + } else { + title.textContent = data.title; + } + + if (data.description === '') { + desc.style.display = 'none'; + } else { + desc.textContent = data.description; + } + + if (data.image === '') { + imageColumn.style.display = 'none'; + metaColumn.classList.remove('col-md-6'); + } else { + image.src = data.image; + } + + if (data.title !== '' || data.description !== '' || data.image !== '') { + el.classList.remove('d-none'); + } + }); +} + export function pageSelector(el: Element) { if (!(el instanceof HTMLSelectElement)) return; el.addEventListener('change', function () { @@ -8,57 +55,6 @@ export function pageSelector(el: Element) { } (function ($) { - $.fn.linkCard = function (options) { - const settings = $.extend( - { - endpoint: '/api/checkin/card', - }, - options - ); - - return this.each(function () { - const $this = $(this); - - const url = $this.find('a').attr('href'); - if (!url) { - return; - } - - fetchGet(settings.endpoint, { url }) - .then((response) => response.json()) - .then((data) => { - const $metaColumn = $this.find('.col-12:last-of-type'); - const $imageColumn = $this.find('.col-12:first-of-type'); - const $title = $this.find('.card-title'); - const $desc = $this.find('.card-text'); - const $image = $imageColumn.find('img'); - - if (data.title === '') { - $title.hide(); - } else { - $title.text(data.title); - } - - if (data.description === '') { - $desc.hide(); - } else { - $desc.text(data.description); - } - - if (data.image === '') { - $imageColumn.hide(); - $metaColumn.removeClass('col-md-6'); - } else { - $image.attr('src', data.image); - } - - if (data.title !== '' || data.description !== '' || data.image !== '') { - $this.removeClass('d-none'); - } - }); - }); - }; - $.fn.deleteCheckinModal = function () { return this.each(function () { $(this) From 23189b76e40158f18371be30f071e8922a8015e4 Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 7 Aug 2020 00:53:36 +0900 Subject: [PATCH 13/17] =?UTF-8?q?deleteCheckinModal=E3=82=92Vanilla?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/@types/jquery-tissue.d.ts | 5 -- resources/assets/js/app.ts | 16 +++--- resources/assets/js/bootstrap.ts | 3 -- resources/assets/js/tissue.ts | 53 ++++++++++--------- 4 files changed, 37 insertions(+), 40 deletions(-) delete mode 100644 resources/assets/js/@types/jquery-tissue.d.ts diff --git a/resources/assets/js/@types/jquery-tissue.d.ts b/resources/assets/js/@types/jquery-tissue.d.ts deleted file mode 100644 index 0494a7b..0000000 --- a/resources/assets/js/@types/jquery-tissue.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -// tissue.ts で定義されているjQuery Pluginの型定義 - -interface JQuery { - deleteCheckinModal: () => this; -} diff --git a/resources/assets/js/app.ts b/resources/assets/js/app.ts index fda7cbf..10fdc70 100644 --- a/resources/assets/js/app.ts +++ b/resources/assets/js/app.ts @@ -1,6 +1,6 @@ import * as Cookies from 'js-cookie'; import { fetchPostJson, fetchDeleteJson, ResponseError } from './fetch'; -import { linkCard, pageSelector } from './tissue'; +import { linkCard, pageSelector, deleteCheckinModal } from './tissue'; require('./bootstrap'); @@ -24,11 +24,15 @@ $(() => { document.querySelectorAll('.tis-page-selector').forEach(pageSelector); document.querySelectorAll('.link-card').forEach(linkCard); - const $deleteCheckinModal = $('#deleteCheckinModal').deleteCheckinModal(); - $(document).on('click', '[data-target="#deleteCheckinModal"]', function (event) { - event.preventDefault(); - $deleteCheckinModal.modal('show', this); - }); + + const elDeleteCheckinModal = document.getElementById('deleteCheckinModal'); + if (elDeleteCheckinModal) { + const $deleteCheckinModal = deleteCheckinModal(elDeleteCheckinModal); + $(document).on('click', '[data-target="#deleteCheckinModal"]', function (event) { + event.preventDefault(); + $deleteCheckinModal.modal('show', this); + }); + } $(document).on('click', '[data-href]', function (_event) { location.href = $(this).data('href'); diff --git a/resources/assets/js/bootstrap.ts b/resources/assets/js/bootstrap.ts index fbfc914..02b71c6 100644 --- a/resources/assets/js/bootstrap.ts +++ b/resources/assets/js/bootstrap.ts @@ -1,5 +1,2 @@ -// jQuery -import './tissue'; - // Bootstrap import 'bootstrap'; diff --git a/resources/assets/js/tissue.ts b/resources/assets/js/tissue.ts index 0e0b945..ae2ddcb 100644 --- a/resources/assets/js/tissue.ts +++ b/resources/assets/js/tissue.ts @@ -1,6 +1,6 @@ import { fetchGet } from './fetch'; -function suicide(e: T) { +export function suicide(e: T) { return function (): never { throw e; }; @@ -45,33 +45,34 @@ export function linkCard(el: Element) { el.classList.remove('d-none'); } }); + + return el; } export function pageSelector(el: Element) { - if (!(el instanceof HTMLSelectElement)) return; - el.addEventListener('change', function () { - location.href = this.options[this.selectedIndex].dataset.href as string; - }); + if (el instanceof HTMLSelectElement) { + el.addEventListener('change', function () { + location.href = this.options[this.selectedIndex].dataset.href as string; + }); + } + return el; } -(function ($) { - $.fn.deleteCheckinModal = function () { - return this.each(function () { - $(this) - .on('show.bs.modal', function (event) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const target = $(event.relatedTarget!); - const modal = $(this); - modal.find('.modal-body .date-label').text(target.data('date')); - modal.data('id', target.data('id')); - }) - .find('.btn-danger') - .on('click', function (_event) { - const modal = $('#deleteCheckinModal'); - const form = modal.find('form'); - form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null); - form.submit(); - }); - }); - }; -})(jQuery); +export function deleteCheckinModal(el: Element) { + return $(el) + .on('show.bs.modal', function (event) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const target = $(event.relatedTarget!); + const modal = $(this); + modal.find('.modal-body .date-label').text(target.data('date')); + modal.data('id', target.data('id')); + }) + .find('.btn-danger') + .on('click', function (_event) { + const modal = $('#deleteCheckinModal'); + const form = modal.find('form'); + form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null); + form.submit(); + }) + .end(); +} From 723587b0acc49c4638df4a049903f789de205805 Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 7 Aug 2020 09:50:01 +0900 Subject: [PATCH 14/17] =?UTF-8?q?deleteCheckinModal=E3=81=AE=E4=B8=AD?= =?UTF-8?q?=E8=BA=AB=E3=81=A7=E3=81=AA=E3=82=8B=E3=81=B9=E3=81=8FjQuery?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=82=8F=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/tissue.ts | 31 +++++++++------------- resources/views/ejaculation/show.blade.php | 12 ++++----- resources/views/user/profile.blade.php | 12 ++++----- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/resources/assets/js/tissue.ts b/resources/assets/js/tissue.ts index ae2ddcb..804ef4d 100644 --- a/resources/assets/js/tissue.ts +++ b/resources/assets/js/tissue.ts @@ -6,6 +6,8 @@ export function suicide(e: T) { }; } +const die = suicide('Element not found!'); + export function linkCard(el: Element) { const url = el.querySelector('a')?.href; if (!url) { @@ -15,7 +17,6 @@ export function linkCard(el: Element) { fetchGet('/api/checkin/card', { url }) .then((response) => response.json()) .then((data) => { - const die = suicide('Element not found!'); const metaColumn = el.querySelector('.col-12:last-of-type') || die(); const imageColumn = el.querySelector('.col-12:first-of-type') || die(); const title = el.querySelector('.card-title') || die(); @@ -58,21 +59,15 @@ export function pageSelector(el: Element) { return el; } -export function deleteCheckinModal(el: Element) { - return $(el) - .on('show.bs.modal', function (event) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const target = $(event.relatedTarget!); - const modal = $(this); - modal.find('.modal-body .date-label').text(target.data('date')); - modal.data('id', target.data('id')); - }) - .find('.btn-danger') - .on('click', function (_event) { - const modal = $('#deleteCheckinModal'); - const form = modal.find('form'); - form.attr('action', form.attr('action')?.replace('@', modal.data('id')) || null); - form.submit(); - }) - .end(); +export function deleteCheckinModal(modal: Element) { + let id: any = null; + modal.querySelector('form')?.addEventListener('submit', function () { + this.action = this.action.replace('@', id); + }); + return $(modal).on('show.bs.modal', function (event) { + const target = event.relatedTarget || die(); + const dateLabel = this.querySelector('.modal-body .date-label') || die(); + dateLabel.textContent = target.dataset.date || null; + id = target.dataset.id; + }); } diff --git a/resources/views/ejaculation/show.blade.php b/resources/views/ejaculation/show.blade.php index 5dea347..4f9db40 100644 --- a/resources/views/ejaculation/show.blade.php +++ b/resources/views/ejaculation/show.blade.php @@ -97,13 +97,13 @@ 削除確認 @endslot のチェックインを削除してもよろしいですか? -
- {{ csrf_field() }} - {{ method_field('DELETE') }} -
@slot('footer') - - +
+ {{ csrf_field() }} + {{ method_field('DELETE') }} + + +
@endslot @endcomponent @endsection diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index d850e6a..d7c39d7 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -117,13 +117,13 @@ 削除確認 @endslot のチェックインを削除してもよろしいですか? -
- {{ csrf_field() }} - {{ method_field('DELETE') }} -
@slot('footer') - - +
+ {{ csrf_field() }} + {{ method_field('DELETE') }} + + +
@endslot @endcomponent @endsection From 7aa11275cc135c43e2339dba96ce4318dff9c81c Mon Sep 17 00:00:00 2001 From: shibafu Date: Sat, 8 Aug 2020 18:32:32 +0900 Subject: [PATCH 15/17] =?UTF-8?q?OGPResolver:=20=E3=83=AA=E3=83=80?= =?UTF-8?q?=E3=82=A4=E3=83=AC=E3=82=AF=E3=83=88=E6=99=82=E3=81=ABCookie?= =?UTF-8?q?=E3=82=92=E7=B6=AD=E6=8C=81=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/OGPResolver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/MetadataResolver/OGPResolver.php b/app/MetadataResolver/OGPResolver.php index a1cf603..9bd0bb3 100644 --- a/app/MetadataResolver/OGPResolver.php +++ b/app/MetadataResolver/OGPResolver.php @@ -3,6 +3,8 @@ namespace App\MetadataResolver; use GuzzleHttp\Client; +use GuzzleHttp\Cookie\CookieJar; +use GuzzleHttp\RequestOptions; class OGPResolver implements Resolver, Parser { @@ -18,7 +20,7 @@ class OGPResolver implements Resolver, Parser public function resolve(string $url): Metadata { - return $this->parse($this->client->get($url)->getBody()); + return $this->parse($this->client->get($url, [RequestOptions::COOKIES => new CookieJar()])->getBody()); } public function parse(string $html): Metadata From b99930e1452fa26eb39f0b70cce5d518fad38cf5 Mon Sep 17 00:00:00 2001 From: shibafu Date: Mon, 10 Aug 2020 00:10:06 +0900 Subject: [PATCH 16/17] =?UTF-8?q?EjaculationController=E3=81=A7=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=83=B3=E3=82=B6=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/EjaculationController.php | 90 ++++++++++--------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/app/Http/Controllers/EjaculationController.php b/app/Http/Controllers/EjaculationController.php index bd8d70c..8446c96 100644 --- a/app/Http/Controllers/EjaculationController.php +++ b/app/Http/Controllers/EjaculationController.php @@ -9,6 +9,7 @@ use App\User; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; use Validator; class EjaculationController extends Controller @@ -52,29 +53,33 @@ class EjaculationController extends Controller return redirect()->route('checkin')->withErrors($validator)->withInput(); } - $ejaculation = Ejaculation::create([ - 'user_id' => Auth::id(), - 'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']), - 'note' => $inputs['note'] ?? '', - 'link' => $inputs['link'] ?? '', - 'source' => Ejaculation::SOURCE_WEB, - 'is_private' => $request->has('is_private') ?? false, - 'is_too_sensitive' => $request->has('is_too_sensitive') ?? false - ]); + $ejaculation = DB::transaction(function () use ($request, $inputs) { + $ejaculation = Ejaculation::create([ + 'user_id' => Auth::id(), + 'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']), + 'note' => $inputs['note'] ?? '', + 'link' => $inputs['link'] ?? '', + 'source' => Ejaculation::SOURCE_WEB, + 'is_private' => $request->has('is_private') ?? false, + 'is_too_sensitive' => $request->has('is_too_sensitive') ?? false + ]); - $tagIds = []; - if (!empty($inputs['tags'])) { - $tags = explode(' ', $inputs['tags']); - foreach ($tags as $tag) { - if ($tag === '') { - continue; + $tagIds = []; + if (!empty($inputs['tags'])) { + $tags = explode(' ', $inputs['tags']); + foreach ($tags as $tag) { + if ($tag === '') { + continue; + } + + $tag = Tag::firstOrCreate(['name' => $tag]); + $tagIds[] = $tag->id; } - - $tag = Tag::firstOrCreate(['name' => $tag]); - $tagIds[] = $tag->id; } - } - $ejaculation->tags()->sync($tagIds); + $ejaculation->tags()->sync($tagIds); + + return $ejaculation; + }); if (!empty($ejaculation->link)) { event(new LinkDiscovered($ejaculation->link)); @@ -144,27 +149,29 @@ class EjaculationController extends Controller return redirect()->route('checkin.edit', ['id' => $id])->withErrors($validator)->withInput(); } - $ejaculation->fill([ - 'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']), - 'note' => $inputs['note'] ?? '', - 'link' => $inputs['link'] ?? '', - 'is_private' => $request->has('is_private') ?? false, - 'is_too_sensitive' => $request->has('is_too_sensitive') ?? false - ])->save(); + DB::transaction(function () use ($ejaculation, $request, $inputs) { + $ejaculation->fill([ + 'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']), + 'note' => $inputs['note'] ?? '', + 'link' => $inputs['link'] ?? '', + 'is_private' => $request->has('is_private') ?? false, + 'is_too_sensitive' => $request->has('is_too_sensitive') ?? false + ])->save(); - $tagIds = []; - if (!empty($inputs['tags'])) { - $tags = explode(' ', $inputs['tags']); - foreach ($tags as $tag) { - if ($tag === '') { - continue; + $tagIds = []; + if (!empty($inputs['tags'])) { + $tags = explode(' ', $inputs['tags']); + foreach ($tags as $tag) { + if ($tag === '') { + continue; + } + + $tag = Tag::firstOrCreate(['name' => $tag]); + $tagIds[] = $tag->id; } - - $tag = Tag::firstOrCreate(['name' => $tag]); - $tagIds[] = $tag->id; } - } - $ejaculation->tags()->sync($tagIds); + $ejaculation->tags()->sync($tagIds); + }); if (!empty($ejaculation->link)) { event(new LinkDiscovered($ejaculation->link)); @@ -180,8 +187,11 @@ class EjaculationController extends Controller $this->authorize('edit', $ejaculation); $user = User::findOrFail($ejaculation->user_id); - $ejaculation->tags()->detach(); - $ejaculation->delete(); + + DB::transaction(function () use ($ejaculation) { + $ejaculation->tags()->detach(); + $ejaculation->delete(); + }); return redirect()->route('user.profile', ['name' => $user->name])->with('status', '削除しました。'); } From 04d546b1f02374a16afb2f4d55ac46cb4154d75e Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 16 Aug 2020 14:38:35 +0900 Subject: [PATCH 17/17] =?UTF-8?q?Twitter=E3=81=AE=E3=82=B5=E3=83=96?= =?UTF-8?q?=E3=83=89=E3=83=A1=E3=82=A4=E3=83=B3=E5=AF=BE=E5=BF=9C=E7=94=A8?= =?UTF-8?q?Resolver=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/MetadataResolver.php | 1 + app/MetadataResolver/TwitterResolver.php | 33 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 app/MetadataResolver/TwitterResolver.php diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index 8470275..6ab663d 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -34,6 +34,7 @@ class MetadataResolver implements Resolver '~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class, '~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class, '~www\.hentai-foundry\.com/pictures/user/.+/\d+/.+~'=> HentaiFoundryResolver::class, + '~(www\.)?((mobile|m)\.)?twitter\.com/(#!/)?[0-9a-zA-Z_]{1,15}/status(es)?/([0-9]+)/?(\\?.+)?$~' => TwitterResolver::class, ]; public $mimeTypes = [ diff --git a/app/MetadataResolver/TwitterResolver.php b/app/MetadataResolver/TwitterResolver.php new file mode 100644 index 0000000..adfb5d3 --- /dev/null +++ b/app/MetadataResolver/TwitterResolver.php @@ -0,0 +1,33 @@ +client = $client; + $this->ogpResolver = $ogpResolver; + } + + public function resolve(string $url): Metadata + { + $url = preg_replace('/(www\.)?(mobile|m)\.twitter\.com/u', 'twitter.com', $url); + + $res = $this->client->get($url); + $html = (string) $res->getBody(); + + return $this->ogpResolver->parse($html); + } +}