Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remember posts #451

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Livewire/Questions/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public function maxContentLength(): int
return $this->isSharingUpdate ? 1000 : 255;
}

#[Computed]
public function draftKey(): string
{
return $this->parentId !== null && $this->parentId !== '' && $this->parentId !== '0'
? "reply_{$this->parentId}"
: 'post_new';
}

/**
* Refresh the component.
*/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@tailwindcss/forms": "^0.5.2",
"@tailwindcss/typography": "^0.5.12",
"alpinejs-notify": "^1.0.3",
"autosize": "^6.0.1",
"autoprefixer": "^10.4.19",
"axios": "^1.6.8",
"highlight.js": "^11.9.0",
Expand Down
15 changes: 5 additions & 10 deletions resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './bootstrap'

import autosize from 'autosize';
import focus from '@alpinejs/focus'
import notifications from 'alpinejs-notify'
import Sortable from 'sortablejs'
Expand All @@ -26,15 +26,10 @@ Alpine.directive('sortable', (el) => {
})

Alpine.directive('autosize', (el) => {
const offset = (el.offsetHeight - el.clientHeight) + 8
const resize = () => {
el.style.height = 'auto';
el.style.height = el.scrollHeight + offset + 'px';
};

el.addEventListener('input', resize);
el.resize = resize;
})
if (el) {
autosize(el);
}
});

import { shareProfile } from './share-profile.js'
Alpine.data('shareProfile', shareProfile)
Expand Down
31 changes: 22 additions & 9 deletions resources/views/livewire/questions/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,29 @@ class="mb-12 pt-4"
maxFileSize = {{ $this->maxFileSize }};
}'
class="relative group/menu">
<x-textarea
wire:model="content"
placeholder="{{ $this->placeholder }}"
maxlength="{{ $this->maxContentLength }}"
rows="3"
required
x-autosize
x-ref="content"
/>
<div x-data="{ content: $persist($wire.entangle('content')).as('{{ $this->draftKey }}') }">
<x-textarea
x-model="content"
placeholder="{{ $this->placeholder }}"
maxlength="{{ $this->maxContentLength }}"
rows="3"
required
x-autosize
x-ref="content"
/>
</div>

<div class="absolute top-0 right-0 mt-2 mr-2 group-hover/menu:inline-block hidden">
<button
title="Upload an image"
x-ref="imageButton"
:disabled="uploading || images.length >= uploadLimit"
class="rounded-lg bg-slate-800 text-sm text-slate-400 p-1.5 hover:text-pink-500"
:class="{'cursor-not-allowed text-pink-500': uploading || images.length >= uploadLimit}"
>
<x-heroicon-o-camera class="h-5 w-5"/>
</button>
</div>
<div
class="absolute top-0 right-0 mt-2 mr-2 group-hover/menu:inline-block hidden">
<button title="Upload an image" x-ref="imageButton"
Expand Down