Add delete button to drive page

This commit is contained in:
jaina heartles 2022-12-16 02:37:04 -08:00
parent 6dc8447343
commit d4703a2127
3 changed files with 56 additions and 1 deletions

View File

@ -280,6 +280,7 @@ const drive = struct {
const Action = enum {
mkdir,
delete,
};
pub const body_tag_from_query_param = "action";
@ -287,6 +288,7 @@ const drive = struct {
mkdir: struct {
name: []const u8,
},
delete: struct {},
};
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
@ -297,6 +299,19 @@ const drive = struct {
try servePage(req, res, srv);
},
.delete => {
const trimmed_path = std.mem.trim(u8, req.args.path, "/");
_ = try srv.driveDelete(trimmed_path);
const dir = trimmed_path[0 .. std.mem.lastIndexOfScalar(u8, trimmed_path, '/') orelse trimmed_path.len];
const url = try std.fmt.allocPrint(srv.allocator, "{s}/drive/{s}", .{
req.mount_path,
dir,
});
defer srv.allocator.free(url);
try res.headers.put("Location", url);
return res.status(.see_other);
},
}
}
};

View File

@ -48,6 +48,25 @@
{$dir.name.?}
</a>
</td>
<td />
<td />
<td />
<td class="actions">
<div class="popup" id="delete-{$dir.name.?}">
<a href="#delete-{$dir.name.?}">
<i class="fa-solid fa-trash"></i>
</a>
<form class="popup-dialog" action="
{= .mount_path}/{.base_drive_path}
{= #for @slice(.breadcrumbs, 0, .breadcrumbs.len) |$c|}/{$c}{/for =}/{$dir.name.? =}
?action=delete" method="post"
>
<div>Are you sure you want to delete this directory?</div>
<button type="submit">Yes, Delete</button>
<a href="#">No, Cancel</a>
</form>
</div>
</td>
{#case file |$file|}
<td class="icons">
{#if %user |$u|}
@ -71,6 +90,23 @@
<td class="content-type">{#if $file.meta.content_type |$t|}{$t}{/if}</td>
<td class="size">{$file.meta.size}</td>
<td class="created-at">{$file.meta.created_at}</td>
<td class="actions">
<div class="popup" id="delete-{$file.name.?}">
<a href="#delete-{$file.name.?}">
<i class="fa-solid fa-trash"></i>
</a>
<form class="popup-dialog" action="
{= .mount_path}/{.base_drive_path}
{= #for @slice(.breadcrumbs, 0, .breadcrumbs.len) |$c|}/{$c}{/for =}/{$file.name.? =}
?action=delete" method="post"
>
<div>Are you sure you want to delete this file?</div>
<input type="hidden" name="action" value="delete" />
<button type="submit">Yes, Delete</button>
<a href="#">No, Cancel</a>
</form>
</div>
</td>
{/switch =}
</tr>
{/for=}

View File

@ -266,7 +266,11 @@ pub fn DeserializerContext(comptime Result: type, comptime From: type, comptime
}
pub fn finish(self: *@This(), allocator: std.mem.Allocator) !Result {
return (try self.deserialize(allocator, Result, self.data, &.{})) orelse error.MissingField;
return (try self.deserialize(allocator, Result, self.data, &.{})) orelse
if (std.meta.fields(Result).len == 0)
return .{}
else
return error.MissingField;
}
fn getSerializedField(self: *@This(), comptime field_ref: FieldRef) ?From {