I have made a component which uses the grid layout, but I get an error creating the breakpoints for responsiveness.
item.js:10 Uncaught TypeError: Cannot read property '10' of undefined
at item.js:10
at Array.map (<anonymous>)
at responsiveItems (item.js:9)
at ResizeObserver.<anonymous> (index.svelte:107)
<script context="module">
import { API, graphqlOperation } from 'aws-amplify';
import { listPosts } from '../graphql/queries';
import PostLink from './PostLink.svelte';
import Grid from "svelte-grid";
import gridHelp from "svelte-grid/build/helper/index.mjs";
import map from 'lodash.map';
let items;
let breakpoints = [[1100, 5], [800, 4], [530, 1]];
let cols = 10;
export async function preload(page, session) {
let { posts } = session;
if (undefined === posts) {
const res = await API.graphql(graphqlOperation(listPosts));
posts = res.data.listPosts.items;
session.posts = posts;
}
// Just generate messy layout
let layout = generateLayout(posts);
// Helper function which normalize. you need to pass items and columns
items = gridHelp.normalize(layout, cols);
return items;
}
function generateLayout(posts) {
return map(new Array(Object.keys(posts).length), function(item, i) {
return gridHelp.item({
x: 0,
y: 0,
w: 2,
h: 6,
resizable: false,
draggable: false,
id: posts[i].id,
post: posts[i],
});
});
}
</script>
<Grid {breakpoints} items={items} {cols} let:item={item} rowHeight={100} gap={10} dynamic>
<PostLink post={item.post} />
</Grid>