Compare commits
6
Commits
ebbe4a678a
...
74ee288fd4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74ee288fd4 | ||
|
|
3d03567633 | ||
|
|
ef759e7d8b | ||
|
|
3dd47fa178 | ||
|
|
6e4c4930cb | ||
|
|
52d53fb78a |
@@ -7,6 +7,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.fabledsword.inkwell.core.Inkwell
|
||||
import com.fabledsword.inkwell.core.Label
|
||||
import com.fabledsword.inkwell.core.Note
|
||||
@@ -178,7 +180,7 @@ class BoardViewModel(
|
||||
// Broad by intent: the board must render something for any
|
||||
// failure, and the core reports problems as one error type
|
||||
// carrying a message meant to be shown.
|
||||
state.copy(loading = false, error = e.message ?: FALLBACK_ERROR)
|
||||
state.copy(loading = false, error = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -268,7 +270,7 @@ class BoardViewModel(
|
||||
val hits = withContext(Dispatchers.IO) { load(destination, filters, text) }
|
||||
state.copy(notes = hits, loading = false, error = null)
|
||||
} catch (e: Exception) {
|
||||
state.copy(loading = false, error = e.message ?: FALLBACK_ERROR)
|
||||
state.copy(loading = false, error = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,11 +287,20 @@ class BoardViewModel(
|
||||
fun openNoteById(id: String) {
|
||||
viewModelScope.launch {
|
||||
runCatching { withContext(Dispatchers.IO) { core.getNote(id) } }
|
||||
.onSuccess { state = state.copy(editing = it, editingSession = state.editingSession + 1) }
|
||||
.onSuccess { beginSitting(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun openNote(note: Note) {
|
||||
beginSitting(note)
|
||||
}
|
||||
|
||||
/**
|
||||
* A new sitting in the editor, on [note]: bumps [BoardState.editingSession] so
|
||||
* the editor's field is re-keyed onto what it now shows. Saving within a
|
||||
* sitting never comes through here.
|
||||
*/
|
||||
private fun beginSitting(note: Note? = state.editing) {
|
||||
state = state.copy(editing = note, editingSession = state.editingSession + 1)
|
||||
}
|
||||
|
||||
@@ -307,7 +318,7 @@ class BoardViewModel(
|
||||
*/
|
||||
fun compose() {
|
||||
draftDismissed = false
|
||||
state = state.copy(editing = blankDraft(), editingSession = state.editingSession + 1)
|
||||
beginSitting(blankDraft())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,7 +346,7 @@ class BoardViewModel(
|
||||
// Draft` deliberately does not bump this — it is written for the autosave
|
||||
// case, where re-keying mid-typing would be the bug.
|
||||
draftDismissed = false
|
||||
state = state.copy(editingSession = state.editingSession + 1)
|
||||
beginSitting()
|
||||
// A shared photo arrives with no words, and the note it makes is still a
|
||||
// note: the picture is its content.
|
||||
createFromDraft(content, allowEmpty = files.isNotEmpty()) { created ->
|
||||
@@ -423,7 +434,7 @@ class BoardViewModel(
|
||||
error = null,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
state.copy(saving = false, error = e.message ?: FALLBACK_ERROR)
|
||||
state.copy(saving = false, error = e.shownAs())
|
||||
}
|
||||
if (!draftDismissed) state.editing?.let(then)
|
||||
}
|
||||
@@ -607,7 +618,7 @@ class BoardViewModel(
|
||||
// Broad by intent, as elsewhere: the core reports every failure
|
||||
// as one error type carrying a message meant to be shown, and a
|
||||
// half-applied edit must still leave a usable screen.
|
||||
state.copy(saving = false, error = e.message ?: FALLBACK_ERROR)
|
||||
state.copy(saving = false, error = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -645,7 +656,6 @@ class BoardViewModel(
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val FALLBACK_ERROR = "Something went wrong."
|
||||
private const val SEARCH_DEBOUNCE_MS = 180L
|
||||
|
||||
// The core's board vocabulary. "archived", not "archive" — it matches on
|
||||
@@ -659,11 +669,7 @@ class BoardViewModel(
|
||||
readFile: (Uri) -> PickedFile,
|
||||
onRemindersChanged: () -> Unit,
|
||||
): ViewModelProvider.Factory =
|
||||
object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T =
|
||||
BoardViewModel(core, onRemindersChanged, readFile) as T
|
||||
}
|
||||
viewModelFactory { initializer { BoardViewModel(core, onRemindersChanged, readFile) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,7 +718,7 @@ private fun blankDraft(): Note =
|
||||
previews = emptyList(),
|
||||
createdAt = null,
|
||||
updatedAt = null,
|
||||
permission = "owner",
|
||||
permission = NoteAccess.OWNER.wire,
|
||||
shared = false,
|
||||
sharedBy = null,
|
||||
)
|
||||
|
||||
@@ -345,7 +345,7 @@ fun EditorLabelRow(
|
||||
// `#` on every chip, matching the card. This row still shows the
|
||||
// tags the BODY owns as well — it is the control surface, and the
|
||||
// "from tag" hint beside one is what says why it has no cross.
|
||||
text = "#${label.name}",
|
||||
text = hashtag(label.name),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = tint.tagInk(dark),
|
||||
modifier =
|
||||
|
||||
@@ -286,7 +286,7 @@ private fun ExactReminderPicker(
|
||||
) { Text(stringResource(R.string.picker_next)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.editor_cancel)) }
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||
},
|
||||
) {
|
||||
DatePicker(state = state)
|
||||
@@ -312,7 +312,7 @@ private fun ExactReminderPicker(
|
||||
}) { Text(stringResource(R.string.picker_set)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.editor_cancel)) }
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.fabledsword.inkwell.ui
|
||||
|
||||
/** What a failure says when the core gave it no message of its own. */
|
||||
internal const val FALLBACK_ERROR = "Something went wrong."
|
||||
|
||||
/**
|
||||
* The message to show for a failure.
|
||||
*
|
||||
* The core writes its errors for people to read ("notes.example.com responded, but
|
||||
* not with Inkwell's configuration"), so they are shown as they are rather than
|
||||
* replaced with a generic line that would throw away the only useful part.
|
||||
* [fallback] is for the failure that carries no message at all.
|
||||
*/
|
||||
internal fun Throwable.shownAs(fallback: String = FALLBACK_ERROR): String = message ?: fallback
|
||||
@@ -10,15 +10,17 @@ import com.fabledsword.inkwell.core.Note
|
||||
* refuses the rest anyway — this only keeps the editor from offering what would be
|
||||
* refused.
|
||||
*/
|
||||
enum class NoteAccess { OWNER, EDIT, VIEW }
|
||||
enum class NoteAccess(
|
||||
/** The core's `permission` string, which is also the server's and the web's. */
|
||||
val wire: String,
|
||||
) {
|
||||
OWNER("owner"),
|
||||
EDIT("edit"),
|
||||
VIEW("view"),
|
||||
}
|
||||
|
||||
val Note.access: NoteAccess
|
||||
get() =
|
||||
when (permission) {
|
||||
"edit" -> NoteAccess.EDIT
|
||||
"view" -> NoteAccess.VIEW
|
||||
else -> NoteAccess.OWNER
|
||||
}
|
||||
get() = NoteAccess.entries.firstOrNull { it.wire == permission } ?: NoteAccess.OWNER
|
||||
|
||||
/** Its content can't change here: it is in the trash, or shared with us to view. */
|
||||
val Note.readOnlyHere: Boolean
|
||||
|
||||
@@ -402,7 +402,7 @@ private fun LabelChips(labels: List<NoteLabel>) {
|
||||
// this row is a tag — a tag lifted off its own line, or one attached
|
||||
// through the picker — and the hash is how you would type either. It
|
||||
// also keeps a lifted chip reading as the `#todo` somebody wrote.
|
||||
text = "#${label.name}",
|
||||
text = hashtag(label.name),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = tint.tagInk(dark),
|
||||
maxLines = 1,
|
||||
|
||||
@@ -126,19 +126,66 @@ fun MenuItem(
|
||||
fun ConfirmDeleteDialog(
|
||||
onConfirm: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
ConfirmDialog(
|
||||
title = stringResource(R.string.editor_delete_forever_title),
|
||||
body = stringResource(R.string.editor_delete_forever_body),
|
||||
confirm = stringResource(R.string.editor_delete_forever_confirm),
|
||||
onDismiss = onDismiss,
|
||||
onConfirm = onConfirm,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A confirmation: what is about to happen, what it costs, and one way out.
|
||||
*
|
||||
* Every dialog that asks before acting is this one, so they all word their buttons
|
||||
* and lay out their consequences the same way.
|
||||
*/
|
||||
@Composable
|
||||
fun ConfirmDialog(
|
||||
title: String,
|
||||
body: String,
|
||||
confirm: String,
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: () -> Unit,
|
||||
footnote: String? = null,
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.editor_delete_forever_title)) },
|
||||
text = { Text(stringResource(R.string.editor_delete_forever_body)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = onConfirm) {
|
||||
Text(stringResource(R.string.editor_delete_forever_confirm))
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(text = body, style = MaterialTheme.typography.bodyMedium)
|
||||
footnote?.let {
|
||||
Text(
|
||||
text = it,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.editor_cancel)) }
|
||||
confirmButton = {
|
||||
TextButton(onClick = onConfirm) { Text(confirm) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/** Secondary text under a field or a heading: smaller, and in the quieter ink. */
|
||||
@Composable
|
||||
fun Hint(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ fun SharedByLine(note: Note) {
|
||||
)
|
||||
}
|
||||
|
||||
private const val VIEW = "view"
|
||||
private const val EDIT = "edit"
|
||||
private val VIEW = NoteAccess.VIEW.wire
|
||||
private val EDIT = NoteAccess.EDIT.wire
|
||||
|
||||
/**
|
||||
* The Share sheet: who the note is shared with, and adding someone or a group.
|
||||
@@ -222,11 +222,7 @@ private fun TargetName(
|
||||
Column(modifier = modifier) {
|
||||
Text(text = title, style = MaterialTheme.typography.bodyLarge)
|
||||
detail?.let {
|
||||
Text(
|
||||
text = it,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.fabledsword.inkwell.core.CoreException
|
||||
import com.fabledsword.inkwell.core.Inkwell
|
||||
import com.fabledsword.inkwell.core.Member
|
||||
@@ -99,7 +101,7 @@ class ShareViewModel(
|
||||
)
|
||||
}
|
||||
} catch (e: CoreException) {
|
||||
state.copy(loading = false, loadError = e.describeShareFailure())
|
||||
state.copy(loading = false, loadError = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +128,7 @@ class ShareViewModel(
|
||||
onStoreChanged()
|
||||
state.copy(busy = false, shares = shares)
|
||||
} catch (e: CoreException) {
|
||||
state.copy(busy = false, error = e.describeShareFailure())
|
||||
state.copy(busy = false, error = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,13 +137,6 @@ class ShareViewModel(
|
||||
fun factory(
|
||||
core: Inkwell,
|
||||
onStoreChanged: () -> Unit,
|
||||
): ViewModelProvider.Factory =
|
||||
object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = ShareViewModel(core, onStoreChanged) as T
|
||||
}
|
||||
): ViewModelProvider.Factory = viewModelFactory { initializer { ShareViewModel(core, onStoreChanged) } }
|
||||
}
|
||||
}
|
||||
|
||||
/** The core's message is written to be shown ("The server doesn't have this note yet…"). */
|
||||
private fun Throwable.describeShareFailure(): String = message ?: "Something went wrong."
|
||||
|
||||
@@ -201,11 +201,7 @@ private fun SignInFields(
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.sync_device_name_help),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.sync_device_name_help))
|
||||
} else {
|
||||
PlainTextField(
|
||||
value = token,
|
||||
@@ -218,11 +214,7 @@ private fun SignInFields(
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.sync_token_help),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.sync_token_help))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,11 +252,7 @@ private fun AddressSection(
|
||||
Text(stringResource(R.string.sync_check))
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = stringResource(R.string.sync_address_help),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.sync_address_help))
|
||||
}
|
||||
|
||||
/** Everything the probe produced: progress, failure, what answered, and the risk. */
|
||||
@@ -311,11 +299,7 @@ private fun ProbeCard(
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
)
|
||||
version?.let {
|
||||
Text(
|
||||
text = stringResource(R.string.sync_server_version, it),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.sync_server_version, it))
|
||||
}
|
||||
Text(
|
||||
text = describeCompatibility(compatibility),
|
||||
|
||||
@@ -11,7 +11,6 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@@ -146,10 +145,8 @@ private fun BuildLine() {
|
||||
val context = LocalContext.current
|
||||
val unknown = stringResource(R.string.build_unknown)
|
||||
val version = remember(context) { context.installedVersionName() ?: unknown }
|
||||
Text(
|
||||
Hint(
|
||||
text = version,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = 16.dp),
|
||||
)
|
||||
}
|
||||
@@ -183,11 +180,7 @@ private fun LinkedPanel(
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
)
|
||||
state.linkedAs?.let {
|
||||
Text(
|
||||
text = stringResource(R.string.sync_linked_as, it),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.sync_linked_as, it))
|
||||
}
|
||||
Text(
|
||||
text =
|
||||
@@ -200,11 +193,7 @@ private fun LinkedPanel(
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
if (state.pending) {
|
||||
Text(
|
||||
text = stringResource(R.string.sync_unsent),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.sync_unsent))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,11 +214,7 @@ private fun LinkedPanel(
|
||||
|
||||
state.lastOutcome?.let { outcome ->
|
||||
if (state.syncError == null) {
|
||||
Text(
|
||||
text = syncSummary(outcome),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(syncSummary(outcome))
|
||||
}
|
||||
// Rejections are the server refusing a SPECIFIC change. Surfaced, never
|
||||
// swallowed, because only a person can resolve them.
|
||||
@@ -269,10 +254,8 @@ private fun LinkedPanel(
|
||||
onOutcome = onInstallOutcome,
|
||||
)
|
||||
|
||||
Text(
|
||||
Hint(
|
||||
text = stringResource(R.string.sync_footer),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
)
|
||||
|
||||
@@ -280,20 +263,14 @@ private fun LinkedPanel(
|
||||
// Confirmed because it is not obvious what disconnecting does to the notes.
|
||||
// The copy answers that first — they stay — since the fear it raises is
|
||||
// "will this delete something?", not "am I sure?".
|
||||
AlertDialog(
|
||||
onDismissRequest = { confirmingUnlink = false },
|
||||
title = { Text(stringResource(R.string.sync_disconnect_title)) },
|
||||
text = { Text(stringResource(R.string.sync_disconnect_body)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
confirmingUnlink = false
|
||||
onUnlink()
|
||||
}) { Text(stringResource(R.string.sync_disconnect)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { confirmingUnlink = false }) {
|
||||
Text(stringResource(R.string.editor_cancel))
|
||||
}
|
||||
ConfirmDialog(
|
||||
title = stringResource(R.string.sync_disconnect_title),
|
||||
body = stringResource(R.string.sync_disconnect_body),
|
||||
confirm = stringResource(R.string.sync_disconnect),
|
||||
onDismiss = { confirmingUnlink = false },
|
||||
onConfirm = {
|
||||
confirmingUnlink = false
|
||||
onUnlink()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.fabledsword.inkwell.core.Compatibility
|
||||
import com.fabledsword.inkwell.core.Inkwell
|
||||
import com.fabledsword.inkwell.core.ProbeResult
|
||||
@@ -143,7 +145,7 @@ class SyncViewModel(
|
||||
// A store that won't answer is a real fault, but the screen
|
||||
// still has to render — showing the unlinked state is honest,
|
||||
// since without a readable link there is effectively none.
|
||||
state.copy(loading = false, status = null, syncError = e.describe())
|
||||
state.copy(loading = false, status = null, syncError = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +165,7 @@ class SyncViewModel(
|
||||
try {
|
||||
state.copy(probe = core.probe(url), probing = false)
|
||||
} catch (e: Exception) {
|
||||
state.copy(probing = false, probeError = e.describe())
|
||||
state.copy(probing = false, probeError = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,7 +219,7 @@ class SyncViewModel(
|
||||
status = withContext(Dispatchers.IO) { core.syncStatus() },
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
state.copy(linking = false, linkError = e.describe())
|
||||
state.copy(linking = false, linkError = e.shownAs())
|
||||
}
|
||||
if (state.linked) syncNow()
|
||||
}
|
||||
@@ -259,7 +261,7 @@ class SyncViewModel(
|
||||
} catch (e: Exception) {
|
||||
state.copy(
|
||||
syncing = false,
|
||||
syncError = if (announce) e.describe() else state.syncError,
|
||||
syncError = if (announce) e.shownAs() else state.syncError,
|
||||
)
|
||||
}
|
||||
// Only when something actually arrived: a no-op sync must not make the
|
||||
@@ -293,7 +295,7 @@ class SyncViewModel(
|
||||
pending = false,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
state.copy(syncing = false, syncError = e.describe())
|
||||
state.copy(syncing = false, syncError = e.shownAs())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,11 +320,7 @@ class SyncViewModel(
|
||||
fun factory(
|
||||
core: Inkwell,
|
||||
onStoreChanged: () -> Unit,
|
||||
): ViewModelProvider.Factory =
|
||||
object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = SyncViewModel(core, onStoreChanged) as T
|
||||
}
|
||||
): ViewModelProvider.Factory = viewModelFactory { initializer { SyncViewModel(core, onStoreChanged) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,12 +337,3 @@ private fun SyncOutcome.changedTheStore(): Boolean =
|
||||
pull.labelsApplied > 0uL ||
|
||||
pull.labelsDeleted > 0uL ||
|
||||
pull.blobsDownloaded > 0uL
|
||||
|
||||
/**
|
||||
* The message to show for a failure.
|
||||
*
|
||||
* The core writes these for people to read — "notes.example.com responded, but not
|
||||
* with Inkwell's configuration" — so they are shown as-is rather than
|
||||
* replaced with a generic string that would throw away the only useful part.
|
||||
*/
|
||||
private fun Exception.describe(): String = message ?: "Something went wrong."
|
||||
|
||||
@@ -181,8 +181,8 @@ fun TagsScreen(
|
||||
|
||||
is TagDialog.ConfirmMerge ->
|
||||
ConfirmDialog(
|
||||
title = stringResource(R.string.tags_rename_merges_title, hash(open.into.name)),
|
||||
body = stringResource(R.string.tags_rename_merges_body, hash(open.into.name)),
|
||||
title = stringResource(R.string.tags_rename_merges_title, hashtag(open.into.name)),
|
||||
body = stringResource(R.string.tags_rename_merges_body, hashtag(open.into.name)),
|
||||
confirm = stringResource(R.string.tags_rename_merges_confirm),
|
||||
onDismiss = { dialog = null },
|
||||
onConfirm = {
|
||||
@@ -204,7 +204,7 @@ fun TagsScreen(
|
||||
|
||||
is TagDialog.Delete ->
|
||||
ConfirmDialog(
|
||||
title = stringResource(R.string.tags_delete_title, hash(open.tag.name)),
|
||||
title = stringResource(R.string.tags_delete_title, hashtag(open.tag.name)),
|
||||
// The count is the part that makes the consequence real — "it is on
|
||||
// 40 notes" is a different decision from "delete this tag?". It comes
|
||||
// from the LIST, the only call the core populates a count on.
|
||||
@@ -235,13 +235,13 @@ fun TagsScreen(
|
||||
}
|
||||
|
||||
/**
|
||||
* `#` on the name, everywhere it is spoken about.
|
||||
* `#` on the name, everywhere it is spoken about: the chips on a card and in the
|
||||
* editor (`NoteCard.kt`, `EditorChrome.kt`) and every dialog here.
|
||||
*
|
||||
* The chips already wear it (`NoteCard.kt`, `EditorChrome.kt`) and it is the
|
||||
* reason these are called tags at all — a dialog that said "Delete grocery?" would
|
||||
* be talking about something else.
|
||||
* It is the reason these are called tags at all — a dialog that said "Delete
|
||||
* grocery?" would be talking about something else.
|
||||
*/
|
||||
private fun hash(name: String): String = "#$name"
|
||||
internal fun hashtag(name: String): String = "#$name"
|
||||
|
||||
@Composable
|
||||
private fun NewTagField(
|
||||
@@ -333,7 +333,7 @@ private fun TagRow(
|
||||
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = hash(tag.name),
|
||||
text = hashtag(tag.name),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = tint.tagInk(dark),
|
||||
)
|
||||
@@ -410,7 +410,7 @@ private fun RenameDialog(
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.tags_rename_title, hash(tag.name))) },
|
||||
title = { Text(stringResource(R.string.tags_rename_title, hashtag(tag.name))) },
|
||||
text = {
|
||||
PlainTextField(
|
||||
value = text,
|
||||
@@ -427,7 +427,7 @@ private fun RenameDialog(
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.tags_cancel)) }
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -452,11 +452,11 @@ private fun MergeDialog(
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.tags_merge_title, hash(tag.name))) },
|
||||
title = { Text(stringResource(R.string.tags_merge_title, hashtag(tag.name))) },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(
|
||||
text = stringResource(R.string.tags_merge_body, hash(tag.name)),
|
||||
text = stringResource(R.string.tags_merge_body, hashtag(tag.name)),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
if (others.isEmpty()) {
|
||||
@@ -469,7 +469,7 @@ private fun MergeDialog(
|
||||
others.forEach { other ->
|
||||
val tint = labelTintFor(other.name, other.color)
|
||||
Text(
|
||||
text = hash(other.name),
|
||||
text = hashtag(other.name),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = tint.tagInk(dark),
|
||||
modifier =
|
||||
@@ -483,7 +483,7 @@ private fun MergeDialog(
|
||||
},
|
||||
confirmButton = {},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.tags_cancel)) }
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -507,7 +507,7 @@ private fun ColourDialog(
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.tags_colour_of, hash(tag.name))) },
|
||||
title = { Text(stringResource(R.string.tags_colour_of, hashtag(tag.name))) },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
NOTE_TINTS.forEach { (key, tint) ->
|
||||
@@ -544,41 +544,7 @@ private fun ColourDialog(
|
||||
},
|
||||
confirmButton = {},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.tags_cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/** A destructive confirmation: what it is, what it costs, and one way out. */
|
||||
@Composable
|
||||
private fun ConfirmDialog(
|
||||
title: String,
|
||||
body: String,
|
||||
confirm: String,
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: () -> Unit,
|
||||
footnote: String? = null,
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(text = body, style = MaterialTheme.typography.bodyMedium)
|
||||
footnote?.let {
|
||||
Text(
|
||||
text = it,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onConfirm) { Text(confirm) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.tags_cancel)) }
|
||||
TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.fabledsword.inkwell.core.Inkwell
|
||||
import com.fabledsword.inkwell.core.Label
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -86,7 +88,7 @@ class TagsViewModel(
|
||||
// the only thing on the display, and an empty list here
|
||||
// would read as "you have no tags" rather than "I couldn't
|
||||
// look".
|
||||
onFailure = { state.copy(loading = false, error = it.describeTagFailure()) },
|
||||
onFailure = { state.copy(loading = false, error = it.shownAs()) },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -154,7 +156,7 @@ class TagsViewModel(
|
||||
state.copy(
|
||||
tags = tags,
|
||||
busy = false,
|
||||
error = failure?.describeTagFailure(),
|
||||
error = failure?.shownAs(),
|
||||
)
|
||||
// Even a FAILED write can have changed the store — a merge that threw
|
||||
// partway still moved rows — so the board is told either way.
|
||||
@@ -166,16 +168,6 @@ class TagsViewModel(
|
||||
fun factory(
|
||||
core: Inkwell,
|
||||
onStoreChanged: () -> Unit,
|
||||
): ViewModelProvider.Factory =
|
||||
object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = TagsViewModel(core, onStoreChanged) as T
|
||||
}
|
||||
): ViewModelProvider.Factory = viewModelFactory { initializer { TagsViewModel(core, onStoreChanged) } }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The core reports problems as one error type carrying a message meant to be
|
||||
* shown, so the message is used when there is one.
|
||||
*/
|
||||
private fun Throwable.describeTagFailure(): String = message ?: "Something went wrong."
|
||||
|
||||
@@ -68,18 +68,10 @@ fun UpdateCard(
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.fillMaxWidth().padding(top = 4.dp)) {
|
||||
Text(
|
||||
text = stringResource(R.string.update_installed_version, state.installedVersion),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.update_installed_version, state.installedVersion))
|
||||
|
||||
if (!state.selfUpdates) {
|
||||
Text(
|
||||
text = stringResource(R.string.update_debug_build),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.update_debug_build))
|
||||
return@Column
|
||||
}
|
||||
|
||||
@@ -95,11 +87,7 @@ fun UpdateCard(
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
} else if (state.upToDate) {
|
||||
Text(
|
||||
text = stringResource(R.string.update_current),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Hint(stringResource(R.string.update_current))
|
||||
}
|
||||
|
||||
if (state.working) {
|
||||
@@ -204,10 +192,8 @@ private val BANNER_SPINNER = 18.dp
|
||||
*/
|
||||
@Composable
|
||||
fun UnlinkedUpdateNote() {
|
||||
Text(
|
||||
Hint(
|
||||
text = stringResource(R.string.update_needs_server),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
// Carries the bottom breathing room the connect button used to provide,
|
||||
// now that it is the last thing on the unlinked screen.
|
||||
modifier = Modifier.padding(top = 8.dp, bottom = 24.dp),
|
||||
|
||||
@@ -7,6 +7,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import com.fabledsword.inkwell.AppUpdate
|
||||
import com.fabledsword.inkwell.UpdateOutcome
|
||||
import com.fabledsword.inkwell.core.ClientUpdate
|
||||
@@ -143,7 +145,7 @@ class UpdateViewModel(
|
||||
// Broad by intent, as everywhere the core is called: it reports
|
||||
// every failure as one error type carrying a message written to
|
||||
// be read, and a failed check must not take the screen down.
|
||||
state.copy(checking = false, error = e.message ?: FALLBACK)
|
||||
state.copy(checking = false, error = e.shownAs(FALLBACK))
|
||||
}
|
||||
// Fetched before anything is said, so the banner is a one-tap install
|
||||
// rather than the start of a wait. Off wifi this simply does not happen
|
||||
@@ -162,7 +164,7 @@ class UpdateViewModel(
|
||||
core.downloadClientUpdate(AppUpdate.downloadTarget(context).absolutePath)
|
||||
state.copy(downloading = false, ready = true)
|
||||
} catch (e: Exception) {
|
||||
state.copy(downloading = false, error = e.message ?: FALLBACK_DOWNLOAD)
|
||||
state.copy(downloading = false, error = e.shownAs(FALLBACK_DOWNLOAD))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +192,7 @@ class UpdateViewModel(
|
||||
// Off the main thread: this streams ~55 MiB into the session.
|
||||
withContext(Dispatchers.IO) { AppUpdate.install(context, target) }
|
||||
} catch (e: Exception) {
|
||||
e.message ?: FALLBACK
|
||||
e.shownAs(FALLBACK)
|
||||
}
|
||||
// `working` stays TRUE on success: the install is still in flight, and
|
||||
// on a silent update this process is about to be replaced. Clearing it
|
||||
@@ -220,11 +222,7 @@ class UpdateViewModel(
|
||||
core: Inkwell,
|
||||
context: Context,
|
||||
): ViewModelProvider.Factory =
|
||||
object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T =
|
||||
UpdateViewModel(core, context.applicationContext) as T
|
||||
}
|
||||
viewModelFactory { initializer { UpdateViewModel(core, context.applicationContext) } }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<string name="editor_unarchive">Unarchive</string>
|
||||
<string name="editor_trash">Move to trash</string>
|
||||
<string name="editor_restore">Restore</string>
|
||||
<string name="editor_cancel">Cancel</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="editor_share">Share…</string>
|
||||
|
||||
<!-- Sharing (#5175). Shares live on the server, so the sheet says so when this
|
||||
@@ -159,7 +159,6 @@
|
||||
said here rather than left as a surprise. -->
|
||||
<string name="tags_delete_from_text">Tags written as #tag in a note come back when that note is next edited.</string>
|
||||
|
||||
<string name="tags_cancel">Cancel</string>
|
||||
|
||||
<!-- Pickers -->
|
||||
<string name="label_picker_title">Tags</string>
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { api } from "../api/client";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useSessionStore } from "../stores/session";
|
||||
import { appLink } from "../router/links";
|
||||
import OneTimeLink from "./OneTimeLink.vue";
|
||||
import { useRowAction } from "../composables/useAction";
|
||||
import { useRowAction, useLoad } from "../composables/useAction";
|
||||
|
||||
// Admin: the accounts on this instance, and a password reset link for any of them
|
||||
// (#5173). There is no mail path, so the admin hands the link over.
|
||||
@@ -20,23 +19,13 @@ interface Account {
|
||||
const session = useSessionStore();
|
||||
|
||||
const accounts = ref<Account[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const { loading, error, load } = useLoad(async () => {
|
||||
accounts.value = (await api.get<{ accounts: Account[] }>("/api/accounts")).accounts;
|
||||
}, "Couldn't load accounts.");
|
||||
const { busy, act } = useRowAction();
|
||||
// The reset link just made, and whose it is. Never retrievable again once dismissed.
|
||||
const fresh = ref<{ link: string; email: string } | null>(null);
|
||||
|
||||
async function load() {
|
||||
error.value = "";
|
||||
try {
|
||||
accounts.value = (await api.get<{ accounts: Account[] }>("/api/accounts")).accounts;
|
||||
} catch (e) {
|
||||
error.value = errorMessage(e, "Couldn't load accounts.");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function resetLink(account: Account) {
|
||||
const self = account.id === session.user?.id;
|
||||
const warning = self
|
||||
|
||||
@@ -3,6 +3,7 @@ import { onMounted, ref } from "vue";
|
||||
import { api } from "../api/client";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { formatShortDateTime } from "../notes/datetime";
|
||||
import { useLoad } from "../composables/useAction";
|
||||
|
||||
// Admin: what has happened to accounts on this instance, newest first (#2939 §5).
|
||||
// Kept for `audit_retention_days` (Settings → Security).
|
||||
@@ -45,28 +46,18 @@ const REFUSALS = new Set([
|
||||
|
||||
const events = ref<AuditEvent[]>([]);
|
||||
const more = ref(false);
|
||||
const loading = ref(true);
|
||||
const { loading, error, load } = useLoad(async () => {
|
||||
const res = await page();
|
||||
events.value = res.events;
|
||||
more.value = res.more;
|
||||
}, "Couldn't load activity.");
|
||||
const loadingMore = ref(false);
|
||||
const error = ref("");
|
||||
|
||||
async function page(before?: string) {
|
||||
const query = before ? `?before=${encodeURIComponent(before)}` : "";
|
||||
return api.get<{ events: AuditEvent[]; more: boolean }>(`/api/accounts/activity${query}`);
|
||||
}
|
||||
|
||||
async function load() {
|
||||
error.value = "";
|
||||
try {
|
||||
const res = await page();
|
||||
events.value = res.events;
|
||||
more.value = res.more;
|
||||
} catch (e) {
|
||||
error.value = errorMessage(e, "Couldn't load activity.");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMore() {
|
||||
const last = events.value[events.value.length - 1];
|
||||
if (!last) return;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// The backdrop + centered dialog panel every modal shares: a fixed dimmed overlay and
|
||||
// a bordered, rounded panel with role="dialog". Emits `close` on Escape and on a
|
||||
// backdrop pointer-down (mousedown outside the panel). The caller sizes/shadows/pads
|
||||
// the panel via `panelClass` and fills it (its own header + content) through the
|
||||
// default slot.
|
||||
// the panel via `panelClass` and fills it through the default slot; `title` adds the
|
||||
// heading row with a close button that a titled dialog wants.
|
||||
//
|
||||
// Owns the dialog's focus contract on behalf of all four callers: focus moves in on
|
||||
// open, Tab is trapped inside, and focus returns to the opener on close. Doing it
|
||||
@@ -13,6 +13,7 @@
|
||||
// NoteEditor deliberately does NOT use this — its backdrop mousedown is drag-guarded and
|
||||
// its Escape/⌘-Enter handling is bespoke (unsaved-edit safety), so it keeps its own shell.
|
||||
import { onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import Icon from "./Icon.vue";
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
@@ -22,6 +23,8 @@ withDefaults(
|
||||
align?: "start" | "center";
|
||||
/** aria-label for the panel when it has no visible heading (e.g. the command palette). */
|
||||
ariaLabel?: string;
|
||||
/** A heading row with a close button, for a dialog that has a title. */
|
||||
title?: string;
|
||||
}>(),
|
||||
{ panelClass: "w-full max-w-sm shadow-xl", align: "start" },
|
||||
);
|
||||
@@ -109,6 +112,13 @@ onBeforeUnmount(() => restoreTo?.focus?.());
|
||||
@keydown.esc="emit('close')"
|
||||
@keydown.tab="onTab"
|
||||
>
|
||||
<div
|
||||
v-if="title"
|
||||
class="flex items-center justify-between border-b border-neutral-100 px-4 py-3 dark:border-neutral-800"
|
||||
>
|
||||
<h2 class="text-sm font-semibold">{{ title }}</h2>
|
||||
<button type="button" class="icon-btn" aria-label="Close" @click="emit('close')"><Icon name="close" /></button>
|
||||
</div>
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// because a wrong guess must cost a person nothing.
|
||||
import { computed } from "vue";
|
||||
import { useConfigStore, type ClientRelease } from "../stores/config";
|
||||
import { roughSize } from "../size";
|
||||
|
||||
const config = useConfigStore();
|
||||
|
||||
@@ -108,13 +109,6 @@ const missingPlatform = computed(() =>
|
||||
const hasLinux = computed(() => Object.keys(config.clients).some((id) => id.startsWith("linux-")));
|
||||
const installCommand = `curl -fsSL ${window.location.origin}/install.sh | sh`;
|
||||
|
||||
// One decimal below 10 MB, none above: these sit in one list where a 2.7 MB
|
||||
// package and a 95 MB AppImage are compared, and "3 MB" next to "95 MB" loses the
|
||||
// only distinction that matters at the small end.
|
||||
function readableSize(bytes: number): string {
|
||||
const mb = bytes / 1024 / 1024;
|
||||
return `${mb < 10 ? mb.toFixed(1) : mb.toFixed(0)} MB`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -144,7 +138,7 @@ function readableSize(bytes: number): string {
|
||||
second source to contradict it, a wrong version here is a wrong
|
||||
answer nothing can catch. Not knowing which build it is, is also
|
||||
not a reason to withhold the download. -->
|
||||
Version {{ client.version || "unknown" }} · {{ readableSize(client.size) }}<span
|
||||
Version {{ client.version || "unknown" }} · {{ roughSize(client.size, "MB") }}<span
|
||||
v-if="client.platform === 'linux-appimage'"
|
||||
>, and the only one that updates itself in place</span
|
||||
>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { errorMessage } from "../api/errors";
|
||||
import BaseButton from "./BaseButton.vue";
|
||||
import BaseInput from "./BaseInput.vue";
|
||||
import Icon from "./Icon.vue";
|
||||
import { useRowAction } from "../composables/useAction";
|
||||
import { useRowAction, useLoad } from "../composables/useAction";
|
||||
|
||||
// Admin: groups of people a note can be shared with in one go (#5177). A group is
|
||||
// the instance's; anyone can share with it, and a note shared with it reaches whoever
|
||||
@@ -23,11 +23,16 @@ interface Group {
|
||||
members: Person[];
|
||||
}
|
||||
|
||||
|
||||
const groups = ref<Group[]>([]);
|
||||
const accounts = ref<Person[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const { loading, error, load } = useLoad(async () => {
|
||||
const [g, a] = await Promise.all([
|
||||
api.get<{ groups: Group[] }>("/api/groups"),
|
||||
api.get<{ accounts: Person[] }>("/api/accounts"),
|
||||
]);
|
||||
groups.value = g.groups;
|
||||
accounts.value = a.accounts;
|
||||
}, "Couldn't load groups.");
|
||||
const name = ref("");
|
||||
const creating = ref(false);
|
||||
const { busy, act } = useRowAction();
|
||||
@@ -43,22 +48,6 @@ function outside(group: Group): Person[] {
|
||||
|
||||
const empty = computed(() => !loading.value && !groups.value.length);
|
||||
|
||||
async function load() {
|
||||
error.value = "";
|
||||
try {
|
||||
const [g, a] = await Promise.all([
|
||||
api.get<{ groups: Group[] }>("/api/groups"),
|
||||
api.get<{ accounts: Person[] }>("/api/accounts"),
|
||||
]);
|
||||
groups.value = g.groups;
|
||||
accounts.value = a.accounts;
|
||||
} catch (e) {
|
||||
error.value = errorMessage(e, "Couldn't load groups.");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function replace(updated: Group) {
|
||||
groups.value = groups.value.map((g) => (g.id === updated.id ? updated : g)).sort(byName);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { appLink } from "../router/links";
|
||||
import BaseButton from "./BaseButton.vue";
|
||||
import BaseInput from "./BaseInput.vue";
|
||||
import OneTimeLink from "./OneTimeLink.vue";
|
||||
import { toastOnFailure } from "../composables/useAction";
|
||||
import { toastOnFailure, useLoad } from "../composables/useAction";
|
||||
|
||||
// Admin: invite one person to register while registration stays closed (#5172).
|
||||
// The server keeps only a hash of each invite's token, so the link is shown once,
|
||||
@@ -29,27 +29,16 @@ const LIFETIMES = [
|
||||
{ days: 30, label: "30 days" },
|
||||
];
|
||||
|
||||
|
||||
const invites = ref<Invite[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const { loading, error, load } = useLoad(async () => {
|
||||
invites.value = (await api.get<{ invites: Invite[] }>("/api/invites")).invites;
|
||||
}, "Couldn't load invites.");
|
||||
const email = ref("");
|
||||
const days = ref(7);
|
||||
const creating = ref(false);
|
||||
// The link for the invite just made. Never retrievable again once dismissed.
|
||||
const freshLink = ref("");
|
||||
|
||||
async function load() {
|
||||
error.value = "";
|
||||
await toastOnFailure(async () => {
|
||||
invites.value = (await api.get<{ invites: Invite[] }>("/api/invites")).invites;
|
||||
} catch (e) {
|
||||
error.value = errorMessage(e, "Couldn't load invites.");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function create() {
|
||||
creating.value = true;
|
||||
error.value = "";
|
||||
@@ -71,7 +60,7 @@ async function create() {
|
||||
|
||||
async function revoke(invite: Invite) {
|
||||
if (!window.confirm(`Revoke the invite for ${who(invite)}? Its link will stop working.`)) return;
|
||||
try {
|
||||
await toastOnFailure(async () => {
|
||||
const updated = await api.del<Invite>(`/api/invites/${invite.id}`);
|
||||
invites.value = invites.value.map((i) => (i.id === updated.id ? updated : i));
|
||||
}, "Couldn't revoke that invite.");
|
||||
|
||||
@@ -58,11 +58,7 @@ async function doMerge(sourceId: string, targetId: string) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BaseModal panel-class="w-full max-w-sm shadow-xl" @close="emit('close')">
|
||||
<div class="flex items-center justify-between border-b border-neutral-100 px-4 py-3 dark:border-neutral-800">
|
||||
<h2 class="text-sm font-semibold">Manage tags</h2>
|
||||
<button type="button" class="icon-btn" aria-label="Close" @click="emit('close')"><Icon name="close" /></button>
|
||||
</div>
|
||||
<BaseModal panel-class="w-full max-w-sm shadow-xl" title="Manage tags" @close="emit('close')">
|
||||
<div class="flex flex-col gap-2 p-4">
|
||||
<form class="flex items-center gap-2" @submit.prevent="add">
|
||||
<Icon name="plus" />
|
||||
|
||||
@@ -105,11 +105,7 @@ onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BaseModal panel-class="w-full max-w-md shadow-xl" @close="emit('close')">
|
||||
<div class="flex items-center justify-between border-b border-neutral-100 px-4 py-3 dark:border-neutral-800">
|
||||
<h2 class="text-sm font-semibold">Share note</h2>
|
||||
<button type="button" class="icon-btn" aria-label="Close" @click="emit('close')"><Icon name="close" /></button>
|
||||
</div>
|
||||
<BaseModal panel-class="w-full max-w-md shadow-xl" title="Share note" @close="emit('close')">
|
||||
|
||||
<div class="flex flex-col gap-4 p-4">
|
||||
<p v-if="loading" class="py-4 text-center text-sm text-neutral-400">Loading…</p>
|
||||
|
||||
@@ -45,3 +45,23 @@ export function useRowAction() {
|
||||
}
|
||||
return { busy, act };
|
||||
}
|
||||
|
||||
/**
|
||||
* A list's first load: `loading` until it settles, then `error` holding what went
|
||||
* wrong (the server's reason, else `fallback`) or "". `load` is also the retry.
|
||||
*/
|
||||
export function useLoad(work: () => Promise<unknown>, fallback: string) {
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
async function load(): Promise<void> {
|
||||
error.value = "";
|
||||
try {
|
||||
await work();
|
||||
} catch (e) {
|
||||
error.value = errorMessage(e, fallback);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
return { loading, error, load };
|
||||
}
|
||||
|
||||
@@ -32,6 +32,17 @@ export interface IntegrationStatus {
|
||||
appimage_path: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run `handler` with each payload of a desktop event. Returns an unlisten function,
|
||||
* or a no-op where there is no event API (the web build, or a desktop runtime that
|
||||
* doesn't expose one).
|
||||
*/
|
||||
async function listen<T>(event: string, handler: (payload: T) => void): Promise<() => void> {
|
||||
const events = window.__TAURI__?.event;
|
||||
if (!events) return () => {};
|
||||
return events.listen<T>(event, (e) => handler(e.payload));
|
||||
}
|
||||
|
||||
/** True when running inside the Tauri desktop shell (vs. the web build). */
|
||||
export function isDesktop(): boolean {
|
||||
return typeof window !== "undefined" && !!window.__TAURI__;
|
||||
@@ -200,9 +211,7 @@ const SYNCED_EVENT = "inkwell://synced";
|
||||
* there, so there is nothing to hear.
|
||||
*/
|
||||
export async function onSynced(handler: (cycle: LastCycle) => void): Promise<() => void> {
|
||||
const events = window.__TAURI__?.event;
|
||||
if (!events) return () => {};
|
||||
return events.listen<LastCycle>(SYNCED_EVENT, (e) => handler(e.payload));
|
||||
return listen<LastCycle>(SYNCED_EVENT, handler);
|
||||
}
|
||||
|
||||
export const sync = {
|
||||
@@ -295,9 +304,7 @@ export const capture = {
|
||||
* what it has until its next load, which is a stale list rather than a broken one.
|
||||
*/
|
||||
export async function onCaptured(handler: () => void): Promise<() => void> {
|
||||
const events = window.__TAURI__?.event;
|
||||
if (!events) return () => {};
|
||||
return events.listen(CAPTURED_EVENT, () => handler());
|
||||
return listen(CAPTURED_EVENT, () => handler());
|
||||
}
|
||||
|
||||
/** A reminder the desktop's reminder worker found due (desktop/src-tauri/src/reminders.rs). */
|
||||
@@ -319,7 +326,5 @@ const REMINDER_DUE_EVENT = "inkwell://reminder-due";
|
||||
* Returns an unlisten function, or a no-op where there is no event API.
|
||||
*/
|
||||
export async function onReminderDue(handler: (reminder: DueReminder) => void): Promise<() => void> {
|
||||
const events = window.__TAURI__?.event;
|
||||
if (!events) return () => {};
|
||||
return events.listen<DueReminder>(REMINDER_DUE_EVENT, (e) => handler(e.payload));
|
||||
return listen<DueReminder>(REMINDER_DUE_EVENT, handler);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// How big something is, in words a person reads at a glance.
|
||||
|
||||
const UNITS = { MB: 1024 ** 2, GB: 1024 ** 3 } as const;
|
||||
|
||||
/**
|
||||
* `bytes` in `unit`, with one decimal below 10 and none above. Sizes sit in lists
|
||||
* where a 2.7 MB package and a 95 MB AppImage are compared, and "3 MB" next to
|
||||
* "95 MB" loses the only distinction that matters at the small end.
|
||||
*/
|
||||
export function roughSize(bytes: number, unit: keyof typeof UNITS): string {
|
||||
const n = bytes / UNITS[unit];
|
||||
return `${n < 10 ? n.toFixed(1) : n.toFixed(0)} ${unit}`;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { formatDateTime } from "../notes/datetime";
|
||||
import { repo } from "../adapters";
|
||||
import type { StorageUse } from "../adapters/repo";
|
||||
import { useAction } from "../composables/useAction";
|
||||
import { roughSize } from "../size";
|
||||
|
||||
// The signed-in person's own account (not admin): the native clients linked to it
|
||||
// (the desktop and Android apps sync with a device bearer token issued here), its
|
||||
@@ -51,14 +52,9 @@ async function load() {
|
||||
// Attachment storage (#2939 §4): how much this account uses, against its limit.
|
||||
const storage = ref<StorageUse | null>(null);
|
||||
|
||||
function gigabytes(bytes: number): string {
|
||||
const gb = bytes / 1024 ** 3;
|
||||
return `${gb < 10 ? gb.toFixed(1) : gb.toFixed(0)} GB`;
|
||||
}
|
||||
|
||||
function storageLine(use: StorageUse): string {
|
||||
const used = gigabytes(use.used_bytes);
|
||||
return use.limit_bytes === null ? `${used} used` : `${used} of ${gigabytes(use.limit_bytes)} used`;
|
||||
const used = roughSize(use.used_bytes, "GB");
|
||||
return use.limit_bytes === null ? `${used} used` : `${used} of ${roughSize(use.limit_bytes, "GB")} used`;
|
||||
}
|
||||
|
||||
async function link() {
|
||||
|
||||
@@ -107,6 +107,46 @@ const offeredServer = computed(
|
||||
() => source.value ?? status.value?.server_url?.replace(/\/+$/, "") ?? null,
|
||||
);
|
||||
|
||||
// The two choices on the update card, each a radio with a name and a line on what
|
||||
// choosing it means.
|
||||
interface UpdateOption {
|
||||
title: string;
|
||||
detail: string;
|
||||
checked: boolean;
|
||||
pick: () => Promise<void>;
|
||||
}
|
||||
|
||||
const sourceOptions = computed<UpdateOption[]>(() => [
|
||||
{
|
||||
title: "Fabled-Git",
|
||||
detail: "Where Inkwell is published, on the channel below.",
|
||||
checked: source.value === null,
|
||||
pick: () => switchSource(null),
|
||||
},
|
||||
{
|
||||
title: offeredServer.value ?? "",
|
||||
detail:
|
||||
"The build that server holds. It passes on official builds only: every update is checked against the signature built into this app first.",
|
||||
checked: source.value !== null,
|
||||
pick: () => switchSource(offeredServer.value),
|
||||
},
|
||||
]);
|
||||
|
||||
const channelOptions = computed<UpdateOption[]>(() => [
|
||||
{
|
||||
title: "Stable",
|
||||
detail: "Released versions only.",
|
||||
checked: channel.value === "stable",
|
||||
pick: () => switchChannel("stable"),
|
||||
},
|
||||
{
|
||||
title: "Development",
|
||||
detail: "Every build that passes CI. Newer, and less tested.",
|
||||
checked: channel.value === "dev",
|
||||
pick: () => switchChannel("dev"),
|
||||
},
|
||||
]);
|
||||
|
||||
// --- Quick capture -----------------------------------------------------------
|
||||
// A desktop-local preference, so it lives here beside the update channel rather
|
||||
// than in admin Settings: that screen is the SERVER's, and this is a property of
|
||||
@@ -147,15 +187,20 @@ async function checkUpdates() {
|
||||
}
|
||||
}
|
||||
|
||||
// After a channel or source switch: the last answer described somewhere else, so it
|
||||
// means nothing now. Forget it and ask again.
|
||||
async function recheck() {
|
||||
update.value = null;
|
||||
checkedOnce.value = false;
|
||||
await checkUpdates();
|
||||
}
|
||||
|
||||
async function switchChannel(next: UpdateChannel) {
|
||||
if (next === channel.value) return;
|
||||
updateError.value = "";
|
||||
try {
|
||||
channel.value = await updateBridge.setChannel(next);
|
||||
// The previous answer described the OTHER channel, so it's meaningless now.
|
||||
update.value = null;
|
||||
checkedOnce.value = false;
|
||||
await checkUpdates();
|
||||
await recheck();
|
||||
} catch (e) {
|
||||
updateError.value = errorMessage(e, "The update channel couldn't be changed.");
|
||||
}
|
||||
@@ -166,10 +211,7 @@ async function switchSource(next: string | null) {
|
||||
updateError.value = "";
|
||||
try {
|
||||
source.value = await updateBridge.setSource(next);
|
||||
// Same reason as a channel switch: the last answer came from somewhere else.
|
||||
update.value = null;
|
||||
checkedOnce.value = false;
|
||||
await checkUpdates();
|
||||
await recheck();
|
||||
} catch (e) {
|
||||
updateError.value = errorMessage(e, "The update source couldn't be changed.");
|
||||
}
|
||||
@@ -613,35 +655,11 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
Updates from
|
||||
</legend>
|
||||
<div class="mt-2 flex flex-col gap-2">
|
||||
<label class="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
type="radio"
|
||||
class="mt-1"
|
||||
name="update-source"
|
||||
:checked="source === null"
|
||||
@change="switchSource(null)"
|
||||
/>
|
||||
<label v-for="o in sourceOptions" :key="o.title" class="flex items-start gap-2 text-sm">
|
||||
<input type="radio" class="mt-1" name="update-source" :checked="o.checked" @change="o.pick()" />
|
||||
<span>
|
||||
<span class="font-medium">Fabled-Git</span>
|
||||
<span class="block text-neutral-500 dark:text-neutral-400">
|
||||
Where Inkwell is published, on the channel below.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
type="radio"
|
||||
class="mt-1"
|
||||
name="update-source"
|
||||
:checked="source !== null"
|
||||
@change="switchSource(offeredServer)"
|
||||
/>
|
||||
<span>
|
||||
<span class="font-medium">{{ offeredServer }}</span>
|
||||
<span class="block text-neutral-500 dark:text-neutral-400">
|
||||
The build that server holds. It passes on official builds only: every
|
||||
update is checked against the signature built into this app first.
|
||||
</span>
|
||||
<span class="font-medium">{{ o.title }}</span>
|
||||
<span class="block text-neutral-500 dark:text-neutral-400">{{ o.detail }}</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
@@ -653,36 +671,11 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
Channel
|
||||
</legend>
|
||||
<div class="mt-2 flex flex-col gap-2">
|
||||
<label class="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
type="radio"
|
||||
class="mt-1"
|
||||
name="update-channel"
|
||||
value="stable"
|
||||
:checked="channel === 'stable'"
|
||||
@change="switchChannel('stable')"
|
||||
/>
|
||||
<label v-for="o in channelOptions" :key="o.title" class="flex items-start gap-2 text-sm">
|
||||
<input type="radio" class="mt-1" name="update-channel" :checked="o.checked" @change="o.pick()" />
|
||||
<span>
|
||||
<span class="font-medium">Stable</span>
|
||||
<span class="block text-neutral-500 dark:text-neutral-400">
|
||||
Released versions only.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<label class="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
type="radio"
|
||||
class="mt-1"
|
||||
name="update-channel"
|
||||
value="dev"
|
||||
:checked="channel === 'dev'"
|
||||
@change="switchChannel('dev')"
|
||||
/>
|
||||
<span>
|
||||
<span class="font-medium">Development</span>
|
||||
<span class="block text-neutral-500 dark:text-neutral-400">
|
||||
Every build that passes CI. Newer, and less tested.
|
||||
</span>
|
||||
<span class="font-medium">{{ o.title }}</span>
|
||||
<span class="block text-neutral-500 dark:text-neutral-400">{{ o.detail }}</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user