uni-directional delete works

This commit is contained in:
Brandon Thomas committed 2021-06-07 02:33:48 -04:00
1 parent 83da090ba1
commit 5f477fe04b
2 files changed
+57 -2

No files matched your search

+6 -2
View File
@@ -67,11 +67,15 @@ export class SessionWrapper {
return this.sessionStateResponse?.user?.can_ban_users || false;
}
public canApproveW2lTemplates() : boolean {
return this.sessionStateResponse?.user?.can_approve_w2l_templates || false;
}
public canEditOtherUsersProfiles() : boolean {
return this.sessionStateResponse?.user?.can_edit_other_users_profiles || false;
}
public canApproveW2lTemplates() : boolean {
return this.sessionStateResponse?.user?.can_approve_w2l_templates || false;
public canDeleteOtherUsersW2lTemplates() : boolean {
return this.sessionStateResponse?.user?.can_delete_other_users_w2l_templates || false;
}
}
@@ -173,6 +173,36 @@ function W2lTemplateViewFc(props: Props) {
return false;
}
const handleDeleteFormSubmit = (ev: React.FormEvent<HTMLFormElement>) : boolean => {
ev.preventDefault();
const api = new ApiConfig();
const endpointUrl = api.deleteW2l(templateSlug);
const request = {
set_delete: true,
}
fetch(endpointUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
credentials: 'include',
body: JSON.stringify(request),
})
.then(res => res.json())
.then(res => {
if (res.success) {
history.go(0); // force reload
}
})
.catch(e => {
});
return false;
}
let creatorLink=`/profile/${w2lTemplate?.creator_username}`;
let object : string|undefined = undefined;
@@ -236,6 +266,25 @@ function W2lTemplateViewFc(props: Props) {
);
}
let deletionForm = <span />;
if (props.sessionWrapper.canDeleteOtherUsersW2lTemplates()) {
deletionForm = (
<form onSubmit={handleDeleteFormSubmit}>
<br />
<label className="label">Delete W2L Template (hides from everyone but mods)</label>
<p className="control">
<button className="button is-danger is-large is-fullwidth">
Delete
</button>
</p>
</form>
);
}
return (
<div>
<h1 className="title is-1"> Video lip sync template </h1>
@@ -323,6 +372,8 @@ function W2lTemplateViewFc(props: Props) {
{modOnlyApprovalForm}
{deletionForm}
<SessionW2lInferenceResultListFc w2lInferenceJobs={props.w2lInferenceJobs} />
<br />
</div>