mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-23 06:09:21 +01:00
Add "Refresh" button for polls
This commit is contained in:
parent
23745d0683
commit
71083b46e2
3 changed files with 49 additions and 5 deletions
|
@ -410,6 +410,16 @@ a.card:hover {
|
||||||
|
|
||||||
/* POLLS */
|
/* POLLS */
|
||||||
|
|
||||||
|
.poll {
|
||||||
|
transition: opacity 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
.poll.loading {
|
||||||
|
opacity: 0.5;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.poll.read-only {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
.poll-option {
|
.poll-option {
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
|
|
@ -899,7 +899,11 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
|
||||||
const expiresAtDate = !!expiresAt && new Date(expiresAt);
|
const expiresAtDate = !!expiresAt && new Date(expiresAt);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="poll">
|
<div
|
||||||
|
class={`poll ${readOnly ? 'read-only' : ''} ${
|
||||||
|
uiState === 'loading' ? 'loading' : ''
|
||||||
|
}`}
|
||||||
|
>
|
||||||
{voted || expired ? (
|
{voted || expired ? (
|
||||||
options.map((option, i) => {
|
options.map((option, i) => {
|
||||||
const { title, votesCount: optionVotesCount } = option;
|
const { title, votesCount: optionVotesCount } = option;
|
||||||
|
@ -959,10 +963,6 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
|
||||||
onUpdate(pollResponse);
|
onUpdate(pollResponse);
|
||||||
setUIState('default');
|
setUIState('default');
|
||||||
}}
|
}}
|
||||||
style={{
|
|
||||||
pointerEvents: uiState === 'loading' || readOnly ? 'none' : 'auto',
|
|
||||||
opacity: uiState === 'loading' ? 0.5 : 1,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{options.map((option, i) => {
|
{options.map((option, i) => {
|
||||||
const { title } = option;
|
const { title } = option;
|
||||||
|
@ -994,6 +994,31 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
|
||||||
)}
|
)}
|
||||||
{!readOnly && (
|
{!readOnly && (
|
||||||
<p class="poll-meta">
|
<p class="poll-meta">
|
||||||
|
{!expired && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="textual"
|
||||||
|
disabled={uiState === 'loading'}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setUIState('loading');
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const pollResponse = await masto.poll.fetch(id);
|
||||||
|
onUpdate(pollResponse);
|
||||||
|
} catch (e) {
|
||||||
|
// Silent fail
|
||||||
|
}
|
||||||
|
setUIState('default');
|
||||||
|
})();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Refresh
|
||||||
|
</button>{' '}
|
||||||
|
•{' '}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<span title={votersCount}>{shortenNumber(votersCount)}</span>{' '}
|
<span title={votersCount}>{shortenNumber(votersCount)}</span>{' '}
|
||||||
{votersCount === 1 ? 'voter' : 'voters'}
|
{votersCount === 1 ? 'voter' : 'voters'}
|
||||||
{votersCount !== votesCount && (
|
{votersCount !== votesCount && (
|
||||||
|
|
|
@ -157,6 +157,15 @@ button,
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:is(button, .button).textual {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
vertical-align: baseline;
|
||||||
|
color: var(--link-color);
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
input[type='text'],
|
input[type='text'],
|
||||||
textarea,
|
textarea,
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Add table
Reference in a new issue