mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-20 07:24:23 +01:00
feat: auto resize text input
This commit is contained in:
@@ -64,6 +64,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
tailwindcss: {
|
tailwindcss: {
|
||||||
whitelist: [
|
whitelist: [
|
||||||
|
'h-fill-available',
|
||||||
'form-input',
|
'form-input',
|
||||||
// rabbit parts
|
// rabbit parts
|
||||||
'nostr-textnote',
|
'nostr-textnote',
|
||||||
|
|||||||
@@ -75,6 +75,12 @@ const NotePostForm: Component<NotePostFormProps> = (props) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const resizeTextArea = () => {
|
||||||
|
if (textAreaRef == null) return;
|
||||||
|
textAreaRef.style.height = 'auto';
|
||||||
|
textAreaRef.style.height = `${textAreaRef.scrollHeight}px`;
|
||||||
|
};
|
||||||
|
|
||||||
const uploadFilesMutation = createMutation({
|
const uploadFilesMutation = createMutation({
|
||||||
mutationKey: ['uploadFiles'],
|
mutationKey: ['uploadFiles'],
|
||||||
mutationFn: (files: File[]) => {
|
mutationFn: (files: File[]) => {
|
||||||
@@ -84,6 +90,7 @@ const NotePostForm: Component<NotePostFormProps> = (props) => {
|
|||||||
if (result.status === 'fulfilled') {
|
if (result.status === 'fulfilled') {
|
||||||
console.log('succeeded to upload', result);
|
console.log('succeeded to upload', result);
|
||||||
setText((current) => `${current} ${result.value.imageUrl}`);
|
setText((current) => `${current} ${result.value.imageUrl}`);
|
||||||
|
resizeTextArea();
|
||||||
} else {
|
} else {
|
||||||
console.error('failed to upload', result);
|
console.error('failed to upload', result);
|
||||||
}
|
}
|
||||||
@@ -102,6 +109,9 @@ const NotePostForm: Component<NotePostFormProps> = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
|
if (text().length === 0) return;
|
||||||
|
if (publishTextNoteMutation.isLoading) return;
|
||||||
|
|
||||||
const pubkey = getPubkey();
|
const pubkey = getPubkey();
|
||||||
if (pubkey == null) {
|
if (pubkey == null) {
|
||||||
console.error('pubkey is not available');
|
console.error('pubkey is not available');
|
||||||
@@ -117,6 +127,11 @@ const NotePostForm: Component<NotePostFormProps> = (props) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleInput: JSX.EventHandler<HTMLTextAreaElement, InputEvent> = (ev) => {
|
||||||
|
setText(ev.currentTarget.value);
|
||||||
|
resizeTextArea();
|
||||||
|
};
|
||||||
|
|
||||||
const handleSubmit: JSX.EventHandler<HTMLFormElement, Event> = (ev) => {
|
const handleSubmit: JSX.EventHandler<HTMLFormElement, Event> = (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
submit();
|
submit();
|
||||||
@@ -140,6 +155,7 @@ const NotePostForm: Component<NotePostFormProps> = (props) => {
|
|||||||
|
|
||||||
const handleDrop: JSX.EventHandler<HTMLTextAreaElement, DragEvent> = (ev) => {
|
const handleDrop: JSX.EventHandler<HTMLTextAreaElement, DragEvent> = (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
if (uploadFilesMutation.isLoading) return;
|
||||||
const files = [...(ev?.dataTransfer?.files ?? [])];
|
const files = [...(ev?.dataTransfer?.files ?? [])];
|
||||||
uploadFilesMutation.mutate(files);
|
uploadFilesMutation.mutate(files);
|
||||||
};
|
};
|
||||||
@@ -186,7 +202,7 @@ const NotePostForm: Component<NotePostFormProps> = (props) => {
|
|||||||
class="rounded border-none"
|
class="rounded border-none"
|
||||||
rows={4}
|
rows={4}
|
||||||
placeholder={placeholder(mode())}
|
placeholder={placeholder(mode())}
|
||||||
onInput={(ev) => setText(ev.currentTarget.value)}
|
onInput={handleInput}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
onDragOver={handleDragOver}
|
onDragOver={handleDragOver}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
|
|||||||
@@ -23,3 +23,7 @@ code {
|
|||||||
.link {
|
.link {
|
||||||
@apply underline text-blue-500;
|
@apply underline text-blue-500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.h-fill-available {
|
||||||
|
height: -webkit-fill-available;
|
||||||
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ const Home: Component = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="flex h-screen w-screen flex-row overflow-hidden">
|
<div class="h-fill-available flex h-screen w-screen flex-row overflow-hidden">
|
||||||
<SideBar />
|
<SideBar />
|
||||||
<div class="flex h-full flex-row overflow-y-hidden overflow-x-scroll">
|
<div class="flex h-full flex-row overflow-y-hidden overflow-x-scroll">
|
||||||
<Column name="ホーム" columnIndex={1} width="widest">
|
<Column name="ホーム" columnIndex={1} width="widest">
|
||||||
|
|||||||
Reference in New Issue
Block a user