Remove the New Note and Delete buttons from default view, moved functionality to File menu
This commit is contained in:
parent
19aeb40863
commit
aea4399e3b
5 changed files with 251 additions and 34 deletions
|
|
@ -26,7 +26,7 @@ The application layout follows a classic 3-column / top-menu layout rendered cle
|
|||
+-----------------------------------------------------------------------------------+
|
||||
| [File] [Edit] [View] [Theme] [Help] [EternaLibre Notes v{CARGO_PKG_VERSION}] | <-- Classic Menu Bar; version is manifest-derived
|
||||
+-----------------------------------------------------------------------------------+
|
||||
| [+ New Note] [Delete] | Search... | Theme: [ Dark v ] | <-- Apple-style Toolbar
|
||||
| Search... | Theme: [ Dark v ] | <-- Apple-style Toolbar
|
||||
+-------------------+-----------------------------------+---------------------------+
|
||||
| Sidebar | Editor Pane | Live Preview Pane |
|
||||
| ----------------- | --------------------------------- | ------------------------- |
|
||||
|
|
@ -46,7 +46,7 @@ The application layout follows a classic 3-column / top-menu layout rendered cle
|
|||
1. **Fluid Typography**: Inter/SF Pro or high-quality system sans-serif for the interface; Monospace for Markdown source; clean sans for HTML preview.
|
||||
2. **Subtle Elevation & Borders**: Soft 1px borders using `--ui-border` / `--app-bg` contrast shades rather than heavy drop shadows.
|
||||
3. **Apple-style Note List**: Sidebar lists show note title, relative timestamp, and a single line preview snippet in muted text.
|
||||
4. **Progressive Enhancement**: Note editing, server-side search, weather-location settings, and the login form work with JavaScript disabled via HTML forms and page reloads. The visible theme selector currently submits through Alpine's change handler, so theme changes from the toolbar require JavaScript. Menu dropdowns, mobile tab switching, live preview, drag-and-drop re-filing, and automatic opening of the PDF print dialog are also JavaScript-dependent.
|
||||
4. **Progressive Enhancement**: Note editing, server-side search, weather-location settings, and the login form work with JavaScript disabled via HTML forms and page reloads. New Note and Delete live in the `File` menu for everyone; a `<noscript>` toolbar group keeps the same plain forms available when scripting is disabled, because the menu itself cannot open. The visible theme selector currently submits through Alpine's change handler, so theme changes from the toolbar require JavaScript. Menu dropdowns, mobile tab switching, live preview, drag-and-drop re-filing, and automatic opening of the PDF print dialog are also JavaScript-dependent.
|
||||
|
||||
When no note is open, the editor pane renders a welcome dashboard with up to five recently updated notes from the current sidebar result set. Its optional weather card submits the location and a Celsius/Fahrenheit radio as a plain form; the server stores the location in `.weather_location` and the unit in `.weather_units` under the notes directory and sends the location to wttr.in only when the dashboard or the dedicated `/weather` page is requested. The `format=j1` response keeps both scales so switching units reuses the cache without refetching. Results and failed checks are cached for 15 minutes, and requests time out after four seconds. Without a saved location, no weather request is made. The table shows current conditions as its top row followed by each forecast date wttr.in returns (currently three dates including today); render what is present rather than assuming a five-day horizon.
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ Two touch-specific details follow from the long press. `.note-item` sets `-webki
|
|||
|
||||
Neither entry point may carry `.desktop-only`. That class hides at `max-width: 600px`, and the bar is already hidden above 600px by a `min-width` query; adding the class composes to hiding it at *every* width and phones lose re-filing entirely. That shipped once. No Rust test can observe `display: none`, so `move_entry_points_are_not_desktop_only` pins the markup contract instead. All forms post the same `folder` field, where an empty value means the root. See §11 for the rename rule that makes a move destructive if done any other way, and for why user-supplied folder names force the flyout's `max-width`/wrapping.
|
||||
|
||||
The status bar currently displays `Saved` as a static label; it does not track unsaved editor changes. The toolbar has no separate Preview button: Preview is a pane and a mobile tab.
|
||||
The status bar currently displays `Saved` as a static label; it does not track unsaved editor changes. The toolbar has no separate Preview button: Preview is a pane and a mobile tab. It also carries no New Note or Delete buttons; both are `File` menu entries, with the `<noscript>` fallback described above for the scripting-disabled case.
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -330,7 +330,7 @@ toggleSubmenu(name, event) {
|
|||
|
||||
Dropdowns are revealed by a class on the trigger rather than `x-show`, because Alpine's `x-show` works by *removing* an inline `display` when true, at which point the stylesheet's `display: none` would take over again and the menu would stay hidden. Top-level menus use `.menu-item.open`; the File export flyout uses `.menu-submenu-list.open`. This also means menus stay closed if JavaScript never loads, instead of all five appearing at once.
|
||||
|
||||
**Consequence: the menu bar requires JavaScript.** Since `.open` is applied by Alpine, no dropdown opens without it. This is a deliberate trade-off (see section 2, directive 4). Note CRUD and server-side search remain usable without JavaScript, but the visible theme selector and menu-based actions do not. If you change this, keep `.desktop-only`, `.open`, and submenu state consistent.
|
||||
**Consequence: the menu bar requires JavaScript.** Since `.open` is applied by Alpine, no dropdown opens without it. This is a deliberate trade-off (see section 2, directive 4). Note CRUD and server-side search remain usable without JavaScript because the toolbar carries a `<noscript>` group with the same New Note/Delete forms; the visible theme selector and the rest of the menu-based actions do not. If you change this, keep `.desktop-only`, `.open`, and submenu state consistent.
|
||||
|
||||
Outside-click detection is a manual `document` listener in an `init()` hook with a matching `destroy()`. `Escape` closes any open menu.
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ app from making that request.
|
|||
|
||||
- **TOTP-locked by default** — authenticator app required on first launch and after every restart
|
||||
- **Server-side rendered** with Axum and Maud — fast, type-safe HTML templates
|
||||
- **Uses a small amount of JavaScript** — note editing, search, and the login form are plain HTML; the menus, mobile tabs, live preview, and drag-and-drop re-filing are the JS-dependent parts
|
||||
- **Uses a small amount of JavaScript** — note editing, search, create/delete, and the login form are plain HTML; the menus, mobile tabs, live preview, and drag-and-drop re-filing are the JS-dependent parts. With JavaScript disabled, a `<noscript>` toolbar fallback keeps `New Note` and `Delete` available because the `File` menu cannot open
|
||||
- **Alpine.js enhancements** — live Markdown preview, instant search, keyboard shortcuts
|
||||
- **File-based storage** — notes are persisted as Markdown files in `notes/`
|
||||
- **Virtual folders** — organize notes into folders without real directories; folders are encoded as `[Folder]uuid.md` filename prefixes
|
||||
|
|
@ -95,7 +95,7 @@ Root notes (no folder) keep the plain `uuid.md` format. Folders exist only when
|
|||
|
||||
**Creating a folder:** click `+ New Folder` in the sidebar, type a name, and the app creates a new note in that folder and opens it.
|
||||
|
||||
**Filtering:** click a folder name in the sidebar to see only that folder's notes. Click **All Notes** to see everything grouped by folder. When a folder is active, the **+ New Note** button creates notes in that folder.
|
||||
**Filtering:** click a folder name in the sidebar to see only that folder's notes. Click **All Notes** to see everything grouped by folder. When a folder is active, **File → New Note** creates notes in that folder.
|
||||
|
||||
**Moving a note between folders:** drag it from the sidebar onto a folder, pick `File → Move to Folder…`, or use the Move control under the editor on a phone. Dropping a note on **All Notes** — or choosing **Unfiled** — takes it back out of its folder.
|
||||
|
||||
|
|
|
|||
123
src/pages.rs
123
src/pages.rs
|
|
@ -93,7 +93,12 @@ pub fn render_app(
|
|||
script defer src=(base.url("/static/alpine.min.js")) {}
|
||||
}
|
||||
body x-data="app()" x-on:keydown="handleKeydown($event)" {
|
||||
(render_menu_bar(base, current_note, folder_ctx.folders))
|
||||
(render_menu_bar(
|
||||
base,
|
||||
current_note,
|
||||
folder_ctx.folders,
|
||||
folder_ctx.active_folder,
|
||||
))
|
||||
(render_toolbar(
|
||||
current_note,
|
||||
page.query,
|
||||
|
|
@ -178,7 +183,57 @@ fn render_tab_bar(default_tab: &str, has_note: bool) -> Markup {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_menu_bar(base: &Base<'_>, current_note: Option<&Note>, folders: &[String]) -> Markup {
|
||||
/// Plain form that creates a note in the folder currently being viewed.
|
||||
///
|
||||
/// Shared by the File menu and the `<noscript>` toolbar fallback. The hidden
|
||||
/// `folder` input is why this is a helper: the File menu previously omitted it
|
||||
/// and silently created a root note even while a folder was active.
|
||||
fn render_new_note_form(
|
||||
active_folder: Option<&str>,
|
||||
button_class: Option<&str>,
|
||||
label: &str,
|
||||
base: &Base<'_>,
|
||||
) -> Markup {
|
||||
html! {
|
||||
form action=(base.url("/notes")) method="post" {
|
||||
@if let Some(folder) = active_folder {
|
||||
input type="hidden" name="folder" value=(folder);
|
||||
}
|
||||
button type="submit" class=[button_class] { (label) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete form with the confirmation prompt.
|
||||
///
|
||||
/// Shared by the File menu and the `<noscript>` toolbar fallback so the
|
||||
/// destructive POST and its confirmation label cannot drift apart.
|
||||
fn render_delete_note_form(
|
||||
note: &Note,
|
||||
button_class: &str,
|
||||
label: &str,
|
||||
base: &Base<'_>,
|
||||
) -> Markup {
|
||||
html! {
|
||||
form
|
||||
action=(base.url(&format!("/notes/{}", note.id)))
|
||||
method="post"
|
||||
data-delete-label=(format!("[{}-{}]",
|
||||
note.folder.as_deref().unwrap_or("Unfiled"),
|
||||
note.title))
|
||||
onsubmit="return confirm('Are you sure you want to delete ' + this.dataset.deleteLabel + '? This cannot be undone.')" {
|
||||
input type="hidden" name="_method" value="delete";
|
||||
button type="submit" class=(button_class) { (label) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_menu_bar(
|
||||
base: &Base<'_>,
|
||||
current_note: Option<&Note>,
|
||||
folders: &[String],
|
||||
active_folder: Option<&str>,
|
||||
) -> Markup {
|
||||
let theme_return = theme_return_path(current_note);
|
||||
let weather_href = dedicated_page_href(base, "/weather", current_note);
|
||||
let welcome_href = dedicated_page_href(base, "/welcome", current_note);
|
||||
|
|
@ -191,11 +246,18 @@ fn render_menu_bar(base: &Base<'_>, current_note: Option<&Note>, folders: &[Stri
|
|||
span { "File" }
|
||||
ul class="menu-dropdown file-menu-dropdown" {
|
||||
li {
|
||||
form action=(base.url("/notes")) method="post" {
|
||||
button type="submit" { "New Note" }
|
||||
(render_new_note_form(
|
||||
active_folder,
|
||||
Some("menu-action"),
|
||||
"New Note",
|
||||
base,
|
||||
))
|
||||
}
|
||||
li {
|
||||
button class="menu-action" x-on:click="saveCurrentNote()" {
|
||||
"Save Note"
|
||||
}
|
||||
}
|
||||
li { button x-on:click="saveCurrentNote()" { "Save Note" } }
|
||||
li { hr; }
|
||||
li {
|
||||
a href=(base.url("/export")) { "Export All Notes" }
|
||||
|
|
@ -280,6 +342,19 @@ fn render_menu_bar(base: &Base<'_>, current_note: Option<&Note>, folders: &[Stri
|
|||
aria-disabled="true" { "Move to Folder…" }
|
||||
}
|
||||
}
|
||||
@if let Some(note) = current_note {
|
||||
// Destructive action last, behind a separator, so it
|
||||
// is never adjacent to New Note.
|
||||
li { hr; }
|
||||
li {
|
||||
(render_delete_note_form(
|
||||
note,
|
||||
"menu-danger menu-action",
|
||||
"Delete Note…",
|
||||
base,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
li class="menu-item" tabindex="0"
|
||||
|
|
@ -392,23 +467,21 @@ fn render_toolbar(
|
|||
let theme_return = theme_return_path(current_note);
|
||||
html! {
|
||||
div class="toolbar" {
|
||||
div class="toolbar-group" {
|
||||
form action=(base.url("/notes")) method="post" {
|
||||
@if let Some(folder) = active_folder {
|
||||
input type="hidden" name="folder" value=(folder);
|
||||
}
|
||||
button type="submit" class="btn btn-primary" { "+ New Note" }
|
||||
}
|
||||
@if let Some(note) = current_note {
|
||||
form
|
||||
action=(base.url(&format!("/notes/{}", note.id)))
|
||||
method="post"
|
||||
data-delete-label=(format!("[{}-{}]",
|
||||
note.folder.as_deref().unwrap_or("Unfiled"),
|
||||
note.title))
|
||||
onsubmit="return confirm('Are you sure you want to delete ' + this.dataset.deleteLabel + '? This cannot be undone.')" {
|
||||
input type="hidden" name="_method" value="delete";
|
||||
button type="submit" class="btn btn-danger" { "Delete" }
|
||||
// Both actions live in the File menu now. The menu cannot open
|
||||
// without JavaScript, so keep plain-form equivalents here for the
|
||||
// no-script case. The inner div matters: styling `noscript` itself
|
||||
// can expose its text content in engines that render it as text
|
||||
// when scripting is enabled.
|
||||
noscript {
|
||||
div class="toolbar-group" {
|
||||
(render_new_note_form(
|
||||
active_folder,
|
||||
Some("btn btn-primary"),
|
||||
"+ New Note",
|
||||
base,
|
||||
))
|
||||
@if let Some(note) = current_note {
|
||||
(render_delete_note_form(note, "btn btn-danger", "Delete", base))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -958,7 +1031,7 @@ pub fn render_weather_page(
|
|||
script defer src=(base.url("/static/alpine.min.js")) {}
|
||||
}
|
||||
body class="weather-page" x-data="app()" x-on:keydown="handleKeydown($event)" {
|
||||
(render_menu_bar(base, None, &[]))
|
||||
(render_menu_bar(base, None, &[], None))
|
||||
main class="weather-page-main" {
|
||||
p class="welcome-eyebrow" { "MOBILE WEATHER" }
|
||||
h1 { "Weather" }
|
||||
|
|
@ -1000,7 +1073,7 @@ pub fn render_welcome_page(
|
|||
script defer src=(base.url("/static/alpine.min.js")) {}
|
||||
}
|
||||
body class="welcome-page" x-data="app()" x-on:keydown="handleKeydown($event)" {
|
||||
(render_menu_bar(base, None, &[]))
|
||||
(render_menu_bar(base, None, &[], None))
|
||||
main class="welcome-page-main welcome-state" {
|
||||
(render_welcome_heading(quotes))
|
||||
(render_recent_card(recent_notes, base))
|
||||
|
|
@ -1187,7 +1260,7 @@ pub fn render_about(theme_name: &str, base: &Base<'_>) -> Markup {
|
|||
// The About page has no notes pane and no selected note, so
|
||||
// there is nothing to move; an empty folder list renders the
|
||||
// submenu trigger disabled.
|
||||
(render_menu_bar(base, None, &[]))
|
||||
(render_menu_bar(base, None, &[], None))
|
||||
main {
|
||||
h1 { "EternaLibre Notes" }
|
||||
p class="tagline" { "Free notes, forever." }
|
||||
|
|
|
|||
|
|
@ -134,6 +134,13 @@ button, input, select, textarea {
|
|||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Destructive File menu entry. Uses the already contrast-guarded danger color
|
||||
from `Theme::button_colors(1)`, which falls back to the foreground on
|
||||
palettes where bright red is not legible. */
|
||||
.menu-dropdown .menu-danger {
|
||||
color: var(--btn-danger-bg);
|
||||
}
|
||||
|
||||
/* Marks a View menu item whose pane is currently collapsed, so the state is
|
||||
readable at a glance instead of only via the Hide/Show label. */
|
||||
.menu-dropdown button.active-view::before {
|
||||
|
|
@ -1658,6 +1665,17 @@ button, input, select, textarea {
|
|||
max-height: calc(100dvh - 56px);
|
||||
}
|
||||
|
||||
/* New Note, Save Note, and Delete now live in the File menu, so the primary
|
||||
actions need the same 44px touch target the toolbar buttons used to carry.
|
||||
Scoped to `.menu-action` rather than the whole dropdown: stretching every
|
||||
export and submenu entry too made the File menu taller than a landscape
|
||||
phone viewport, and it cannot scroll because its flyouts must escape. */
|
||||
.file-menu-dropdown .menu-action {
|
||||
min-height: 44px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -690,10 +690,15 @@ async fn delete_form_has_confirmation_prompt() {
|
|||
let (status, body) = f.get_authed(&format!("/notes/{id}")).await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
|
||||
// Find the delete form by its note-specific action
|
||||
let form_start = body
|
||||
.find(&format!("action=\"/notes/{id}\""))
|
||||
// Anchor on the delete label rather than the action: the editor's save
|
||||
// form posts to the same `/notes/{id}` route, and the noscript toolbar
|
||||
// fallback carries a second delete form.
|
||||
let label_at = body
|
||||
.find("data-delete-label")
|
||||
.expect("delete form should exist");
|
||||
let form_start = body[..label_at]
|
||||
.rfind("<form")
|
||||
.expect("delete form should open");
|
||||
let form_end = body[form_start..]
|
||||
.find("</form>")
|
||||
.map(|i| form_start + i + "</form>".len())
|
||||
|
|
@ -1455,6 +1460,127 @@ async fn save_note_is_in_file_menu() {
|
|||
);
|
||||
}
|
||||
|
||||
/// New Note and Delete belong to the File menu on every width, and New Note
|
||||
/// must respect the folder currently being viewed.
|
||||
#[tokio::test]
|
||||
async fn file_menu_holds_new_note_and_delete() {
|
||||
let f = Fixture::provisioned("file-menu-actions");
|
||||
let (_, _, loc) = f.post_authed("/folders", "name=Projects").await;
|
||||
let loc = loc.expect("folder creation redirects");
|
||||
let id = loc.rsplit('/').next().unwrap().to_string();
|
||||
|
||||
let (status, body) = f.get_authed(&format!("/notes/{id}")).await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
|
||||
// Scope to the whole File menu, including the nested submenu lists.
|
||||
let file_start = body
|
||||
.find("toggleMenu('file')")
|
||||
.expect("the File menu should exist");
|
||||
let file_end = body[file_start..]
|
||||
.find("toggleMenu('edit')")
|
||||
.map(|i| file_start + i)
|
||||
.expect("the File menu should end before the Edit menu");
|
||||
let file_menu = &body[file_start..file_end];
|
||||
|
||||
let create_at = file_menu
|
||||
.find("action=\"/notes\"")
|
||||
.expect("New Note should be in the File menu");
|
||||
let create_end = file_menu[create_at..]
|
||||
.find("</form>")
|
||||
.map(|i| create_at + i)
|
||||
.expect("the New Note form should close");
|
||||
let create_form = &file_menu[create_at..create_end];
|
||||
assert!(
|
||||
create_form.contains("name=\"folder\""),
|
||||
"New Note must submit the active folder"
|
||||
);
|
||||
assert!(
|
||||
create_form.contains("value=\"Projects\""),
|
||||
"New Note should inherit the folder being viewed"
|
||||
);
|
||||
assert!(
|
||||
create_form.contains("New Note"),
|
||||
"the File menu should label the action New Note"
|
||||
);
|
||||
|
||||
let delete_at = file_menu
|
||||
.find("data-delete-label")
|
||||
.expect("Delete should be in the File menu");
|
||||
let delete_start = file_menu[..delete_at]
|
||||
.rfind("<form")
|
||||
.expect("the delete form should open");
|
||||
let delete_end = file_menu[delete_start..]
|
||||
.find("</form>")
|
||||
.map(|i| delete_start + i)
|
||||
.expect("the delete form should close");
|
||||
let delete_form = &file_menu[delete_start..delete_end];
|
||||
assert!(
|
||||
delete_form.contains("value=\"delete\"") && delete_form.contains("_method"),
|
||||
"the File menu delete must still post _method=delete"
|
||||
);
|
||||
assert!(
|
||||
delete_form.contains("Delete Note…"),
|
||||
"the File menu should label the destructive action Delete Note…"
|
||||
);
|
||||
assert!(
|
||||
delete_form.contains("[Projects-"),
|
||||
"the confirmation label should include the folder"
|
||||
);
|
||||
}
|
||||
|
||||
/// The visible toolbar no longer carries create/delete actions. They remain as
|
||||
/// plain forms inside `<noscript>` so CRUD survives with JavaScript disabled,
|
||||
/// when the File menu cannot open.
|
||||
#[tokio::test]
|
||||
async fn toolbar_actions_are_a_noscript_fallback() {
|
||||
let f = Fixture::provisioned("toolbar-noscript-actions");
|
||||
let id = f.create_note().await;
|
||||
|
||||
let (status, body) = f.get_authed(&format!("/notes/{id}")).await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
|
||||
let toolbar_start = body
|
||||
.find("class=\"toolbar\"")
|
||||
.expect("the toolbar should exist");
|
||||
let tab_start = body[toolbar_start..]
|
||||
.find("class=\"tab-bar\"")
|
||||
.map(|i| toolbar_start + i)
|
||||
.expect("the tab bar should follow the toolbar");
|
||||
let toolbar = &body[toolbar_start..tab_start];
|
||||
|
||||
let noscript_start = toolbar
|
||||
.find("<noscript>")
|
||||
.expect("the toolbar should carry a noscript fallback");
|
||||
let noscript_end = toolbar
|
||||
.find("</noscript>")
|
||||
.map(|i| i + "</noscript>".len())
|
||||
.expect("the noscript fallback should close");
|
||||
let fallback = &toolbar[noscript_start..noscript_end];
|
||||
assert!(
|
||||
fallback.contains("btn btn-primary") && fallback.contains("+ New Note"),
|
||||
"no-JS fallback should keep the New Note button"
|
||||
);
|
||||
assert!(
|
||||
fallback.contains("btn btn-danger") && fallback.contains("Delete"),
|
||||
"no-JS fallback should keep the Delete button"
|
||||
);
|
||||
assert!(
|
||||
fallback.contains("action=\"/notes\"")
|
||||
&& fallback.contains("_method")
|
||||
&& fallback.contains("value=\"delete\""),
|
||||
"no-JS fallback should submit the same create and delete forms"
|
||||
);
|
||||
|
||||
// Everything after the fallback is the ordinary visible toolbar.
|
||||
let visible = &toolbar[noscript_end..];
|
||||
for forbidden in ["btn-primary", "btn-danger", "action=\"/notes\""] {
|
||||
assert!(
|
||||
!visible.contains(forbidden),
|
||||
"the visible toolbar should not contain {forbidden}:\n{visible}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// On mobile, the folder nav and note list scroll independently within their
|
||||
/// own bounded areas. The sidebar itself does not scroll, and the pull-tab
|
||||
/// toggle stays visible above the scrolling folder list.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue