Fix replicant reactivity for scoreboard

This commit is contained in:
Pandipipas
2026-02-08 17:19:06 +01:00
parent aa6c9acf1c
commit 62ce10df55
3 changed files with 10 additions and 18 deletions
+4 -6
View File
@@ -1,6 +1,5 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
import type { Ref } from 'vue';
import { playersReplicant } from '../../../browser_shared/replicants'; import { playersReplicant } from '../../../browser_shared/replicants';
import type { Schemas } from '../../../types'; import type { Schemas } from '../../../types';
@@ -67,7 +66,6 @@ const writeStorage = (value: PlayersMap) => {
export const usePlayersStore = defineStore('players', () => { export const usePlayersStore = defineStore('players', () => {
const players = ref<PlayersMap>({}); const players = ref<PlayersMap>({});
const replicant = playersReplicant; const replicant = playersReplicant;
const replicantRef = replicant?.data as unknown as Ref<PlayersMap | undefined> | undefined;
const storageSnapshot = readStorage(); const storageSnapshot = readStorage();
if (storageSnapshot) { if (storageSnapshot) {
players.value = storageSnapshot; players.value = storageSnapshot;
@@ -76,7 +74,7 @@ export const usePlayersStore = defineStore('players', () => {
const isApplyingReplicant = ref(false); const isApplyingReplicant = ref(false);
watch( watch(
() => replicantRef?.value, () => replicant?.data,
(value) => { (value) => {
if (!value) { if (!value) {
return; return;
@@ -93,11 +91,11 @@ export const usePlayersStore = defineStore('players', () => {
players, players,
(value) => { (value) => {
writeStorage(value); writeStorage(value);
if (isApplyingReplicant.value || !replicantRef) { if (isApplyingReplicant.value || !replicant) {
return; return;
} }
replicantRef.value = normalizePlayers(value); replicant.data = normalizePlayers(value);
replicant?.save(); replicant.save();
}, },
{ deep: true } { deep: true }
); );
+4 -6
View File
@@ -1,6 +1,5 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
import type { Ref } from 'vue';
import { scoreboardReplicant } from '../../../browser_shared/replicants'; import { scoreboardReplicant } from '../../../browser_shared/replicants';
import type { Schemas } from '../../../types'; import type { Schemas } from '../../../types';
@@ -61,7 +60,6 @@ const writeStorage = (value: Scoreboard) => {
export const useScoreboardStore = defineStore('scoreboard', () => { export const useScoreboardStore = defineStore('scoreboard', () => {
const scoreboard = ref<Scoreboard>({ ...defaultScoreboard }); const scoreboard = ref<Scoreboard>({ ...defaultScoreboard });
const replicant = scoreboardReplicant; const replicant = scoreboardReplicant;
const replicantRef = replicant?.data as unknown as Ref<Scoreboard | undefined> | undefined;
const storageSnapshot = readStorage(); const storageSnapshot = readStorage();
if (storageSnapshot) { if (storageSnapshot) {
scoreboard.value = storageSnapshot; scoreboard.value = storageSnapshot;
@@ -70,7 +68,7 @@ export const useScoreboardStore = defineStore('scoreboard', () => {
const isApplyingReplicant = ref(false); const isApplyingReplicant = ref(false);
watch( watch(
() => replicantRef?.value, () => replicant?.data,
(value) => { (value) => {
if (!value) { if (!value) {
return; return;
@@ -87,11 +85,11 @@ export const useScoreboardStore = defineStore('scoreboard', () => {
scoreboard, scoreboard,
(value) => { (value) => {
writeStorage(value); writeStorage(value);
if (isApplyingReplicant.value || !replicantRef) { if (isApplyingReplicant.value || !replicant) {
return; return;
} }
replicantRef.value = normalizeScoreboard(value); replicant.data = normalizeScoreboard(value);
replicant?.save(); replicant.save();
}, },
{ deep: true, flush: 'sync' } { deep: true, flush: 'sync' }
); );
+2 -6
View File
@@ -1,7 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { useHead } from '@unhead/vue'; import { useHead } from '@unhead/vue';
import { computed } from 'vue'; import { computed } from 'vue';
import type { Ref } from 'vue';
import { playersReplicant, scoreboardReplicant } from '../../browser_shared/replicants'; import { playersReplicant, scoreboardReplicant } from '../../browser_shared/replicants';
import type { Schemas } from '../../types'; import type { Schemas } from '../../types';
@@ -17,11 +16,8 @@ const defaultScoreboard: Schemas.Scoreboard = {
round: '', round: '',
}; };
const playersData = playersReplicant?.data as unknown as Ref<Schemas.Players | undefined> | undefined; const players = computed<Schemas.Players>(() => playersReplicant?.data ?? {});
const scoreboardData = scoreboardReplicant?.data as unknown as Ref<Schemas.Scoreboard | undefined> | undefined; const scoreboard = computed<Schemas.Scoreboard>(() => scoreboardReplicant?.data ?? defaultScoreboard);
const players = computed<Schemas.Players>(() => playersData?.value ?? {});
const scoreboard = computed<Schemas.Scoreboard>(() => scoreboardData?.value ?? defaultScoreboard);
const leftName = computed(() => { const leftName = computed(() => {
if (scoreboard.value.leftNameOverride) { if (scoreboard.value.leftNameOverride) {