Browse Source

Add configurable gap size between grid cards

master
jeffvli 3 years ago
committed by Jeff
parent
commit
670fc3d63d
  1. 1
      src/__tests__/App.test.tsx
  2. 22
      src/components/settings/ConfigPanels/LookAndFeelConfig.tsx
  3. 4
      src/components/shared/setDefaultSettings.ts
  4. 10
      src/components/viewtypes/GridViewType.tsx
  5. 7
      src/redux/configSlice.ts
  6. 1
      src/shared/mockSettings.ts

1
src/__tests__/App.test.tsx

@ -365,6 +365,7 @@ const configState: ConfigPage = {
}, },
gridView: { gridView: {
cardSize: 160, cardSize: 160,
gapSize: 20,
alignment: 'flex-start', alignment: 'flex-start',
}, },
}, },

22
src/components/settings/ConfigPanels/LookAndFeelConfig.tsx

@ -31,7 +31,12 @@ import {
genreColumnPicker, genreColumnPicker,
genreColumnListAuto, genreColumnListAuto,
} from '../ListViewColumns'; } from '../ListViewColumns';
import { setActive, setGridAlignment, setGridCardSize } from '../../../redux/configSlice'; import {
setActive,
setGridAlignment,
setGridCardSize,
setGridGapSize,
} from '../../../redux/configSlice';
const LookAndFeelConfig = () => { const LookAndFeelConfig = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -271,7 +276,7 @@ const LookAndFeelConfig = () => {
</StyledCheckbox> </StyledCheckbox>
</ConfigPanel> </ConfigPanel>
<ConfigPanel header="Grid-View" bordered> <ConfigPanel header="Grid-View" bordered>
<ControlLabel>Card size</ControlLabel> <ControlLabel>Card size (px)</ControlLabel>
<StyledInputNumber <StyledInputNumber
defaultValue={config.lookAndFeel.gridView.cardSize} defaultValue={config.lookAndFeel.gridView.cardSize}
step={1} step={1}
@ -284,6 +289,19 @@ const LookAndFeelConfig = () => {
}} }}
/> />
<br /> <br />
<ControlLabel>Gap size (px)</ControlLabel>
<StyledInputNumber
defaultValue={config.lookAndFeel.gridView.gapSize}
step={1}
min={0}
max={100}
width={150}
onChange={(e: any) => {
settings.setSync('gridGapSize', Number(e));
dispatch(setGridGapSize({ size: Number(e) }));
}}
/>
<br />
<ControlLabel>Grid alignment</ControlLabel> <ControlLabel>Grid alignment</ControlLabel>
<RadioGroup <RadioGroup
name="gridAlignemntRadioList" name="gridAlignemntRadioList"

4
src/components/shared/setDefaultSettings.ts

@ -126,6 +126,10 @@ const setDefaultSettings = (force: boolean) => {
settings.setSync('gridCardSize', 175); settings.setSync('gridCardSize', 175);
} }
if (force || !settings.hasSync('gridGapSize')) {
settings.setSync('gridGapSize', 20);
}
if (force || !settings.hasSync('gridAlignment')) { if (force || !settings.hasSync('gridAlignment')) {
settings.setSync('gridAlignment', 'flex-start'); settings.setSync('gridAlignment', 'flex-start');
} }

10
src/components/viewtypes/GridViewType.tsx

@ -77,6 +77,7 @@ function ListWrapper({
cardSubtitle, cardSubtitle,
playClick, playClick,
size, size,
gapSize,
alignment, alignment,
height, height,
itemCount, itemCount,
@ -86,11 +87,10 @@ function ListWrapper({
cachePath, cachePath,
handleFavorite, handleFavorite,
}: any) { }: any) {
const gapSize = 5; const cardHeight = size + 55;
const cardHeight = size + 75; const cardWidth = size;
const cardWidth = size + 25;
// How many cards can we show per row, given the current width? // How many cards can we show per row, given the current width?
const columnCount = Math.floor((width - gapSize) / (cardWidth + gapSize)); const columnCount = Math.floor((width - gapSize + 3) / (cardWidth + gapSize + 2));
const rowCount = Math.ceil(itemCount / columnCount); const rowCount = Math.ceil(itemCount / columnCount);
const itemData = useMemo( const itemData = useMemo(
@ -122,6 +122,7 @@ function ListWrapper({
itemCount, itemCount,
playClick, playClick,
size, size,
gapSize,
alignment, alignment,
cacheImages, cacheImages,
cachePath, cachePath,
@ -168,6 +169,7 @@ const GridViewType = ({
cardSubtitle={cardSubtitle} cardSubtitle={cardSubtitle}
playClick={playClick} playClick={playClick}
size={size} size={size}
gapSize={config.lookAndFeel.gridView.gapSize}
alignment={config.lookAndFeel.gridView.alignment} alignment={config.lookAndFeel.gridView.alignment}
cacheType={cacheType} cacheType={cacheType}
cacheImages={cacheImages} cacheImages={cacheImages}

7
src/redux/configSlice.ts

@ -37,6 +37,7 @@ export interface ConfigPage {
}; };
gridView: { gridView: {
cardSize: number; cardSize: number;
gapSize: number;
alignment: string | 'flex-start' | 'center'; alignment: string | 'flex-start' | 'center';
}; };
}; };
@ -121,6 +122,7 @@ const initialState: ConfigPage = {
}, },
gridView: { gridView: {
cardSize: Number(parsedSettings.gridCardSize), cardSize: Number(parsedSettings.gridCardSize),
gapSize: Number(parsedSettings.gridGapSize),
alignment: String(parsedSettings.gridAlignment), alignment: String(parsedSettings.gridAlignment),
}, },
}, },
@ -197,6 +199,10 @@ const configSlice = createSlice({
state.lookAndFeel.gridView.cardSize = action.payload.size; state.lookAndFeel.gridView.cardSize = action.payload.size;
}, },
setGridGapSize: (state, action: PayloadAction<{ size: number }>) => {
state.lookAndFeel.gridView.gapSize = action.payload.size;
},
setGridAlignment: ( setGridAlignment: (
state, state,
action: PayloadAction<{ alignment: string | 'flex-start' | 'center' }> action: PayloadAction<{ alignment: string | 'flex-start' | 'center' }>
@ -232,6 +238,7 @@ export const {
setRowHeight, setRowHeight,
setFontSize, setFontSize,
setGridCardSize, setGridCardSize,
setGridGapSize,
setGridAlignment, setGridAlignment,
moveToIndex, moveToIndex,
} = configSlice.actions; } = configSlice.actions;

1
src/shared/mockSettings.ts

@ -32,6 +32,7 @@ export const mockSettings = {
starred: false, starred: false,
}, },
gridCardSize: 200, gridCardSize: 200,
gridGapSize: 20,
gridAlignment: 'flex-start', gridAlignment: 'flex-start',
playlistViewType: 'grid', playlistViewType: 'grid',
albumViewType: 'grid', albumViewType: 'grid',

Loading…
Cancel
Save