Skip to content

Commit

Permalink
fix create poll
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Feb 21, 2024
1 parent 2898600 commit b90c18d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
4 changes: 2 additions & 2 deletions js/src/forum/components/Poll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export default class Poll extends Component<PollAttrs, PollState> {
return (
<div className="Poll" data-id={poll.id()}>
{this.controlsView(controls.toArray())}
<div className="Poll-image">
{/* <div className="Poll-image">
<PollImage image={poll.image()} />
</div>
</div> */}
<div className="Poll-wrapper">
<PollTitle text={poll.question()} />
<PollSubTitle text={poll.subtitle()} />
Expand Down
53 changes: 24 additions & 29 deletions js/src/forum/components/Poll/PollListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import PollControls from '../../utils/PollControls';
import ItemList from 'flarum/common/utils/ItemList';
import listItems from 'flarum/common/helpers/listItems';

// Make translation calls shorter
// const t = app.translator.trans.bind(app.translator);
// const prfx = `${slug}.forum.list`;

export interface IPollListItemAttrs extends ComponentAttrs {
poll: Poll;
params: PollListParams;
Expand All @@ -35,14 +31,17 @@ export default class PollListItem<CustomAttrs extends IPollListItemAttrs = IPoll
* unless new data comes in.
*/
subtree!: SubtreeRetainer;
poll!: Poll;

highlightRegExp?: RegExp;

oninit(vnode: Mithril.Vnode<CustomAttrs, this>) {
super.oninit(vnode);

this.poll = this.attrs.poll;

this.subtree = new SubtreeRetainer(
() => this.attrs.poll.freshness,
() => this.poll.freshness,
() => {
const time = app.session.user && app.session.user.markedAllAsReadAt();
return time && time.getTime();
Expand All @@ -55,16 +54,14 @@ export default class PollListItem<CustomAttrs extends IPollListItemAttrs = IPoll
return {
className: classList('PollListItem', {
active: this.active(),
'PollListItem--hidden': this.attrs.poll.isHidden(),
'PollListItem--hidden': this.poll.isHidden(),
Slidable: 'ontouchstart' in window,
}),
};
}

view() {
const poll = this.attrs.poll;

const controls = PollControls.controls(poll, this).toArray();
const controls = PollControls.controls(this.poll, this).toArray();
const attrs = this.elementAttrs();

return (
Expand Down Expand Up @@ -93,8 +90,7 @@ export default class PollListItem<CustomAttrs extends IPollListItemAttrs = IPoll
}

slidableUnderneathView(): Mithril.Children {
const poll = this.attrs.poll;
const isUnread = poll.isUnread();
const isUnread = this.poll.isUnread();

return (
<span
Expand All @@ -107,9 +103,8 @@ export default class PollListItem<CustomAttrs extends IPollListItemAttrs = IPoll
}

contentView(): Mithril.Children {
const poll = this.attrs.poll;
// const isUnread = poll.isUnread();
// const isRead = poll.isRead();
// const isUnread = this.poll.isUnread();
// const isRead = this.poll.isRead();

return (
// <div className={classList('PollListItem-content', 'Slidable-content', { unread: isUnread, read: isRead })}>
Expand All @@ -121,17 +116,20 @@ export default class PollListItem<CustomAttrs extends IPollListItemAttrs = IPoll
}

mainView(): Mithril.Children {
const poll = this.attrs.poll;

return (
<Link href={app.route('fof_polls_list', { id: poll.id() })} className="PollListItem-main">
<h2 className="PollListItem-title">{highlight(poll.question(), this.highlightRegExp)}</h2>
<Link href={app.route('fof_polls_list', { id: this.poll.id() })} className="PollListItem-main">
<h2 className="PollListItem-title">{highlight(this.poll.question(), this.highlightRegExp)}</h2>
</Link>
);
}

infoView() {
return <ul className="UserCard-info">{listItems(this.infoItems().toArray())}</ul>;
return (
<div>
{this.poll.subtitle() && <p className="PollListItem-subtitle helpText">{this.poll.subtitle()}</p>}
<ul className="UserCard-info">{listItems(this.infoItems().toArray())}</ul>
</div>
);
}

oncreate(vnode: Mithril.VnodeDOM<CustomAttrs, this>) {
Expand All @@ -157,38 +155,35 @@ export default class PollListItem<CustomAttrs extends IPollListItemAttrs = IPoll
* Determine whether or not the discussion is currently being viewed.
*/
active() {
return app.current.matches(PollPage, { poll: this.attrs.poll });
return app.current.matches(PollPage, { poll: this.poll });
}

/**
* Mark the poll as read.
*/
markAsRead() {
const poll = this.attrs.poll;

if (poll.isUnread()) {
poll.save({ lastVotedNumber: poll.voteCount() });
if (this.poll.isUnread()) {
this.poll.save({ lastVotedNumber: this.poll.voteCount() });
m.redraw();
}
}

infoItems(): ItemList<Mithril.Children> {
const poll = this.attrs.poll;
const items = new ItemList<Mithril.Children>();
const active = !poll.hasEnded();
const activeView = poll.endDate()
const active = !this.poll.hasEnded();
const activeView = this.poll.endDate()
? [
icon('fas fa-clock'),
' ',
active
? app.translator.trans('fof-polls.forum.days_remaining', { time: dayjs(poll.endDate()).fromNow() })
? app.translator.trans('fof-polls.forum.days_remaining', { time: dayjs(this.poll.endDate()).fromNow() })
: app.translator.trans('fof-polls.forum.poll_ended'),
]
: [icon('fas fa-om'), ' ', app.translator.trans('fof-polls.forum.poll_never_ends')];

items.add('active', <span className={classList('UserCard-lastSeen', { active })}>{activeView}</span>);

const voteCount = poll.voteCount();
const voteCount = this.poll.voteCount();
if (voteCount !== undefined) {
items.add(
'discussion-count',
Expand Down
8 changes: 4 additions & 4 deletions js/src/forum/components/PollForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ export default class PollForm extends Component {
'submit',
<div className="Form-group">
<Button type="submit" className="Button Button--primary PollModal-SubmitButton" icon="fas fa-save" loading={this.state.loading}>
{t('fof-polls.forum.modal.submit')}
{app.translator.trans('fof-polls.forum.modal.submit')}
</Button>
{this.state.poll.exists && (
<Button className="Button Button--secondary" icon="fas fa-trash-alt" loading={this.state.deleting} onclick={this.delete.bind(this)}>
{t(`${prfx}.delete`)}
{app.translator.trans(`${prfx}.delete`)}
</Button>
)}
</div>,
Expand Down Expand Up @@ -260,8 +260,8 @@ export default class PollForm extends Component {
const options = this.options.map((o, i) => {
if (!o.data.attributes) o.data.attributes = {};

o.data.attributes.answer = this.optionAnswers[i]();
o.data.attributes.imageUrl = this.optionImageUrls[i]();
o.data.answer = this.optionAnswers[i]();
o.data.imageUrl = this.optionImageUrls[i]();

return o.data;
});
Expand Down

0 comments on commit b90c18d

Please sign in to comment.