@@ -596,16 +706,19 @@ function QuestionWorkspace({ owner, choirId, sessionId, userId, canPublishOffici
event.target.setCustomValidity(value && !value.trim() ? t('sight.nameRequired') : '');
}} />
+ {!canReadCloud && {entry('identity.unreachable')}{' '}
+
+ }
+ disabled={saving || !canReadCloud || !playable || (Boolean(saved) && !editable)}>{t(replace ? 'sight.replacePublished' : saved ? 'sight.updatePublished' : 'sight.publish')}
{t('sight.sourceFrozen')}
{!saved && {t('sight.publishScope')}}
}
{(status === 'loading' || (source && !loaded.failed && !loaded.document)) && {t('sight.loading')}}
- {status === 'error' && {t('sight.sourceError')}
}
+ {(status === 'error' || status === 'unavailable') && {t('sight.sourceError')}
}
{needsSource && {t('sight.sourceChanged')}
}
- {loaded.failed && source?.kind !== 'upload' && {t('sight.sourceError')}
}
+ {loaded.failed && source?.kind !== 'upload' && {t('sight.sourceError')}
}
{typeof issue === 'string' && {t(`sight.${issue}`)}
}
{failed && {t('sight.publishError')}
}
{!editing && loaded.document && selected && `/api/choirs/${encodeURIComponent(drive)}/sight-singing/questions`;
+import { isSightSingingMemberDenied, publishedPath } from './read';
type QuestionSnapshot = { choirId: string; questionId: string; version: number; name: string };
export type MelodySource =
@@ -30,33 +29,37 @@ function sourceKey(source: MelodySource | null) {
return JSON.stringify([source.kind, ownerKey, sessionId, choirId, score.id, attachment.id, attachment.revision]);
}
if (source.kind === 'upload') return JSON.stringify([source.kind, source.key]);
- return JSON.stringify([source.kind, source.choirId, source.questionId, source.version]);
+ return JSON.stringify([source.kind, source.kind === 'local' ? source.owner : null, source.choirId, source.questionId, source.version]);
}
-export function useMelodySource(source: MelodySource | null) {
+export function useMelodySource(source: MelodySource | null, canReadCloud: boolean, onMemberDenied: () => void) {
const key = sourceKey(source);
const currentSource = useEffectEvent(() => source);
const [loaded, setLoaded] = useState();
const [attempt, setAttempt] = useState(0);
+ const current = loaded?.key === key && loaded.attempt === attempt && 'document' in loaded ? loaded : null;
+ const waitingForConnection = !current && !canReadCloud && (source?.kind === 'cloud' || source?.kind === 'library');
+ const cloudAvailable = useEffectEvent(() => canReadCloud);
+ const memberDenied = useEffectEvent(onMemberDenied);
const retry = useCallback(() => setAttempt(value => value + 1), []);
useEffect(() => {
const source = currentSource();
- if (!source) return;
+ if (!source || waitingForConnection) return;
const lifetime = new AbortController();
- const signal = AbortSignal.any([lifetime.signal, AbortSignal.timeout(MUSICXML_READ_TIMEOUT_MS)]);
+ const signal = AbortSignal.any([lifetime.signal, AbortSignal.timeout(source.kind === 'cloud' ? 30_000 : MUSICXML_READ_TIMEOUT_MS)]);
const playback = source.kind === 'library' ? source.playback : null;
const choirId = source.kind === 'library' ? source.playback.choirId : source.choirId;
const lease = playback ? acquirePlaybackPreparation(playback) : null;
const revoke = () => { lifetime.abort(); setLoaded({ key, attempt, error: true }); };
- const unobserve = onDriveChange(change => { if (change.driveId === choirId && change.dropAuthority) revoke(); });
- const unsuspend = onNavigationSuspend(revoke);
+ const unobserve = onDriveChange(change => { if (playback && change.driveId === choirId && change.dropAuthority) revoke(); });
const verify = () => {
- if (!playback || document.visibilityState !== 'visible' || lifetime.signal.aborted) return;
+ if (!playback || !cloudAvailable() || document.visibilityState !== 'visible' || lifetime.signal.aborted) return;
void readAttachment(playback.choirId, playback.score.id, playback.attachment.id, lifetime.signal).then(fresh => {
if (!lifetime.signal.aborted && (fresh.revision !== playback.attachment.revision || fresh.trashExpiresAt)) revoke();
}).catch(reason => { if (!lifetime.signal.aborted && isSettingsReadDenied(reason)) revoke(); });
};
window.addEventListener('focus', verify);
+ window.addEventListener('online', verify);
const open = async (): Promise<{ bytes: Uint8Array; name: string }> => {
if (source.kind === 'library' && lease) {
const { bytes } = await resolveMusicXmlSource(source.playback, signal, lease);
@@ -75,7 +78,8 @@ export function useMelodySource(source: MelodySource | null) {
const response = await diagnosticFetch(`${publishedPath(choirId)}/${encodeURIComponent(source.questionId)}/score?version=${source.version}`, {
signal,
});
- if (response.ok) return { bytes: new Uint8Array(await response.arrayBuffer()), name: source.name };
+ if (!response.ok) throw new SettingsRequestError(response.status);
+ return { bytes: new Uint8Array(await response.arrayBuffer()), name: source.name };
}
throw new Error('question_source_unavailable');
};
@@ -83,15 +87,19 @@ export function useMelodySource(source: MelodySource | null) {
signal.throwIfAborted();
if (bytes.byteLength > SIGHT_SINGING_SCORE_MAX_BYTES) throw new Error('question_source_too_large');
setLoaded({ key, attempt, document: loadMelodyScore(bytes), bytes, name });
- }).catch(() => { if (!lifetime.signal.aborted) setLoaded({ key, attempt, error: true }); });
+ }).catch(error => {
+ if (lifetime.signal.aborted) return;
+ if (source.kind === 'cloud' && isSightSingingMemberDenied(error)) memberDenied();
+ setLoaded({ key, attempt, error: true });
+ });
return () => {
- lifetime.abort(); lease?.release(); unobserve(); unsuspend();
+ lifetime.abort(); lease?.release(); unobserve();
window.removeEventListener('focus', verify);
+ window.removeEventListener('online', verify);
};
- }, [key, attempt]);
- const current = loaded?.key === key && loaded.attempt === attempt && 'document' in loaded ? loaded : null;
+ }, [key, attempt, waitingForConnection]);
return {
document: current?.document ?? null, bytes: current?.bytes ?? null, name: current?.name ?? null,
- failed: loaded?.key === key && loaded.attempt === attempt && 'error' in loaded, retry,
+ failed: waitingForConnection || loaded?.key === key && loaded.attempt === attempt && 'error' in loaded, retry,
};
}
diff --git a/src/i18n/messages/de/practice.json b/src/i18n/messages/de/practice.json
index 37ad9337..6eccfc41 100644
--- a/src/i18n/messages/de/practice.json
+++ b/src/i18n/messages/de/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "Blattsing-Challenge",
"loading": "Wird geladen…",
- "needMember": "Öffne die Challenge online als Mitglied dieses Laufwerks.",
+ "needMember": "Nur Mitglieder dieses Laufwerks können die Blattsing-Challenge öffnen.",
"publishedQuestions": "Geteilte Aufgaben",
"retryLoad": "Neu laden",
"publishedError": "Geteilte Aufgaben konnten nicht geladen werden.",
diff --git a/src/i18n/messages/en/practice.json b/src/i18n/messages/en/practice.json
index e31f5195..bf87cf0e 100644
--- a/src/i18n/messages/en/practice.json
+++ b/src/i18n/messages/en/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "Sight-singing challenge",
"loading": "Loading…",
- "needMember": "Connect to the internet and open the challenge as a member of this drive.",
+ "needMember": "Only members of this drive can open the sight-singing challenge.",
"publishedQuestions": "Drive questions",
"retryLoad": "Reload",
"publishedError": "Couldn’t load drive questions.",
diff --git a/src/i18n/messages/es-419/practice.json b/src/i18n/messages/es-419/practice.json
index 36d550cc..b7caa20b 100644
--- a/src/i18n/messages/es-419/practice.json
+++ b/src/i18n/messages/es-419/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "Desafío de lectura cantada",
"loading": "Cargando…",
- "needMember": "Conéctate a internet y abre el desafío como miembro de esta unidad.",
+ "needMember": "Solo los miembros de esta unidad pueden abrir el desafío de lectura cantada.",
"publishedQuestions": "Ejercicios del disco",
"retryLoad": "Volver a cargar",
"publishedError": "No se pudieron cargar los ejercicios del disco.",
diff --git a/src/i18n/messages/fr/practice.json b/src/i18n/messages/fr/practice.json
index 80df6c0e..60aa1d03 100644
--- a/src/i18n/messages/fr/practice.json
+++ b/src/i18n/messages/fr/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "Défi de lecture chantée",
"loading": "Chargement…",
- "needMember": "Connectez-vous à Internet et ouvrez le défi en tant que membre de cet espace.",
+ "needMember": "Seuls les membres de cet espace peuvent ouvrir le défi de lecture chantée.",
"publishedQuestions": "Exercices du disque",
"retryLoad": "Recharger",
"publishedError": "Impossible de charger les exercices du disque.",
diff --git a/src/i18n/messages/it/practice.json b/src/i18n/messages/it/practice.json
index 264ba377..ddf34a72 100644
--- a/src/i18n/messages/it/practice.json
+++ b/src/i18n/messages/it/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "Sfida di lettura cantata",
"loading": "Caricamento…",
- "needMember": "Connettiti a Internet e apri la sfida come membro di questa unità.",
+ "needMember": "Solo i membri di questa unità possono aprire la sfida di lettura cantata.",
"publishedQuestions": "Esercizi del drive",
"retryLoad": "Ricarica",
"publishedError": "Impossibile caricare gli esercizi del drive.",
diff --git a/src/i18n/messages/ja/practice.json b/src/i18n/messages/ja/practice.json
index 287a4f4b..fe520374 100644
--- a/src/i18n/messages/ja/practice.json
+++ b/src/i18n/messages/ja/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "視唱チャレンジ",
"loading": "読み込み中…",
- "needMember": "オンラインでこのドライブのメンバーとして視唱チャレンジを開いてください。",
+ "needMember": "視唱チャレンジはこのドライブのメンバーのみ利用できます。",
"publishedQuestions": "ドライブの課題",
"retryLoad": "再読み込み",
"publishedError": "ドライブの課題を読み込めませんでした。",
diff --git a/src/i18n/messages/ko/practice.json b/src/i18n/messages/ko/practice.json
index 2717f8be..5fcf13df 100644
--- a/src/i18n/messages/ko/practice.json
+++ b/src/i18n/messages/ko/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "시창 챌린지",
"loading": "불러오는 중…",
- "needMember": "인터넷에 연결한 뒤 이 드라이브의 멤버로 시창 챌린지를 여세요.",
+ "needMember": "이 드라이브의 멤버만 시창 챌린지를 열 수 있습니다.",
"publishedQuestions": "드라이브 문제",
"retryLoad": "다시 불러오기",
"publishedError": "드라이브 문제를 불러올 수 없습니다.",
diff --git a/src/i18n/messages/pt-BR/practice.json b/src/i18n/messages/pt-BR/practice.json
index 5ab477bd..b85758f1 100644
--- a/src/i18n/messages/pt-BR/practice.json
+++ b/src/i18n/messages/pt-BR/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "Desafio de leitura cantada",
"loading": "Carregando…",
- "needMember": "Conecte-se à internet e abra o desafio como membro desta unidade.",
+ "needMember": "Somente membros desta unidade podem abrir o desafio de leitura cantada.",
"publishedQuestions": "Exercícios do drive",
"retryLoad": "Recarregar",
"publishedError": "Não foi possível carregar os exercícios do drive.",
diff --git a/src/i18n/messages/zh-Hans/practice.json b/src/i18n/messages/zh-Hans/practice.json
index a2751c83..2d888c88 100644
--- a/src/i18n/messages/zh-Hans/practice.json
+++ b/src/i18n/messages/zh-Hans/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "视唱挑战",
"loading": "正在读取…",
- "needMember": "请联网并以当前云盘成员身份打开视唱挑战。",
+ "needMember": "视唱挑战仅对当前云盘成员开放。",
"publishedQuestions": "云盘题目",
"retryLoad": "重新加载",
"publishedError": "无法加载云盘题目。",
diff --git a/src/i18n/messages/zh-Hant-TW/practice.json b/src/i18n/messages/zh-Hant-TW/practice.json
index 407eaa90..064256e7 100644
--- a/src/i18n/messages/zh-Hant-TW/practice.json
+++ b/src/i18n/messages/zh-Hant-TW/practice.json
@@ -247,7 +247,7 @@
"sight": {
"title": "視唱挑戰",
"loading": "正在讀取…",
- "needMember": "請連線並以此雲端硬碟成員身分開啟視唱挑戰。",
+ "needMember": "視唱挑戰僅對此雲端硬碟的成員開放。",
"publishedQuestions": "雲端硬碟題目",
"retryLoad": "重新載入",
"publishedError": "無法載入雲端硬碟題目。",