Skip to content

Commit 6599a1b

Browse files
committed
refactor: Adopt granular item rendering and restore empty folder placeholder
Overhaul the directory rendering logic in the file browser by replacing monolithic template compilation with programmatic DOM element construction and individual item parsing. Previously, directory list rendering relied on a single template (`list.hbs`) that wrapped the outer `<ul>` element, handled list iteration (`{{#list}}`), and relied on the `mustache` package's built-in capability to render placeholder text if the element had no children when the `empty-msg` HTML attribute was provided. This commit refactors the template down to a granular single-item scale and adds the empty state placeholder back explicitly via programmatic rendering. By splitting template rendering into granular helper functions (`createListEl`, `createListItemEl`, and `createPlaceholderEl`), directory rendering now builds list elements individually and explicitly appends a styled placeholder node whenever a directory contains no files or folders. * **Template Scope Reduction (`src/pages/fileBrowser/listItem.hbs`):** * Removed the enclosing `<ul class="list" id="list">` container tag and the surrounding `{{#list}}...{{/list}}` iteration block from the Handlebars template. * Converted the file into a standalone item partial that takes an entry object and produces a single `<li>` element representing a file or directory row. * **DOM Element Construction Helpers (`src/pages/fileBrowser/fileBrowser.js`):** * Added `createListEl()` to dynamically generate the parent `<ul className="list" id="list">` element. * Added `createListItemEl(obj)` to parse individual item objects through `mustache.render(_listItem, obj)` into single `HTMLLIElement` nodes. * Added `createPlaceholderEl(msg)` to create dedicated empty-state DOM elements (`<div id="placeholder">{msg}</div>`). * **Render Loop & Empty State Logic (`src/pages/fileBrowser/fileBrowser.js`):** * Updated `render(dir)` to construct list containers programmatically and append rendered child elements via standard DOM iteration (`$list.appendChild(el)`). * Re-implemented empty directory handling: if `list.length` is zero, a placeholder element containing the localized empty folder string is appended to the list, restoring the empty message functionality previously supplied via Mustache's `empty-msg` attribute. * **Placeholder Layout Styling (`src/pages/fileBrowser/fileBrowser.scss`):** * Defined CSS rules for `#placeholder` utilizing Flexbox (`display: flex`, `align-items: center`, `justify-content: center`) to ensure empty folder messages are centered within the file browser container. (AI generated commit message)
1 parent 6eaf67c commit 6599a1b

3 files changed

Lines changed: 71 additions & 36 deletions

File tree

src/pages/fileBrowser/fileBrowser.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Url from "utils/Url";
3131
import _addMenu from "./add-menu.hbs";
3232
import _addMenuHome from "./add-menu-home.hbs";
3333
import _template from "./fileBrowser.hbs";
34-
import _list from "./list.hbs";
34+
import _listItem from "./listItem.hbs";
3535
import util from "./util";
3636

3737
/**
@@ -1720,14 +1720,43 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
17201720
if (doesReload) reload();
17211721
}
17221722

1723+
/**
1724+
* @param {string} [msg]
1725+
* @returns {HTMLDivElement | null}
1726+
*/
1727+
function createPlaceholderEl(msg) {
1728+
return <div id="placeholder">{msg}</div>;
1729+
}
1730+
1731+
/**
1732+
* @returns {HTMLUListElement}
1733+
*/
1734+
function createListEl() {
1735+
return <ul className="list" id="list"></ul>;
1736+
}
1737+
1738+
/**
1739+
* @param {object} obj
1740+
* @returns {HTMLLIElement}
1741+
*/
1742+
function createListItemEl(obj) {
1743+
return helpers.parseHTML(mustache.render(_listItem, obj));
1744+
}
1745+
17231746
function render(dir) {
17241747
const { list, scroll } = dir;
1725-
const $list = helpers.parseHTML(
1726-
mustache.render(_list, {
1727-
msg: strings["empty folder message"],
1728-
list,
1729-
}),
1730-
);
1748+
const $list = createListEl();
1749+
1750+
if (list.length) {
1751+
for (const item of list) {
1752+
const el = createListItemEl(item);
1753+
$list.appendChild(el);
1754+
}
1755+
} else {
1756+
const msg = strings["empty folder message"];
1757+
const el = createPlaceholderEl(msg);
1758+
$list.appendChild(el);
1759+
}
17311760

17321761
if (document.getElementById("search-bar")) {
17331762
hideSearchBar();

src/pages/fileBrowser/fileBrowser.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@
8989
height: calc(100% - 60px);
9090
overflow-y: auto;
9191

92+
> #placeholder {
93+
width: 100%;
94+
height: 100%;
95+
font-size: 1.2em;
96+
font-weight: bold;
97+
display: flex;
98+
align-items: center;
99+
justify-content: center;
100+
text-align: center;
101+
}
102+
92103
.tile {
93104
&[disabled] {
94105
.text {

src/pages/fileBrowser/listItem.hbs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
<ul class="list" id="list" empty-msg="{{msg}}">{{#list}}
2-
{{#.}}
3-
<li
4-
tabindex="1"
5-
class="tile {{#isLink}}symlink{{/isLink}}"
6-
action="open"
7-
type="{{type}}"
8-
name="{{name}}"
9-
{{#home}}home="{{.}}"{{/home}}
10-
{{#notSelectable}}data-not-selectable{{/notSelectable}}
11-
{{#open-doc}}open-doc="true"{{/open-doc}}
12-
{{#ftp-account}}ftp-account{{/ftp-account}}
13-
{{#disabled}}disabled{{/disabled}}
14-
{{#uuid}}uuid="{{uuid}}"{{/uuid}}
15-
{{#storageType}}storageType="{{.}}"{{/storageType}}
16-
>
17-
<span
18-
class="icon {{icon}} {{#uuid}}user-added-storage{{/uuid}}"
19-
{{#storageType}}storageType="{{.}}"{{/storageType}}
20-
></span>
21-
22-
<div class="text">
23-
<span>{{name}}</span>
24-
</div>
25-
<data-url>{{url}}</data-url>
26-
</li>
27-
{{/.}}
28-
{{/list}}
29-
</ul>
1+
<li
2+
tabindex="1"
3+
class="tile {{#isLink}}symlink{{/isLink}}"
4+
action="open"
5+
type="{{type}}"
6+
name="{{name}}"
7+
{{#home}}home="{{.}}"{{/home}}
8+
{{#notSelectable}}data-not-selectable{{/notSelectable}}
9+
{{#open-doc}}open-doc="true"{{/open-doc}}
10+
{{#ftp-account}}ftp-account{{/ftp-account}}
11+
{{#disabled}}disabled{{/disabled}}
12+
{{#uuid}}uuid="{{uuid}}"{{/uuid}}
13+
{{#storageType}}storageType="{{.}}"{{/storageType}}
14+
>
15+
<span
16+
class="icon {{icon}} {{#uuid}}user-added-storage{{/uuid}}"
17+
{{#storageType}}storageType="{{.}}"{{/storageType}}
18+
></span>
19+
20+
<div class="text">
21+
<span>{{name}}</span>
22+
</div>
23+
<data-url>{{url}}</data-url>
24+
</li>

0 commit comments

Comments
 (0)