Frontend: Cleaned up poll code
ci/woodpecker/push/ociImagePush Pipeline was successful
Details
ci/woodpecker/push/ociImagePush Pipeline was successful
Details
This commit is contained in:
parent
98c5bcb4c4
commit
5c8db9b243
|
@ -42,7 +42,10 @@
|
||||||
</span>
|
</span>
|
||||||
<span v-if="!isLocal">
|
<span v-if="!isLocal">
|
||||||
<span> · </span>
|
<span> · </span>
|
||||||
<a @click.stop="refresh">{{ i18n.ts.reload }}</a>
|
<a v-if="!refreshing" @click.stop="refresh">{{
|
||||||
|
i18n.ts.reload
|
||||||
|
}}</a>
|
||||||
|
<span v-else>{{ i18n.ts._poll.refreshing }}</span>
|
||||||
</span>
|
</span>
|
||||||
<span v-if="isVoted"> · {{ i18n.ts._poll.voted }}</span>
|
<span v-if="isVoted"> · {{ i18n.ts._poll.voted }}</span>
|
||||||
<span v-else-if="closed"> · {{ i18n.ts._poll.closed }}</span>
|
<span v-else-if="closed"> · {{ i18n.ts._poll.closed }}</span>
|
||||||
|
@ -57,14 +60,17 @@ import * as misskey from "calckey-js";
|
||||||
import { sum } from "@/scripts/array";
|
import { sum } from "@/scripts/array";
|
||||||
import { pleaseLogin } from "@/scripts/please-login";
|
import { pleaseLogin } from "@/scripts/please-login";
|
||||||
import * as os from "@/os";
|
import * as os from "@/os";
|
||||||
|
import { alert } from "@/os";
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { useInterval } from "@/scripts/use-interval";
|
import { useInterval } from "@/scripts/use-interval";
|
||||||
|
import Mfm from "@/components/mfm";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
note: misskey.entities.Note;
|
note: misskey.entities.Note & Required<Pick<misskey.entities.Note, "poll">>;
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const refreshing = ref(false);
|
||||||
const remaining = ref(-1);
|
const remaining = ref(-1);
|
||||||
|
|
||||||
const total = computed(() => sum(props.note.poll.choices.map((x) => x.votes)));
|
const total = computed(() => sum(props.note.poll.choices.map((x) => x.votes)));
|
||||||
|
@ -100,7 +106,7 @@ if (props.note.poll.expiresAt) {
|
||||||
const tick = () => {
|
const tick = () => {
|
||||||
remaining.value = Math.floor(
|
remaining.value = Math.floor(
|
||||||
Math.max(
|
Math.max(
|
||||||
new Date(props.note.poll.expiresAt).getTime() - Date.now(),
|
new Date(props.note.poll.expiresAt!).getTime() - Date.now(),
|
||||||
0
|
0
|
||||||
) / 1000
|
) / 1000
|
||||||
);
|
);
|
||||||
|
@ -117,13 +123,27 @@ if (props.note.poll.expiresAt) {
|
||||||
|
|
||||||
async function refresh() {
|
async function refresh() {
|
||||||
if (!props.note.uri) return;
|
if (!props.note.uri) return;
|
||||||
const obj = await os.apiWithDialog("ap/show", { uri: props.note.uri });
|
|
||||||
if (obj.type === "Note" && obj.object.poll) {
|
refreshing.value = true;
|
||||||
|
|
||||||
|
os.api("ap/show", { uri: props.note.uri })
|
||||||
|
.then((obj) => {
|
||||||
|
if (obj && obj.type === "Note" && obj.object.poll) {
|
||||||
props.note.poll = obj.object.poll;
|
props.note.poll = obj.object.poll;
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
alert({
|
||||||
|
type: "error",
|
||||||
|
text: err.message + "\n" + (err as any).id,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
refreshing.value = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const vote = async (id) => {
|
const vote = async (id: number) => {
|
||||||
pleaseLogin();
|
pleaseLogin();
|
||||||
|
|
||||||
if (props.readOnly || closed.value || isVoted.value) return;
|
if (props.readOnly || closed.value || isVoted.value) return;
|
||||||
|
|
Loading…
Reference in New Issue