Skip to content

Commit d23440d

Browse files
committed
clean styles and memoize data
1 parent 863fa59 commit d23440d

File tree

1 file changed

+23
-23
lines changed
  • catalog/app/containers/Bucket/PackageCompare/Diff

1 file changed

+23
-23
lines changed

catalog/app/containers/Bucket/PackageCompare/Diff/Entries.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function getEntryChanges(
205205
}
206206
}
207207

208-
function useChanges(
208+
function getChanges(
209209
dir: Dir,
210210
logicalKey: string,
211211
left?: Model.PackageEntry,
@@ -233,24 +233,7 @@ function useChanges(
233233
}
234234
}
235235

236-
const useStyles = M.makeStyles((t) => ({
237-
entryRow: {
238-
borderBottom: `1px solid ${t.palette.divider}`,
239-
},
240-
hash: {
241-
fontFamily: t.typography.monospace.fontFamily,
242-
},
243-
colorInherit: {
244-
color: 'inherit',
245-
},
246-
head: {
247-
overflow: 'hidden',
248-
padding: t.spacing(1),
249-
background: t.palette.background.default,
250-
'& + &': {
251-
borderLeft: `1px solid ${t.palette.divider}`,
252-
},
253-
},
236+
const useEntriesRowStyles = M.makeStyles((t) => ({
254237
side: {
255238
borderLeft: `1px solid ${t.palette.divider}`,
256239
},
@@ -265,9 +248,12 @@ interface EntriesRowProps {
265248
}
266249

267250
function EntriesRow({ className, dir, logicalKey, left, right }: EntriesRowProps) {
268-
const classes = useStyles()
251+
const classes = useEntriesRowStyles()
269252

270-
const changes = useChanges(dir, logicalKey, left, right)
253+
const changes = React.useMemo(
254+
() => getChanges(dir, logicalKey, left, right),
255+
[dir, logicalKey, left, right],
256+
)
271257

272258
switch (changes._tag) {
273259
case 'unmodified':
@@ -295,6 +281,20 @@ function EntriesRow({ className, dir, logicalKey, left, right }: EntriesRowProps
295281
}
296282
}
297283

284+
const useStyles = M.makeStyles((t) => ({
285+
row: {
286+
borderBottom: `1px solid ${t.palette.divider}`,
287+
},
288+
head: {
289+
overflow: 'hidden',
290+
padding: t.spacing(1),
291+
background: t.palette.background.default,
292+
'& + &': {
293+
borderLeft: `1px solid ${t.palette.divider}`,
294+
},
295+
},
296+
}))
297+
298298
interface EntriesDiffProps {
299299
left: Revision
300300
right: Revision
@@ -334,13 +334,13 @@ function EntriesDiff({ left, right }: EntriesDiffProps) {
334334

335335
return (
336336
<div>
337-
<GridRow className={classes.entryRow}>
337+
<GridRow className={classes.row}>
338338
<div className={classes.head}>{left.hash}</div>
339339
<div className={classes.head}>{right.hash}</div>
340340
</GridRow>
341341
{entries.keys.map((logicalKey) => (
342342
<EntriesRow
343-
className={classes.entryRow}
343+
className={classes.row}
344344
key={logicalKey}
345345
logicalKey={logicalKey}
346346
left={entries.left[logicalKey]}

0 commit comments

Comments
 (0)