feat(rail): edit title & open user notes

This commit is contained in:
Fernando López Guevara
2024-01-06 11:38:34 -03:00
parent a93ebd3861
commit 2e23b3ae06
12 changed files with 129 additions and 23 deletions
+8 -3
View File
@@ -43,9 +43,14 @@ export function formatCreatedAt(time: number, message: boolean = false) {
return formated;
}
export function displayNpub(pubkey: string, len: number, separator?: string) {
export function displayNpub(pubkey: string, len: number = 16, separator?: string) {
const npub = pubkey.startsWith('npub1') ? pubkey : (nip19.npubEncode(pubkey) as string);
if (npub.length <= len) return npub;
return cropText(npub, len, separator);
}
export function cropText(text: string, len: number = 16, separator?: string) {
if (text.length <= len) return text;
separator = separator || ' ... ';
@@ -54,7 +59,7 @@ export function displayNpub(pubkey: string, len: number, separator?: string) {
frontChars = Math.ceil(charsToShow / 2),
backChars = Math.floor(charsToShow / 2);
return npub.substr(0, frontChars) + separator + npub.substr(npub.length - backChars);
return text.substr(0, frontChars) + separator + text.substr(text.length - backChars);
}
// convert number to K, M, B, T, etc.
+25 -1
View File
@@ -67,5 +67,29 @@ export function useWidget() {
},
});
return { addWidget, replaceWidget, removeWidget };
const renameWidget = useMutation({
mutationFn: async ({ id, title }: { id: string; title: string }) => {
// Cancel any outgoing refetches
await queryClient.cancelQueries({ queryKey: ['widgets'] });
// Snapshot the previous value
const prevWidgets = queryClient.getQueryData(['widgets']);
// Optimistically update to the new value
queryClient.setQueryData(['widgets'], (prev: Widget[]) =>
prev.filter((t) => t.id !== id)
);
// Update in database
await ark.renameWidget(id, title);
// Return a context object with the snapshotted value
return { prevWidgets };
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['widgets'] });
},
});
return { addWidget, replaceWidget, removeWidget, renameWidget };
}