Skip to content

Commit fb2617e

Browse files
author
Marius Ostheimer
committed
fix(client): Media Center Filters should rerender Gallery
1 parent 157a3a9 commit fb2617e

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

client/src/Media/Gallery.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ export default class Gallery extends Component<Props> {
6868
(mediaFilter.maxHeight && mediaFilter.maxHeight < media.height) ||
6969
(mediaFilter.minHeight && mediaFilter.minHeight > media.height));
7070
return (
71-
<CellMeasurer cache={this.cache} index={index} key={media.id} parent={parent}>
71+
<CellMeasurer
72+
cache={this.cache}
73+
index={index}
74+
key={media.id}
75+
parent={parent}
76+
>
7277
<Image
7378
style={style}
7479
{...media}

client/src/Media/Topbar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export default function Topbar(props: Props) {
146146
});
147147

148148
useEffect(() => {
149+
if (!progress) return;
149150
onUploadProgress(progress || 0);
150151
}, [progress, onUploadProgress]);
151152

client/src/Media/UploadZone.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useEffect, memo } from "react";
1+
import React, { useMemo, useEffect } from "react";
22
import { useDropzone } from "react-dropzone";
33
import { useUpload } from "react-use-upload";
44
import createValidator, { MediaFilter } from "./createValidator";
@@ -27,7 +27,6 @@ export default function UploadZone({
2727
mediaType,
2828
mediaFilter
2929
}: Props) {
30-
const Render = useMemo(() => memo(props => render(props)), [render]);
3130
const validator = useMemo(() => createValidator(mediaType, mediaFilter), [
3231
mediaType,
3332
mediaFilter
@@ -61,16 +60,14 @@ export default function UploadZone({
6160
className={`${className} ${isDragActive ? activeClass : ""}`}
6261
>
6362
<input {...getInputProps()} />
64-
<Render
65-
{...{
63+
{render({...{
6664
...response,
6765
complete: done,
6866
onFiles,
6967
progress,
7068
error,
7169
files
72-
}}
73-
/>
70+
}})}
7471
</div>
7572
);
7673
}

client/src/Media/index.tsx

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Cotype from "../../../typings";
2-
import React, { Component, Fragment } from "react";
2+
import React, { Component } from "react";
33
import styled, { css } from "react-emotion";
44
import { RenderInfo } from "../common/ScrollList";
55
import api from "../api";
@@ -104,12 +104,16 @@ export default class Media extends Component<Props, State> {
104104
if (!props.onSelect) {
105105
this.state.editable = true;
106106
}
107-
if (props.mediaType && typeof props.mediaType === 'string' && props.mediaType !== "all") {
107+
if (
108+
props.mediaType &&
109+
typeof props.mediaType === "string" &&
110+
props.mediaType !== "all"
111+
) {
108112
this.state.filters = this.state.filters.filter(el =>
109113
el.value.includes(props.mediaType as string)
110114
);
111-
if(this.state.filters.length >0){
112-
this.state.fileType = this.state.filters[0].value
115+
if (this.state.filters.length > 0) {
116+
this.state.fileType = this.state.filters[0].value;
113117
}
114118
}
115119
}
@@ -265,8 +269,7 @@ export default class Media extends Component<Props, State> {
265269
editable,
266270
conflictingItems,
267271
filters,
268-
topbarProgress,
269-
fileType
272+
topbarProgress
270273
} = this.state;
271274
return (
272275
<Root {...testable("upload-zone")}>
@@ -306,27 +309,31 @@ export default class Media extends Component<Props, State> {
306309
activeClass={activeClass}
307310
onUpload={this.onUpload}
308311
render={({ progress, onFiles }: any) => {
309-
const itemCount =
310-
!!progress || !!topbarProgress ? total + 1 : total;
311-
const data =
312-
!!progress || !!topbarProgress
313-
? [{ progress: progress || topbarProgress }, ...items]
314-
: items;
312+
const isProgress =
313+
(progress && progress < 100) ||
314+
(topbarProgress && topbarProgress < 100);
315+
const itemCount = isProgress ? total + 1 : total;
316+
const data = isProgress
317+
? [
318+
{
319+
progress:
320+
progress && progress < 100 ? progress : topbarProgress
321+
},
322+
...items
323+
]
324+
: items;
315325
return (
316-
<Fragment>
317-
<Main>
318-
<Gallery
319-
key={fileType}
320-
count={itemCount}
321-
data={data}
322-
editable={editable}
323-
onSelect={this.onSelect}
324-
onDelete={this.deleteMedia}
325-
onRowsRendered={this.onRowsRendered}
326-
mediaFilter={this.props.mediaFilter}
327-
/>
328-
</Main>
329-
</Fragment>
326+
<Main>
327+
<Gallery
328+
count={itemCount}
329+
data={data}
330+
editable={editable}
331+
onSelect={this.onSelect}
332+
onDelete={this.deleteMedia}
333+
onRowsRendered={this.onRowsRendered}
334+
mediaFilter={this.props.mediaFilter}
335+
/>
336+
</Main>
330337
);
331338
}}
332339
/>

src/persistence/adapter/knex/KnexContent.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ export default class KnexContent implements ContentAdapter {
751751
if (contents.length > 0) {
752752
// TODO action delete/unpublish/schedule
753753
const err = new ReferenceConflictError({ type: "content" });
754-
err.refs = contents.map(c => this.parseData(c));
754+
err.refs = contents.map((c:any) => this.parseData(c));
755755
throw err;
756756
}
757757
}
@@ -894,7 +894,7 @@ export default class KnexContent implements ContentAdapter {
894894

895895
return {
896896
total,
897-
items: items.map(i => this.parseData(i))
897+
items: items.map((i:any) => this.parseData(i))
898898
};
899899
}
900900

@@ -916,7 +916,7 @@ export default class KnexContent implements ContentAdapter {
916916
.where("content_references.media", "=", media)
917917
.andWhere("contents.deleted", false);
918918

919-
return contents.map(c => this.parseData(c));
919+
return contents.map((c:any) => this.parseData(c));
920920
}
921921

922922
async list(
@@ -1303,7 +1303,7 @@ export default class KnexContent implements ContentAdapter {
13031303
state: "applied"
13041304
});
13051305
const outstanding = migrations.filter(
1306-
m => !applied.some(a => a.name === m.name)
1306+
m => !applied.some((a:any) => a.name === m.name)
13071307
);
13081308

13091309
if (!outstanding.length) {
@@ -1317,7 +1317,7 @@ export default class KnexContent implements ContentAdapter {
13171317
await this.knex("content_migrations").insert(
13181318
names.map(name => ({ name, state: "pending" }))
13191319
);
1320-
const tx = await this.knex.transaction();
1320+
const tx = await (this.knex as any).transaction(); // TODO: Fix Line
13211321
try {
13221322
await callback(new KnexContent(tx), outstanding);
13231323
await tx.commit();

0 commit comments

Comments
 (0)