Add note history to make it easier to use the same notes for several clock-ins - #3
Conversation
This also cleans up some of the code around the isCategoryFound and isSubcategoryFound logic.
This is to prevent issue where user may accidentally clock into a new subcat without realizing the notes field auto-populated
There was a problem hiding this comment.
Pull request overview
Adds a “recent notes” (note history) feature to the clock-in dashboard so users can quickly reuse previously-entered notes per subcategory, backed by a new controller endpoint and route.
Changes:
- Added a new GET endpoint to fetch recent notes for a given subcategory.
- Added dashboard UI controls to cycle through recent notes and clear the notes field.
- Added client-side fetching/caching logic to auto-populate notes based on the selected category/subcategory.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| routes/web.php | Registers a new /recent-notes/{subcategory_id} route exposing the recent-notes API. |
| resources/js/Pages/Dashboard.vue | Adds the note-history UI and fetch/cycle behavior tied to category/subcategory selection. |
| app/Http/Controllers/ClockInOutController.php | Implements getRecentNotes() returning latest and a de-duplicated history payload. |
Suppressed comments (1)
resources/js/Pages/Dashboard.vue:248
- When
data.latestis blank,getNotesHistory()forcibly clearsform.notes. This can unexpectedly erase notes the user has already typed when switching categories/subcategories. Only auto-populate when there is a non-empty latest note and the notes field is still empty; otherwise leave the user's input untouched.
// Auto-populate only if the latest note wasn't blank
if (data.latest && data.latest.trim() !== "") {
this.isCyclingHistory = true; // Prevent the notes watcher from resetting the index
this.form.notes = data.latest;
this.historyIndex = 0; // Reset to the first item in the history
} else {
this.form.notes = ""; // Clear notes if no history is found for subcategory
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -147,6 +137,14 @@ export default { | |||
| }, | |||
There was a problem hiding this comment.
Unrelated to PR
| if (!subId) { | ||
| this.lastFetchedSubId = null; | ||
| this.form.notes = ""; // Clear notes if subcategory isn't recognized | ||
| return; | ||
| } |
There was a problem hiding this comment.
That's fine. It's the last field, so less likely. And it's a trade-off to help clear old notes from other sub-category's notes.
| this.form.manualTime = dateTimeUTCFormatted; | ||
| // Close modal and remove event listener | ||
| document.querySelector('.modal').style.display = 'none'; | ||
| modalFooter.removeEventListener('click', saveTime); |
There was a problem hiding this comment.
Pre-existing and unrelated to this PR.
| $raw = TempLog::where('user_id', auth()->user()->id) | ||
| ->where('subcategory_id', $subcategory_id) | ||
| ->orderBy('created_at', 'desc') | ||
| ->take(20) | ||
| ->pluck('notes'); | ||
|
|
||
| return response()->json([ | ||
| 'latest' => $raw->first(), | ||
| 'history' => $raw->filter(fn($n) => !empty(trim($n)))->unique()->values() | ||
| ]); |
There was a problem hiding this comment.
This shouldn't be an issue. We don't actually need 20 and the null issue can't actually happen.
| <a v-if="notesHistory.length > 0" href="#" @click.prevent="cycleNotesHistory" title="Cycle Recent Notes"> | ||
| <i class="fas fa-clock-rotate-left"></i> | ||
| </a> | ||
| <a v-if="form.notes" href="#" @click.prevent="clearNotes" title="Clear Notes"> | ||
| <i class="fas fa-times"></i> |
This pull request introduces a new feature for retrieving recent notes associated with a subcategory. The main changes are the addition of a note history button, a controller method to fetch recent notes, and the corresponding route to expose this functionality via the API.
Details
getRecentNotesmethod toClockInOutControllerthat returns the 20 most recent notes (history) and the latest note for a given subcategory, filtering out empty notes and ensuring uniqueness in the history./recent-notes/{subcategory_id}inroutes/web.phpto expose the recent notes retrieval functionality.https://trello.com/c/qlPlr7nu