Skip to content

Commit

Permalink
Fix beta 14 issues:
Browse files Browse the repository at this point in the history
- Loading indicator no longer working
- Scroll after upload no longer working
- Default file download click handler not running
- Download endpoint 500 error
- Settings link in admin not working
Some more changes:
- Move loading status handling to Uploader utility
- Allow Guzzle 7
  • Loading branch information
clarkwinkelmann committed Nov 26, 2020
1 parent fe8d080 commit 8048f97
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 56 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"flarum/core": ">=0.1.0-beta.14 <0.1.0-beta.16",
"ramsey/uuid": "^3.5.2",
"softcreatr/php-mime-detector": "^3.0",
"guzzlehttp/guzzle": "^6.0"
"guzzlehttp/guzzle": "^6.0 || ^7.0"
},
"replace": {
"flagrow/upload": "*"
Expand Down
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/src/admin/addUploadPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UploadPage from './components/UploadPage';

export default function () {
app.routes['fof-upload'] = {path: '/fof/upload', component: UploadPage};
app.extensionSettings['fof-upload'] = () => m.route.get(app.route('fof-upload'));
app.extensionSettings['fof-upload'] = () => m.route.set(app.route('fof-upload'));

extend(AdminNav.prototype, 'items', items => {
items.add('fof-upload', AdminLinkButton.component({
Expand Down
25 changes: 17 additions & 8 deletions js/src/forum/addUploadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ export default function () {
extend(TextEditor.prototype, 'controlItems', function (items) {
if (!app.forum.attribute('fof-upload.canUpload')) return;

let button = UploadButton.component({
upload: files => this.uploader.upload(files)
});

this.uploader.on('uploaded', () => button.success());

items.add('fof-upload', button);
items.add('fof-upload', UploadButton.component({
uploader: this.uploader
}));
});

extend(TextEditor.prototype, 'oncreate', function (f_, vnode) {
if (!app.forum.attribute('fof-upload.canUpload')) return;

this.uploader.on('success', image => this.attrs.composer.editor.insertAtCursor(image + '\n'));
this.uploader.on('success', image => {
this.attrs.composer.editor.insertAtCursor(image + '\n');

// Scroll the preview into view
// preview() causes the composer to close on mobile, but we don't want that. We want only the scroll
// We work around that by temporarily patching the isFullScreen method
const originalIsFullScreen = app.composer.isFullScreen;

app.composer.isFullScreen = () => false;

this.attrs.preview();

app.composer.isFullScreen = originalIsFullScreen;
});

const dragAndDrop = new DragAndDrop(
files => this.uploader.upload(files),
Expand Down
47 changes: 12 additions & 35 deletions js/src/forum/components/UploadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import app from 'flarum/app';
import Component from 'flarum/Component';
import icon from 'flarum/helpers/icon';
import LoadingIndicator from 'flarum/components/LoadingIndicator';
import ReplyComposer from 'flarum/components/ReplyComposer';
import EditPostComposer from 'flarum/components/EditPostComposer';
import Stream from 'flarum/utils/Stream'

export default class UploadButton extends Component {
oninit(vnode) {
super.oninit(vnode);
// initial state of the button
this.uploading = Stream(false);

this.attrs.uploader.on('uploaded', () => {
// reset the button for a new upload
this.$('form')[0].reset();

// redraw to reflect uploader.loading in the DOM
m.redraw();
});
}

view() {
const buttonText = this.uploading() ? app.translator.trans('fof-upload.forum.states.loading') : app.translator.trans('fof-upload.forum.buttons.attach');
const buttonText = this.attrs.uploader.uploading ? app.translator.trans('fof-upload.forum.states.loading') : app.translator.trans('fof-upload.forum.buttons.attach');

return m('.Button.hasIcon.fof-upload-button.Button--icon', {
className: this.uploading() ? 'uploading' : '',
className: this.attrs.uploader.uploading ? 'uploading' : '',
}, [
this.uploading() ? LoadingIndicator.component({
this.attrs.uploader.uploading ? LoadingIndicator.component({
size: 'tiny',
className: 'LoadingIndicator--inline Button-icon',
}) : icon('fas fa-file-upload', {className: 'Button-icon'}),
Expand All @@ -43,32 +46,6 @@ export default class UploadButton extends Component {
// get the file from the input field
const files = this.$('input').prop('files');

const upload = this.attrs.upload;

upload(files);
}

/**
* Appends the file's link to the body of the composer.
*/
success() {
console.log('success hit')
// Scroll the preview into view
// We don't call this.textAreaObj.props.preview() because that would close the composer on mobile
// Instead we just directly perform the same scrolling and skip the part about minimizing the composer
if (app.composer.component instanceof ReplyComposer) {
m.route.set(app.route.discussion(app.composer.component.props.discussion, 'reply'));
}

if (app.composer.component instanceof EditPostComposer) {
m.route.set(app.route.post(app.composer.component.props.post));
}

// reset the button for a new upload
setTimeout(() => {
this.$('form')[0].reset();
this.uploading(false);
m.redraw();
}, 1000);
this.attrs.uploader.upload(files);
}
}
6 changes: 2 additions & 4 deletions js/src/forum/downloadButtonInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import Post from 'flarum/components/Post';
/* global $ */

export default function () {
extend(Post.prototype, 'config', function (isInitialized) {
if (isInitialized) return;

extend(Post.prototype, 'oncreate', function () {
this.$('[data-fof-upload-download-uuid]').unbind('click').on('click', (e) => {
e.preventDefault();
e.stopPropagation();
Expand All @@ -20,7 +18,7 @@ export default function () {
let url = app.forum.attribute('apiUrl') + '/fof/download';

url += '/' + e.currentTarget.dataset.fofUploadDownloadUuid;
url += '/' + this.props.post.id();
url += '/' + this.attrs.post.id();
url += '/' + app.session.csrfToken;

window.open(url);
Expand Down

0 comments on commit 8048f97

Please sign in to comment.