-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add saving and loading of pieces layouts for gallery view
- Loading branch information
Showing
10 changed files
with
254 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { Content } from "@prisma/client"; | ||
import Link from "next/link"; | ||
|
||
import { type Layouts, Responsive, WidthProvider } from "react-grid-layout"; | ||
import "react-grid-layout/css/styles.css"; | ||
import "react-resizable/css/styles.css"; | ||
|
||
const ResponsiveGridLayout = WidthProvider(Responsive); | ||
|
||
interface PiecesResponsiveGridReadProps { | ||
pieces: Content[]; | ||
layout: Layouts; | ||
} | ||
|
||
export default function PiecesResponsiveGridRead({ | ||
pieces, | ||
layout, | ||
}: PiecesResponsiveGridReadProps) { | ||
console.log(layout); | ||
return ( | ||
<ResponsiveGridLayout | ||
className="layout basis-full" | ||
rowHeight={300} | ||
width={1000} | ||
layouts={layout} | ||
breakpoints={{ lg: 1200, md: 768, sm: 480, xs: 0 }} | ||
cols={{ lg: 6, md: 6, sm: 4, xs: 2 }} | ||
> | ||
{pieces.map((piece) => { | ||
return ( | ||
<div | ||
key={piece.id} | ||
data-grid={{ | ||
x: 0, | ||
y: 0, | ||
w: 3, | ||
h: 1, | ||
maxW: 3, | ||
maxH: 10, | ||
static: true, | ||
}} | ||
className="cursor-pointer transition duration-500 hover:scale-110" | ||
> | ||
<Link href={`/pieces/${piece.id}`} key={piece.id}> | ||
<img | ||
src={piece.imgURL} | ||
className="h-full w-full bg-gray-50 object-cover" | ||
/> | ||
</Link> | ||
</div> | ||
); | ||
})} | ||
</ResponsiveGridLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { Content } from "@prisma/client"; | ||
|
||
import { | ||
type Layout, | ||
type Layouts, | ||
Responsive, | ||
WidthProvider, | ||
} from "react-grid-layout"; | ||
import "react-grid-layout/css/styles.css"; | ||
import "react-resizable/css/styles.css"; | ||
|
||
const ResponsiveGridLayout = WidthProvider(Responsive); | ||
|
||
interface PiecesResponsiveGridWriteProps { | ||
pieces: Content[]; | ||
} | ||
|
||
export default function PiecesResponsiveGridWrite({ | ||
pieces, | ||
}: PiecesResponsiveGridWriteProps) { | ||
const getLayouts = (): Layouts => { | ||
const savedLayouts = localStorage.getItem("layout"); | ||
return savedLayouts ? (JSON.parse(savedLayouts) as Layouts) : {}; | ||
}; | ||
|
||
const handleLayoutChange = (layout: Layout[], layouts: Layouts) => { | ||
localStorage.setItem("layout", JSON.stringify(layouts)); | ||
}; | ||
|
||
return ( | ||
<ResponsiveGridLayout | ||
className="layout basis-full" | ||
rowHeight={300} | ||
width={1000} | ||
layouts={getLayouts()} | ||
onLayoutChange={handleLayoutChange} | ||
breakpoints={{ lg: 1200, md: 768, sm: 480, xs: 0 }} | ||
cols={{ lg: 6, md: 6, sm: 4, xs: 2 }} | ||
> | ||
{pieces.map((piece) => { | ||
return ( | ||
<div | ||
key={piece.id} | ||
className="cursor-pointer transition duration-500 hover:scale-110" | ||
> | ||
<img | ||
src={piece.imgURL} | ||
className="h-full w-full bg-gray-50 object-cover" | ||
/> | ||
</div> | ||
); | ||
})} | ||
</ResponsiveGridLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.