enhance(reversi): 開始時に対局をシェアできるように

This commit is contained in:
syuilo
2024-01-24 10:36:02 +09:00
parent 547be1973d
commit 645f5e8633
4 changed files with 42 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<div v-if="game == null || (!game.isEnded && connection == null)"><MkLoading/></div>
<GameSetting v-else-if="!game.isStarted" :game="game" :connection="connection!"/>
<GameSetting v-else-if="!game.isStarted" v-model:shareWhenStart="shareWhenStart" :game="game" :connection="connection!"/>
<GameBoard v-else :game="game" :connection="connection"/>
</template>
@@ -32,17 +32,30 @@ const props = defineProps<{
const game = shallowRef<Misskey.entities.ReversiGameDetailed | null>(null);
const connection = shallowRef<Misskey.ChannelConnection | null>(null);
const shareWhenStart = ref(false);
watch(() => props.gameId, () => {
fetchGame();
});
function start(_game: Misskey.entities.ReversiGameDetailed) {
if (shareWhenStart.value) {
misskeyApi('notes/create', {
text: i18n.ts._reversi.iStartedAGame + '\n' + location.href,
visibility: 'home',
});
}
game.value = _game;
}
async function fetchGame() {
const _game = await misskeyApi('reversi/show-game', {
gameId: props.gameId,
});
game.value = _game;
shareWhenStart.value = false;
if (connection.value) {
connection.value.dispose();
@@ -52,7 +65,7 @@ async function fetchGame() {
gameId: game.value.id,
});
connection.value.on('started', x => {
game.value = x.game;
start(x.game);
});
connection.value.on('canceled', x => {
connection.value?.dispose();
@@ -78,10 +91,6 @@ onUnmounted(() => {
}
});
const headerActions = computed(() => []);
const headerTabs = computed(() => []);
definePageMetadata(computed(() => ({
title: 'Reversi',
icon: 'ti ti-device-gamepad',