Skip to content

Commit 7ee2e61

Browse files
committed
fix group spacing bugs
1 parent 841cb42 commit 7ee2e61

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

frontend/src/components/dashboard/base-items/apps/AppShortcut.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ type Props = {
1515
editMode?: boolean;
1616
config?: any;
1717
isPreview?: boolean;
18+
size?: 'small' | 'medium' | 'large';
1819
}
1920

20-
export const AppShortcut = ({ url, name, iconName, showLabel, editMode, config, isPreview }: Props) => {
21+
export const AppShortcut = ({ url, name, iconName, showLabel, editMode, config, isPreview, size = 'medium' }: Props) => {
2122
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
2223
const isWolShortcut = config?.isWol === true;
2324

@@ -33,6 +34,14 @@ export const AppShortcut = ({ url, name, iconName, showLabel, editMode, config,
3334
return isMobile ? '.9rem' : '1rem';
3435
}, [name, isMobile]);
3536

37+
// Calculate text width based on size prop to prevent overlap with status icons
38+
const textWidth = useMemo(() => {
39+
if (size === 'small') {
40+
return '70%'; // Narrower for 4x2 layout to prevent overlap
41+
}
42+
return '80%'; // Default width for other layouts
43+
}, [size]);
44+
3645
const handleWakeOnLan = useCallback(async (e: React.MouseEvent) => {
3746
e.preventDefault();
3847

@@ -125,7 +134,7 @@ export const AppShortcut = ({ url, name, iconName, showLabel, editMode, config,
125134
WebkitLineClamp: 1,
126135
WebkitBoxOrient: 'vertical',
127136
wordBreak: 'break-word',
128-
width: '80%',
137+
width: textWidth,
129138
lineHeight: 1.2,
130139
mt: 1
131140
}}

frontend/src/components/dashboard/base-items/widgets/GroupWidget.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const SortableGroupItem: React.FC<SortableGroupItemProps> = ({
148148
iconName={item.icon || ''}
149149
showLabel={true}
150150
editMode={isEditing}
151+
size={itemSize}
151152
config={{
152153
isWol: item.isWol,
153154
macAddress: item.macAddress,
@@ -262,7 +263,7 @@ const GroupWidget: React.FC<GroupWidgetProps> = ({
262263
// 4x2 grid layout (8 items in 2 rows of 4 items each)
263264
return {
264265
width: '22%', // Even narrower items, 4 per row
265-
maxWidth: '120px', // Max width for larger screens
266+
maxWidth: '180px', // Max width for larger screens
266267
rows: 2,
267268
cols: 4,
268269
height: DUAL_WIDGET_CONTAINER_HEIGHT,
@@ -473,14 +474,6 @@ const GroupWidget: React.FC<GroupWidgetProps> = ({
473474
}
474475
}, [items, onItemsChange, onItemDelete]);
475476

476-
// Handle click on add button - opens the group edit modal
477-
const handleAddClick = useCallback(() => {
478-
if (isEditing && items.length < MAX_ITEMS) {
479-
// Open the group edit modal
480-
onEdit?.();
481-
}
482-
}, [isEditing, items.length, onEdit, MAX_ITEMS]);
483-
484477
// Cleanup effects for mobile
485478
useEffect(() => {
486479
// Cleanup function to ensure we don't leave lingering event listeners
@@ -650,16 +643,22 @@ const GroupWidget: React.FC<GroupWidgetProps> = ({
650643
sx={{
651644
flex: 1,
652645
display: 'grid',
653-
gridTemplateColumns: layout === '2x3' ? 'repeat(2, minmax(100px, 160px))' : layout === '4x2' ? 'repeat(4, minmax(70px, 115px))' : 'repeat(3, minmax(90px, 150px))',
654-
gridTemplateRows: layout === '2x3' ? 'repeat(3, 1fr)' : 'repeat(2, 1fr)',
655-
gap: 3,
646+
gridTemplateColumns: layout === '2x3'
647+
? { xs: 'repeat(2, minmax(110px, 180px))', sm: 'repeat(2, minmax(90px, 160px))' }
648+
: layout === '4x2'
649+
? { xs: 'repeat(4, minmax(70px, 110px))', sm: 'repeat(4, minmax(75px, 140px))', md: 'repeat(4, minmax(85px, 160px))', lg: 'repeat(4, minmax(95px, 180px))' }
650+
: { xs: 'repeat(3, minmax(95px, 160px))', sm: 'repeat(3, minmax(85px, 150px))' },
651+
gridTemplateRows: layout === '2x3' ? 'repeat(3, auto)' : layout === '4x2' ? 'repeat(2, auto)' : 'repeat(1, auto)',
652+
rowGap: layout === '4x2' ? { xs: 3, sm: 4 } : { xs: 4, sm: 4 },
653+
columnGap: layout === '4x2' ? { xs: 1, sm: 2 } : { xs: 2, sm: 4 },
656654
gridAutoFlow: 'row', // Fill row by row (left to right, top to bottom)
657-
justifyItems: 'stretch', // Items fill their grid cells
658-
alignItems: 'stretch',
655+
justifyItems: layout === '4x2' ? 'stretch' : 'center', // Stretch 4x2 items to fill grid cells, center others
656+
alignItems: 'center', // Center items vertically within their grid cells
659657
justifyContent: 'center', // Center the grid content horizontally
658+
alignContent: 'center', // Center the entire grid vertically
660659
overflowY: 'hidden',
661660
overflowX: 'hidden',
662-
p: { lg: 2 },
661+
p: 1,
663662
m: 0
664663
}}
665664
>
@@ -671,7 +670,7 @@ const GroupWidget: React.FC<GroupWidgetProps> = ({
671670
display: 'flex',
672671
justifyContent: 'center',
673672
alignItems: 'center',
674-
maxWidth: gridSettings.maxWidth,
673+
maxWidth: layout === '4x2' ? 'none' : gridSettings.maxWidth,
675674
width: '100%',
676675
height: '100%'
677676
}}
@@ -736,7 +735,7 @@ const GroupWidget: React.FC<GroupWidgetProps> = ({
736735
display: 'flex',
737736
justifyContent: 'center',
738737
alignItems: 'center',
739-
maxWidth: gridSettings.maxWidth,
738+
maxWidth: layout === '4x2' ? 'none' : gridSettings.maxWidth,
740739
width: '100%',
741740
height: '100%'
742741
}}
@@ -756,7 +755,6 @@ const GroupWidget: React.FC<GroupWidgetProps> = ({
756755
backgroundColor: 'rgba(255, 255, 255, 0.05)'
757756
}
758757
}}
759-
onClick={handleAddClick}
760758
title='Edit group to add items'
761759
>
762760
<AddIcon fontSize='medium' />

0 commit comments

Comments
 (0)