Skip to content

Commit 72b6fb8

Browse files
committed
[fix] file creation fixes
- fix names - fix checks for allowed actions - fix contextmenu appearance
1 parent 53b8bee commit 72b6fb8

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/routes/tutorial/[slug]/+page.svelte

+10-10
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@
8484
},
8585
8686
add: async (stubs) => {
87-
const illegal_create = editing_constraints.create.some(
88-
(c) => !stubs.some((s) => (s.type === 'directory' && c.startsWith(s.name)) || s.name === c)
87+
const illegal_create = stubs.some(
88+
(s) => !editing_constraints.create.some((c) => s.name === c)
8989
);
90+
9091
if (illegal_create) {
9192
modal_text =
9293
'Only the following files and folders are allowed to be created in this tutorial chapter:\n' +
@@ -104,14 +105,15 @@
104105
},
105106
106107
edit: async (to_rename, new_name) => {
107-
const illegal_rename = editing_constraints.remove.some(
108-
(r) =>
109-
(to_rename.type === 'directory' && r.startsWith(to_rename.name)) || to_rename.name === r
110-
);
108+
const illegal_rename =
109+
!editing_constraints.remove.some((r) => to_rename.name === r) ||
110+
!editing_constraints.create.some((c) => new_name === c);
111111
if (illegal_rename) {
112112
modal_text =
113113
'Only the following files and folders are allowed to be renamed in this tutorial chapter:\n' +
114-
editing_constraints.remove.join('\n');
114+
editing_constraints.remove.join('\n') +
115+
'\n\nThey can only be renamed to the following:\n' +
116+
editing_constraints.create.join('\n');
115117
return;
116118
}
117119
@@ -141,9 +143,7 @@
141143
},
142144
143145
remove: async (stub) => {
144-
const illegal_delete = editing_constraints.remove.some(
145-
(r) => (stub.type === 'directory' && r.startsWith(stub.name)) || stub.name === r
146-
);
146+
const illegal_delete = !editing_constraints.remove.some((r) => stub.name === r);
147147
if (illegal_delete) {
148148
modal_text =
149149
'Only the following files and folders are allowed to be deleted in this tutorial chapter:\n' +

src/routes/tutorial/[slug]/ContextMenu.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</script>
2525

2626
{#if $menu_items}
27-
<nav style="position: fixed; z-index: 1; top:{$menu_items.y}px; left:{$menu_items.x}px">
27+
<nav style="position: fixed; z-index: 5; top:{$menu_items.y}px; left:{$menu_items.x}px">
2828
<div class="navbar" id="navbar">
2929
<ul>
3030
{#each $menu_items.items as item}

src/routes/tutorial/[slug]/Folder.svelte

+5-3
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@
114114
for (let i = 1; i <= parts.length; i++) {
115115
const part = parts.slice(0, i).join('/');
116116
const basename = /** @type{string} */ (part.split('/').pop());
117-
const name = prefix + part + '/';
117+
const name = prefix + part;
118118
if (!files.some((file) => file.name === name)) {
119119
if (i < parts.length || state === 'add_folder') {
120120
stubs.push({ type: 'directory', name, depth: depth + i, basename });
121121
} else if (i === parts.length && state === 'add_file') {
122122
stubs.push({
123123
type: 'file',
124-
name: name.slice(0, -1),
124+
name,
125125
depth: depth + i,
126126
basename,
127127
text: true,
@@ -131,7 +131,9 @@
131131
}
132132
}
133133
134-
add(stubs);
134+
if (stubs.length) {
135+
add(stubs);
136+
}
135137
}
136138
}
137139

0 commit comments

Comments
 (0)