Frontend: Cleaned up poll code
ci/woodpecker/push/ociImagePush Pipeline was successful Details

This commit is contained in:
Natty 2023-09-30 22:16:27 +02:00
parent 98c5bcb4c4
commit 5c8db9b243
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
1 changed files with 28 additions and 8 deletions

View File

@ -42,7 +42,10 @@
</span>
<span v-if="!isLocal">
<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 v-if="isVoted"> · {{ i18n.ts._poll.voted }}</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 { pleaseLogin } from "@/scripts/please-login";
import * as os from "@/os";
import { alert } from "@/os";
import { i18n } from "@/i18n";
import { useInterval } from "@/scripts/use-interval";
import Mfm from "@/components/mfm";
const props = defineProps<{
note: misskey.entities.Note;
note: misskey.entities.Note & Required<Pick<misskey.entities.Note, "poll">>;
readOnly?: boolean;
}>();
const refreshing = ref(false);
const remaining = ref(-1);
const total = computed(() => sum(props.note.poll.choices.map((x) => x.votes)));
@ -100,7 +106,7 @@ if (props.note.poll.expiresAt) {
const tick = () => {
remaining.value = Math.floor(
Math.max(
new Date(props.note.poll.expiresAt).getTime() - Date.now(),
new Date(props.note.poll.expiresAt!).getTime() - Date.now(),
0
) / 1000
);
@ -117,13 +123,27 @@ if (props.note.poll.expiresAt) {
async function refresh() {
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;
}
})
.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();
if (props.readOnly || closed.value || isVoted.value) return;