mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 22:17:30 -07:00
This commit is contained in:
parent
4d504b837d
commit
b4c9a5d39e
4 changed files with 49 additions and 28 deletions
|
@ -90,27 +90,32 @@
|
||||||
|
|
||||||
this.oninput = (i, e) => {
|
this.oninput = (i, e) => {
|
||||||
this.choices[i] = e.target.value;
|
this.choices[i] = e.target.value;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.add = () => {
|
this.add = () => {
|
||||||
this.choices.push('');
|
this.choices.push('');
|
||||||
this.update();
|
this.update();
|
||||||
this.refs.choices.childNodes[this.choices.length - 1].childNodes[0].focus();
|
this.refs.choices.childNodes[this.choices.length - 1].childNodes[0].focus();
|
||||||
}
|
};
|
||||||
|
|
||||||
this.remove = (i) => {
|
this.remove = (i) => {
|
||||||
this.choices = this.choices.filter((_, _i) => _i != i);
|
this.choices = this.choices.filter((_, _i) => _i != i);
|
||||||
this.update();
|
this.update();
|
||||||
}
|
};
|
||||||
|
|
||||||
this.destroy = () => {
|
this.destroy = () => {
|
||||||
this.opts.ondestroy();
|
this.opts.ondestroy();
|
||||||
}
|
};
|
||||||
|
|
||||||
this.get = () => {
|
this.get = () => {
|
||||||
return {
|
return {
|
||||||
choices: this.choices.filter(choice => choice != '')
|
choices: this.choices.filter(choice => choice != '')
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
this.set = data => {
|
||||||
|
if (data.choices.length == 0) return;
|
||||||
|
this.choices = data.choices;
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</mk-poll-editor>
|
</mk-poll-editor>
|
||||||
|
|
|
@ -78,9 +78,9 @@
|
||||||
|
|
||||||
this.toggleResult = () => {
|
this.toggleResult = () => {
|
||||||
this.result = !this.result;
|
this.result = !this.result;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.vote = (id) => {
|
this.vote = id => {
|
||||||
if (this.poll.choices.some(c => c.is_voted)) return;
|
if (this.poll.choices.some(c => c.is_voted)) return;
|
||||||
this.api('posts/polls/vote', {
|
this.api('posts/polls/vote', {
|
||||||
post_id: this.post.id,
|
post_id: this.post.id,
|
||||||
|
@ -99,6 +99,6 @@
|
||||||
total: this.total + 1
|
total: this.total + 1
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
</mk-poll>
|
</mk-poll>
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
<mk-post-form-window>
|
<mk-post-form-window>
|
||||||
<mk-window ref="window" is-modal={ true } colored={ true }><yield to="header"><span if={ !parent.opts.reply }>新規投稿</span><span if={ parent.opts.reply }>返信</span><span class="files" if={ parent.files.length != 0 }>添付: { parent.files.length }ファイル</span><span class="uploading-files" if={ parent.uploadingFiles.length != 0 }>{ parent.uploadingFiles.length }個のファイルをアップロード中
|
<mk-window ref="window" is-modal={ true } colored={ true }>
|
||||||
<mk-ellipsis></mk-ellipsis></span></yield>
|
<yield to="header">
|
||||||
<yield to="content">
|
<span if={ !parent.opts.reply }>新規投稿</span>
|
||||||
<div class="ref" if={ parent.opts.reply }>
|
<span if={ parent.opts.reply }>返信</span>
|
||||||
<mk-post-preview post={ parent.opts.reply }></mk-post-preview>
|
<span class="files" if={ parent.files.length != 0 }>添付: { parent.files.length }ファイル</span>
|
||||||
</div>
|
<span class="uploading-files" if={ parent.uploadingFiles.length != 0 }>{ parent.uploadingFiles.length }個のファイルをアップロード中<mk-ellipsis></mk-ellipsis></span>
|
||||||
<div class="body">
|
</yield>
|
||||||
<mk-post-form ref="form" reply={ parent.opts.reply }></mk-post-form>
|
<yield to="content">
|
||||||
</div></yield>
|
<div class="ref" if={ parent.opts.reply }>
|
||||||
|
<mk-post-preview post={ parent.opts.reply }></mk-post-preview>
|
||||||
|
</div>
|
||||||
|
<div class="body">
|
||||||
|
<mk-post-form ref="form" reply={ parent.opts.reply }></mk-post-form>
|
||||||
|
</div>
|
||||||
|
</yield>
|
||||||
</mk-window>
|
</mk-window>
|
||||||
<style>
|
<style>
|
||||||
:scope
|
:scope
|
||||||
|
@ -48,13 +54,13 @@
|
||||||
|
|
||||||
this.refs.window.refs.form.on('change-uploading-files', files => {
|
this.refs.window.refs.form.on('change-uploading-files', files => {
|
||||||
this.update({
|
this.update({
|
||||||
uploadingFiles: files
|
uploadingFiles: files || []
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.refs.window.refs.form.on('change-files', files => {
|
this.refs.window.refs.form.on('change-files', files => {
|
||||||
this.update({
|
this.update({
|
||||||
files: files
|
files: files || []
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
<div class="medias { with: poll }" if={ files.length != 0 }>
|
<div class="medias { with: poll }" if={ files.length != 0 }>
|
||||||
<ul>
|
<ul>
|
||||||
<li each={ files }>
|
<li each={ files }>
|
||||||
<div class="img" style="background-image: url({ url + '?thumbnail&size=64' })" title={ name }></div><img class="remove" onclick={ _remove } src="/resources/desktop/remove.png" title="添付取り消し" alt=""/>
|
<div class="img" style="background-image: url({ url + '?thumbnail&size=64' })" title={ name }></div>
|
||||||
|
<img class="remove" onclick={ removeFile } src="/resources/desktop/remove.png" title="添付取り消し" alt=""/>
|
||||||
</li>
|
</li>
|
||||||
<li class="add" if={ files.length < 4 } title="PCからファイルを添付" onclick={ selectFile }><i class="fa fa-plus"></i></li>
|
<li class="add" if={ files.length < 4 } title="PCからファイルを添付" onclick={ selectFile }><i class="fa fa-plus"></i></li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="remain">残り{ 4 - files.length }</p>
|
<p class="remain">{ 4 - files.length }/4</p>
|
||||||
</div>
|
</div>
|
||||||
<mk-poll-editor if={ poll } ref="poll" ondestroy={ onPollDestroyed }></mk-poll-editor>
|
<mk-poll-editor if={ poll } ref="poll" ondestroy={ onPollDestroyed }></mk-poll-editor>
|
||||||
</div>
|
</div>
|
||||||
|
@ -334,10 +335,18 @@
|
||||||
this.autocomplete = new this.Autocomplete(this.refs.text);
|
this.autocomplete = new this.Autocomplete(this.refs.text);
|
||||||
this.autocomplete.attach();
|
this.autocomplete.attach();
|
||||||
|
|
||||||
|
// 書きかけの投稿を復元
|
||||||
let draft = localStorage.getItem('post-draft');
|
let draft = localStorage.getItem('post-draft');
|
||||||
if (draft) {
|
if (draft) {
|
||||||
draft = JSON.parse(draft);
|
draft = JSON.parse(draft);
|
||||||
this.refs.text.value = draft.text;
|
this.refs.text.value = draft.text;
|
||||||
|
this.files = draft.files;
|
||||||
|
if (draft.poll) {
|
||||||
|
this.poll = true;
|
||||||
|
this.update();
|
||||||
|
this.refs.poll.set(draft.poll);
|
||||||
|
}
|
||||||
|
this.trigger('change-files', this.files);
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -418,17 +427,18 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addFile = file => {
|
this.addFile = file => {
|
||||||
file._remove = () => {
|
|
||||||
this.files = this.files.filter(x => x.id != file.id);
|
|
||||||
this.trigger('change-files', this.files);
|
|
||||||
this.update();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.files.push(file);
|
this.files.push(file);
|
||||||
this.trigger('change-files', this.files);
|
this.trigger('change-files', this.files);
|
||||||
this.update();
|
this.update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.removeFile = e => {
|
||||||
|
const file = e.item;
|
||||||
|
this.files = this.files.filter(x => x.id != file.id);
|
||||||
|
this.trigger('change-files', this.files);
|
||||||
|
this.update();
|
||||||
|
};
|
||||||
|
|
||||||
this.addPoll = () => {
|
this.addPoll = () => {
|
||||||
this.poll = true;
|
this.poll = true;
|
||||||
};
|
};
|
||||||
|
@ -477,7 +487,7 @@
|
||||||
const context = {
|
const context = {
|
||||||
text: this.refs.text.value,
|
text: this.refs.text.value,
|
||||||
files: this.files,
|
files: this.files,
|
||||||
poll: this.poll ? this.refs.poll.get() : undefined
|
poll: this.poll && this.refs.poll ? this.refs.poll.get() : undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
localStorage.setItem('post-draft', JSON.stringify(context));
|
localStorage.setItem('post-draft', JSON.stringify(context));
|
||||||
|
|
Loading…
Reference in a new issue