Skip to content

Commit

Permalink
Update for Flarum v1 (#11)
Browse files Browse the repository at this point in the history
* Update for Flarum v1

* Apply fixes from StyleCI

* Apply fixes from StyleCI

Co-authored-by: datitisev <[email protected]>
  • Loading branch information
dsevillamartin and datitisev authored May 27, 2021
1 parent 367a20e commit 60f38af
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A [Flarum](http://flarum.org) extension. Replace author avatars with the first i
Install manually with composer:

```sh
composer require fof/discussion-thumbnail
composer require fof/discussion-thumbnail:"*"
```

### Updating
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"require": {
"flarum/core": "^0.1.0-beta.16"
"flarum/core": "^1.0.0"
},
"authors": [
{
Expand Down
3 changes: 2 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js'),
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/forum.less'),

(new Extend\ApiSerializer(BasicDiscussionSerializer::class))
->attributes(Listener\AddDiscussionThumbnail::class),
Expand Down
125 changes: 64 additions & 61 deletions js/package-lock.json

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

8 changes: 4 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"private": true,
"dependencies": {
"flarum-webpack-config": "^0.1.0-beta.10",
"intersection-observer": "^0.7.0",
"intersection-observer": "^0.12.0",
"object.assign": "^4.1.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"lint": "prettier --single-quote --trailing-comma es5 --print-width 150 --tab-width 4 --write src"
"format": "prettier --single-quote --trailing-comma es5 --print-width 150 --tab-width 4 --write src"
},
"devDependencies": {
"flarum": "0.1.0-beta.16",
"prettier": "^2.1.2"
"flarum": "github:flarum/types#v1",
"prettier": "^2.3.0"
}
}
9 changes: 3 additions & 6 deletions js/src/forum/components/DiscussionThumbnail.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import Component from 'flarum/common/Component';
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
import classList from 'flarum/common/utils/classList';

import 'object.assign/auto';
import 'intersection-observer';

const loadedSet = new Set();

export default class DiscussionThumbnail extends Component {
oninit(vnode) {
super.oninit(vnode);
}

view() {
const attrs = { ...this.attrs.elementAttrs };
const loaded = loadedSet.has(this.attrs.src);
Expand All @@ -29,7 +26,7 @@ export default class DiscussionThumbnail extends Component {
attrs[loaded ? 'src' : 'data-src'] = this.attrs.src;

return (
<div className={attrs.className}>
<div className={classList(attrs.className, 'DiscussionListItem-thumbnail')}>
{!loaded && <LoadingIndicator />}
<img {...attrs} />
</div>
Expand Down Expand Up @@ -57,6 +54,6 @@ export default class DiscussionThumbnail extends Component {

img.style.opacity = 1;

this.$('.LoadingIndicator').remove();
this.$('.LoadingIndicator-container').remove();
}
}
7 changes: 6 additions & 1 deletion js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { extend } from 'flarum/common/extend';
import Model from 'flarum/common/Model';
import Discussion from 'flarum/common/models/Discussion';
import DiscussionListItem from 'flarum/forum/components/DiscussionListItem';
import Tooltip from 'flarum/common/components/Tooltip';

import DiscussionThumbnail from './components/DiscussionThumbnail';

Expand All @@ -18,7 +19,11 @@ app.initializers.add('fof/discussion-thumbnail', () => {
if (!image) return;

const content = find(vdom, 'DiscussionListItem-content');
const author = find(content, 'DiscussionListItem-author');

if (!content || !content.children) return;

const tooltip = content.children.find((e) => e.tag && e.tag === Tooltip);
const author = find(tooltip, 'DiscussionListItem-author');
const avatar = find(author, 'Avatar');

if (!avatar) return;
Expand Down
10 changes: 10 additions & 0 deletions resources/less/forum.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DiscussionListItem-thumbnail {
position: relative;

.LoadingIndicator-container {
position: absolute;
height: 100%;
width: 100%;
--size: 18px;
}
}

0 comments on commit 60f38af

Please sign in to comment.