Skip to content

Commit f498aef

Browse files
committed
Added OnFileRemove method in FileUploader
1 parent ec01781 commit f498aef

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

assets/core/ts/components/file-uploader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface FileUploaderProps {
1515
maxSize?: number; // in bytes
1616
onFileSelect?: (files: (File | WPMedia | string)[]) => void;
1717
onError?: (error: string) => void;
18+
onFileRemove?: (file: File | WPMedia | string) => void;
1819
disabled?: boolean;
1920
variant?: FileUploaderVariant;
2021
value?: File | WPMedia | string | (File | WPMedia | string)[] | null;
@@ -273,6 +274,10 @@ export const fileUploader = (props: FileUploaderProps = defaultProps) => ({
273274
},
274275

275276
removeFile(index?: number) {
277+
if (props.onFileRemove && typeof index === 'number') {
278+
props.onFileRemove(this.selectedFiles[index]);
279+
}
280+
276281
if (this.multiple && typeof index === 'number') {
277282
this.selectedFiles = this.selectedFiles.filter((_, i) => i !== index);
278283
} else {

assets/src/js/v3/shared/utils/endpoints.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const endpoints = {
111111
GET_ASSIGNMENT_DETAILS: 'tutor_assignment_details',
112112
SAVE_ASSIGNMENT: 'tutor_assignment_save',
113113
ASSIGNMENT_SUBMIT: 'tutor_assignment_submit',
114+
REMOVE_ATTACHMENT: 'tutor_remove_assignment_attachment',
114115

115116
// TAX SETTINGS
116117
GET_TAX_SETTINGS: 'tutor_get_tax_settings',

assets/src/scss/frontend/learning-area/components/_assignment.scss

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,45 +150,49 @@
150150
thead {
151151
th {
152152
@include tutor-typography('tiny', 'regular');
153-
width: 20%;
153+
width: 14.3%;
154154

155155
&:first-of-type {
156156
width: 42.5%;
157157
}
158+
159+
&:nth-child(4) {
160+
width: 18%;
161+
}
158162
}
159163
}
160164

161165
tbody {
162166
tr {
167+
height: $tutor-spacing-13;
163168
&:hover {
164169
td {
165170
.attempt-list-badge{
166171
.tutor-badge{
167172
display: none;
168173
}
169174
}
170-
.attempt_details_button {
175+
button {
171176
display: block;
172177
}
173178
}
174179
}
175180
}
176181
td {
177-
position: relative;
178182
@include tutor-typography('small', 'regular', 'secondary');
179183
width: 14.3%;
180184

181185
&:first-of-type {
182186
color: $tutor-text-brand;
183187
font-weight: $tutor-font-weight-medium;
184-
width: 42.8%;
188+
width: 42.5%;
189+
}
190+
191+
&:nth-child(4) {
192+
width: 18%;
185193
}
186194

187-
a.attempt_details_button {
188-
position: absolute;
189-
right: 0;
190-
top: 50%;
191-
transform: translate(-50%, -50%);
195+
button{
192196
display: none;
193197
}
194198
}

components/FileUploader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ public function get(): string {
539539
$button_text = ! empty( $this->uploader_button_text ) ? $this->uploader_button_text : __( 'Select Files', 'tutor' );
540540
$on_file_select = $this->attributes['onFileSelect'] ?? 'null';
541541
$on_error = $this->attributes['onError'] ?? 'null';
542+
$on_file_remove = $this->attributes['onFileRemove'] ?? 'null';
542543
$variant = $this->variant;
543544
$uploader_attributes = $this->attributes;
544545

@@ -558,6 +559,7 @@ class="tutor-file-uploader-wrapper"
558559
accept: '<?php echo esc_attr( $accept ); ?>',
559560
maxSize: <?php echo (int) $max_size; ?>,
560561
onFileSelect: <?php echo esc_js( $on_file_select ); ?>,
562+
onFileRemove: <?php echo esc_js( $on_file_remove ); ?>,
561563
onError: <?php echo esc_js( $on_error ); ?>,
562564
variant: '<?php echo esc_attr( $variant ); ?>',
563565
value: values.<?php echo esc_attr( $this->name ); ?>,

0 commit comments

Comments
 (0)