feat(rail): edit title & open user notes
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user