fix(app): closed hash and canonical-form drawing messages, split crop and drawing views
This commit is contained in:
1 parent
7bf1404946
commit
1bbf97e65b
16 files changed
+487
-248
No files matched your search
@@ -1,12 +1,14 @@
|
||||
import type { PreviewState, SheetView } from '@faunosteo/core-wasm/types'
|
||||
import type { CatalogueFailure } from '@/catalogue/failure'
|
||||
import { rejectionReason } from './drawingReason'
|
||||
import { loadFailureMessage } from './messages'
|
||||
|
||||
/** The state of the drawing a view names itself (not the one it inherits). */
|
||||
export type DrawingStatus =
|
||||
| { kind: 'none' }
|
||||
| { kind: 'ok' }
|
||||
| { kind: 'missing' | 'rejected'; detail: string | null }
|
||||
| { kind: 'missing'; detail: null }
|
||||
| { kind: 'rejected'; detail: string | null }
|
||||
| { kind: 'failed'; failure: CatalogueFailure }
|
||||
|
||||
export function drawingStatusOf(
|
||||
@@ -18,7 +20,9 @@ export function drawingStatusOf(
|
||||
if (assetId === null) return { kind: 'none' }
|
||||
const held = state.drawings.find((drawing) => drawing.asset_id === assetId)
|
||||
if (held?.state === 'ok') return { kind: 'ok' }
|
||||
if (held) return { kind: held.state, detail: held.detail }
|
||||
if (held?.state === 'rejected')
|
||||
return { kind: 'rejected', detail: held.detail }
|
||||
// A drawing the handle refused at load is `missing` for the core: the failure says why.
|
||||
const failure = failures[assetId]
|
||||
return failure
|
||||
? { kind: 'failed', failure }
|
||||
@@ -28,9 +32,22 @@ export function drawingStatusOf(
|
||||
type Translate = (key: string) => string
|
||||
|
||||
export function drawingStatusText(t: Translate, status: DrawingStatus): string {
|
||||
if (status.kind === 'failed') return loadFailureMessage(t, status.failure)
|
||||
const label = t(`editor.views.drawing.${status.kind}`)
|
||||
if (status.kind === 'ok' || status.kind === 'none' || !status.detail)
|
||||
return label
|
||||
return `${label} ${t('editor.views.drawing.detail').replace('{detail}', status.detail)}`
|
||||
if (status.kind === 'failed') return failedText(t, status.failure)
|
||||
if (status.kind === 'rejected') return rejectedText(t, status.detail)
|
||||
return t(`editor.views.drawing.${status.kind}`)
|
||||
}
|
||||
|
||||
function failedText(t: Translate, failure: CatalogueFailure): string {
|
||||
return failure === 'drawing_hash_mismatch'
|
||||
? t('editor.views.drawing.hash_mismatch')
|
||||
: loadFailureMessage(t, failure)
|
||||
}
|
||||
|
||||
function rejectedText(t: Translate, detail: string | null): string {
|
||||
const reason = rejectionReason(detail)
|
||||
if (reason === 'not_canonical') return t('editor.views.drawing.not_canonical')
|
||||
return t('editor.views.drawing.rejected_reason').replace(
|
||||
'{reason}',
|
||||
t(`editor.upload.reason.${reason}`),
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user