Skip to content

Commit db86d35

Browse files
committed
feat: emptying the trash
Closes #12
1 parent ff694d6 commit db86d35

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

assets/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ button:focus,
7070
outline: none;
7171
}
7272

73+
#trash-button {
74+
color: var(--color-danger);
75+
}
76+
7377
h1, h3 {
7478
margin: 0;
7579
}

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,14 @@ func handleDelete(c echo.Context) error {
325325

326326
filesPath := filepath.Join(files.GetFilesPath(), path)
327327

328+
// if the path is inside the .trash, delete it permanently
328329
if strings.HasPrefix(path, ".trash") {
329330
err = os.RemoveAll(filesPath)
330331
if err != nil {
331332
return err
332333
}
333334
} else {
335+
// otherwise, move it to the .trash
334336
trashPath := filepath.Join(files.GetFilesPath(), ".trash")
335337

336338
err = os.Rename(filesPath, filepath.Join(trashPath, filepath.Base(filesPath)))
@@ -339,6 +341,19 @@ func handleDelete(c echo.Context) error {
339341
}
340342
}
341343

344+
// emptying the trash, recreate the .trash directory and redirect to root
345+
if path == ".trash" {
346+
trashPath := filepath.Join(files.GetFilesPath(), ".trash")
347+
err = os.Mkdir(trashPath, 0755)
348+
if err != nil {
349+
return err
350+
}
351+
352+
c.Response().Header().Set("HX-Redirect", "/")
353+
354+
return c.NoContent(http.StatusOK)
355+
}
356+
342357
c.Response().Header().Set("HX-Refresh", "true")
343358

344359
return c.NoContent(http.StatusOK)

views/header.templ

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ templ Header(loggedIn bool, basePath string) {
77
<div class="buttons">
88
if loggedIn {
99
<button id="upload-button">upload</button>
10+
if basePath == ".trash/" {
11+
<button id="trash-button" hx-delete="/.trash" hx-confirm="are you sure you want to empty the trash?">empty</button>
12+
}
1013
<button id="mkdir-button" hx-post={"/mkdir/" + basePath} hx-prompt="create a new directory">mkdir</button>
1114
<button id="logout-button" hx-post="/logout">logout</button>
1215
} else {

views/header_templ.go

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)