Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented user media manager #262

Merged
merged 8 commits into from Mar 13, 2021

Conversation

jaspervriends
Copy link
Contributor

I've implemented a user media upload manager with the idea of stopping multi-uploads from the same file. The files were already attached to the user, so I did not change anything of that.

Changelog:

  • Added responsive media manager
  • Simplified upload button in the composer
  • Added media manager button to the composer
  • Added /fof/uploads endpoint
  • Updated /fof/upload endpoint output
  • Updated FileSerializer
  • Added File frontend model

Modal features:
The media manager is expandable minded. Other extensions could open the FileManagerModal modal component and attach custom params to customize their needs.

The file manager is responsive, has drag & drop support and automatically selects the uploaded files. After clicking the 'Select files' button, the files will be added with their bbcode to the composer.

  • onSelect: Optional, custom callback, default: adds bbcode to composer
  • multiSelect: Optional, allow multiple selections, default true
  • restrictFileType: Optional, restrict file selection to specific types, default null, supported values:
    • [array]
    • image
    • audio
    • video

This PR
Let's focus on the code and improvements/removals:

Updated composer buttons

image

Automatically select uploaded files

image

Example: Restricted to file type image

image

Night mode

image

Mobile view

image

- Added responsive media manager
- Added /fof/uploads endpoint
- Updated /fof/upload endpoint output
- Updated FileSerializer
- Added File frontend model
@imorland
Copy link
Member

This really is great work @jaspervriends thank you for your time in creating this feature! Might take a couple of days to go over this, please bear with us :)

@clarkwinkelmann
Copy link
Member

This looks very nice! I probably also won't be able to review immediately, but I will try to get to it!

How are the image preview managed? Is it the full image? If so, does it load all of the images immediately or only as you scroll down? If a forum allows very large uploads, or someone just has many images, will it not bring the website down by loading all of them?

@jaspervriends
Copy link
Contributor Author

Awesome, take your time :)

This looks very nice! I probably also won't be able to review immediately, but I will try to get to it!

How are the image preview managed? Is it the full image? If so, does it load all of the images immediately or only as you scroll down? If a forum allows very large uploads, or someone just has many images, will it not bring the website down by loading all of them?

The files are loaded in batches as usual (20 files each), so it will depend on the overal image size. Currently the images are just using the path of the image. As there are no thumbnails generated by this extention :(

So if someone has any suggestions, let me know. Maybe generate it on-the-fly on a specific endpoint? fof/uploads/{file-id}/preview? If so, would we cache that on the server, or just in the browser?

Copy link
Member

@davwheat davwheat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in FoF, so I won't make this a proper review, but I just had a few suggestions to point out to do with styling.

resources/less/forum/fileList.less Outdated Show resolved Hide resolved
padding: 0px;
margin: 0 -7px;

display: flex;
Copy link
Member

@davwheat davwheat Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could display: grid be easier for this? Has good support across browsers (even IE, if you're mad you provide the older spec properties too).

display: grid;
grid-template-columns: repeat(3, minmax(10px, 1fr));

...would generate a grid with 3 columns. I think it's clearer than the calcs being used at the moment. Plus you can then use gap to create the spacing between the items (supported in FF61+, Chrome 66+, Safari 12+, or even earlier if you also provide grid-gap).

Reasoning behind minmax(10px, 1fr) over 1fr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered the display: grid too, but I wasn't sure if it was used in Flarum anywhere else, so I went for the safe flexbox variant instead. I could change it if needed.

resources/less/forum/fileList.less Outdated Show resolved Hide resolved
resources/less/forum/fileList.less Outdated Show resolved Hide resolved
resources/locale/en.yml Show resolved Hide resolved
resources/locale/en.yml Outdated Show resolved Hide resolved
resources/locale/en.yml Outdated Show resolved Hide resolved
jaspervriends and others added 2 commits February 1, 2021 16:27
Comma splicing

Co-authored-by: David Wheatley <davidwheatley03@gmail.com>
Comma splicing

Co-authored-by: David Wheatley <davidwheatley03@gmail.com>
@luceos
Copy link
Contributor

luceos commented Feb 2, 2021

I'd love to hear other peoples' opinion about the following. Jasper and I had a discussion about the upload button, previous commits had it replaced by the media manager. Right now there's (yet) another button. Screen space is scarce, especially in the editor.

My suggestion is to allow an admin setting to choose between (upload button, media manager button or both). And then render accordingly. The media manager adds another click to upload.

@davwheat
Copy link
Member

davwheat commented Feb 2, 2021

I'm a fan of that. Maybe it's time to also replace the "Upload" text with a tooltip to match the other buttons in the editor toolbar?

@jaspervriends
Copy link
Contributor Author

jaspervriends commented Feb 2, 2021

@luceos I think an admin setting would be fine. What would be the default setting then? Both buttons visible? And optionally hide one of the buttons?

Maybe it's time to also replace the "Upload" text with a tooltip to match the other buttons in the editor toolbar?

Yup, I already gave the upload button a tooltip :)

@jaspervriends
Copy link
Contributor Author

@luceos @davwheat As requested, I've made some changes and worked on the feedback provided.

I've added an option called Composer buttons to the admin dashboard:
image

Which results into:

  • Both buttons visible:
    image
  • Upload button only:
    image
  • Media manager button only:
    image

If there is anything else, let me know!

Copy link
Member

@imorland imorland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been checking out this PR for a couple of days locally, and I must say it works very, very well.

There's a couple of features that I personally feel this needs, and I'd really appreciate the thoughts of others here:

  • Ability to remove an upload from the media manager
  • Ability to access the media manager from the user profile
  • Ability for moderators to access the media of others, with the possibility to remove inappropriate content

I'm quite undecided on if the above should delay merging, or could be follow up changes

resources/locale/en.yml Outdated Show resolved Hide resolved
js/src/admin/components/UploadPage.js Show resolved Hide resolved
js/src/forum/components/FileManagerModal.js Outdated Show resolved Hide resolved
@@ -193,6 +201,17 @@ export default class UploadPage extends ExtensionPage {
m('.helpText', app.translator.trans('fof-upload.admin.help_texts.download_templates')),
this.templateOptionsDescriptions(),
]),
m('fieldset', [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, but we should probably change this stuff to JSX for better readability in another PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but as you say, this should be a separate PR to this feature

@davwheat
Copy link
Member

davwheat commented Feb 10, 2021

Not sure on others' opinions, but it might be worth considering display: grid again. Flarum doesn't use it elsewhere, but some other styles core and this ext use are incompatible with IE11, so using it wouldn't be a major issue, but it'd just make styling far easier.

Up to you at the end of the day -- both work fine!

@jaspervriends
Copy link
Contributor Author

@imorland I've updated the PR again and added an uploads overview to the user profile page (I agree it is a good addition too). Also, I added a fof-upload.viewUserUploads to view uploads from other users for moderation purpose. By default the permission is set to moderators in the migration file.

Also, I already added the fof-upload.deleteUserUploads to the same migration file for future usage. There is no delete functionality yet, also, I am wondering what would be a good approach for this as there are multiple ways to upload files to different adapters.

When a user sees their own profile, the button label is My uploads, when viewing another profile (and having the rights) they'll see User uploads.

When you click a file in the user profile page, it will open the file URL.

image

@imorland
Copy link
Member

Superb @jaspervriends - I'll take a closer look after work tonight!

In regards to deletion, I agree it's a tricky subject. My feeling is that instead of actually deleting the file from disk/bucket/whatever, which in turn could likely impact posts that have it embedded, we should instead 'delete from media manager'.

Perhaps this could be done by adding a column to the fof-upload-files table, null by default, to act as a flag as to if the file should be included in the media library?

@imorland
Copy link
Member

imorland commented Mar 8, 2021

Any thoughts on the above @jaspervriends ?

Ideally I'd like to get this merged before we start working on the beta 16 updates for this extension

@imorland
Copy link
Member

I'll merge this now, @davwheat and I will add the 'delete from media manager' feature as described #262 (comment)

@imorland imorland merged commit 03bd491 into FriendsOfFlarum:master Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants