Skip to content
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
6 changes: 3 additions & 3 deletions resources/js/Components/Comments/Commentable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const commentsLeft = ref(props.commentsCount);
const idToChildren = ref(new Map());
const sortBy = ref(props.sortByInitialValue);
const hasOpenedComments = ref(false);
const commentRefs = ref(new Map());

const createdNewCommentCallback = (newComment, userData) => {
console.log("Created a new comment!", newComment, userData);
Expand All @@ -59,9 +60,7 @@ const createdNewCommentCallback = (newComment, userData) => {

// Ensure DOM updates are complete, then scroll to the new comment
nextTick(() => {
const newCommentElement = document.getElementById(
"comment_" + newComment.id
);
const newCommentElement = commentRefs.value.get(`comment_${newComment.id}`);
if (newCommentElement) {
newCommentElement.scrollIntoView({
behavior: "smooth",
Expand All @@ -76,6 +75,7 @@ provide("commentableId", props.commentableId);
provide("commentableKey", props.commentableKey);
provide("users", readonly(usersMap));
provide("createdNewCommentCallback", createdNewCommentCallback);
provide("commentRefs", commentRefs);

const showEmptyState = computed(() => {
return (
Expand Down
30 changes: 25 additions & 5 deletions resources/js/Pages/Resources/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,25 @@ const { clearLocalStorage } = useLocalStorageSaver(

const showReset = ref(false);
const stepperValue = ref("1");
const formRef = ref(null);

const toast = useToast();

const scrollToForm = () => {
if (formRef.value) {
formRef.value.scrollIntoView({
behavior: "smooth",
block: "start",
inline: "nearest",
});
}
};

const navigateToStep = (step) => {
stepperValue.value = step;
scrollToForm();
};

const resetForm = () => {
clearLocalStorage();
formData.reset();
Expand All @@ -70,7 +86,9 @@ const submitForm = () => {
toast.add({
severity: "error",
summary: "Error",
detail: errors ? Object.values(errors).flat().join(' ') : "An error occurred while creating the resource.",
detail: errors
? Object.values(errors).flat().join("\n")
: "An error occurred while creating the resource.",
life: 10000,
});
},
Expand Down Expand Up @@ -211,7 +229,9 @@ const handleFormChange = (newFormData) => {
</div>
<!-- Main Form Section -->
<div
ref="formRef"
class="bg-white h-min shadow-lg rounded-lg p-6 flex-1 max-w-full md:max-w-3xl min-w-0 md:min-w-[28rem] relative"
id="create-resource-form"
>
<!-- Move Reset button to top right -->
<div class="flex justify-end mb-2">
Expand All @@ -236,22 +256,22 @@ const handleFormChange = (newFormData) => {
<MandatoryFields
:formData="formData"
@change="handleFormChange"
@next="() => (stepperValue = '2')"
@next="() => navigateToStep('2')"
></MandatoryFields>
</StepPanel>
<StepPanel value="2">
<TopicsFields
:form="formData"
@change="handleFormChange"
@back="() => (stepperValue = '1')"
@next="() => (stepperValue = '3')"
@back="() => navigateToStep('1')"
@next="() => navigateToStep('3')"
></TopicsFields>
</StepPanel>
<StepPanel value="3">
<TagsFields
:form="formData"
@change="handleFormChange"
@back="() => (stepperValue = '2')"
@back="() => navigateToStep('2')"
@next="submitForm"
/>
</StepPanel>
Expand Down