-
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.
- Loading branch information
master1lan
committed
Dec 27, 2022
1 parent
852f110
commit 76b5047
Showing
11 changed files
with
135 additions
and
56 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,39 +1,14 @@ | ||
| import React, { useEffect, useRef } from "react"; | ||
| import { Masonry } from "masonic"; | ||
| import { useFakerImages } from "./utils/faker/index"; | ||
| // import Masonry from "@components/masonry"; | ||
|
|
||
| import Image from "@components/image"; | ||
|
|
||
| export default function App() { | ||
| const lists = useFakerImages(100); | ||
| // return <Masonry />; | ||
| const url = `https://images.pexels.com/photos/5702958/pexels-photo-5702958.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1`; | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| justifyContent: "center", | ||
| }} | ||
| > | ||
| <div className='feedContainer'> | ||
| <Masonry | ||
| items={lists} | ||
| columnWidth={180} | ||
| rowGutter={10} | ||
| columnGutter={10} | ||
| maxColumnCount={5} | ||
| render={FakerCard} | ||
| /> | ||
| </div> | ||
| <div> | ||
| <Image url={url} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function FakerCard({ data: { id, image, name } }) { | ||
| return ( | ||
| <section key={id} className='element-item'> | ||
| <img src={image} alt='' /> | ||
| <div className='footer'> | ||
| <p> | ||
| <span>{name}</span> | ||
| </p> | ||
| </div> | ||
| </section> | ||
| ); | ||
| } |
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,23 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { getImageSize } from "./tool"; | ||
| export default function Image({ url }) { | ||
| const [loading, setLoading] = useState<boolean>(true); | ||
| const [obj, setObj] = useState({}); | ||
| useEffect(() => { | ||
| getImageSize(url).then((data) => { | ||
| setLoading(() => false); | ||
| setObj(() => ({ | ||
| width: data.width, | ||
| height: data.height, | ||
| })); | ||
| }); | ||
| }, [url]); | ||
| if (loading) { | ||
| return <div>loading</div>; | ||
| } | ||
| return ( | ||
| <div> | ||
| <img width={obj.width} height={obj.height} src={url} /> | ||
| </div> | ||
| ); | ||
| } |
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,22 @@ | ||
| import { Once } from "@utils/index"; | ||
| import { resolve } from "path"; | ||
| /** | ||
| * image组件的工具库 | ||
| */ | ||
| export function getImageSize(imageSrc: string) { | ||
| return new Promise((resolve, reject) => { | ||
| const image = new Image(); | ||
| image.src = imageSrc; | ||
| if (image.complete) { | ||
| resolve({ | ||
| width: image.width, | ||
| height: image.height, | ||
| }); | ||
| } | ||
| image.onload = () => | ||
| resolve({ | ||
| width: image.width, | ||
| height: image.height, | ||
| }); | ||
| }); | ||
| } |
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,38 @@ | ||
| import { Masonry } from "masonic"; | ||
| import { useFakerImages } from "@utils/faker/index"; | ||
| export default function App() { | ||
| const lists = useFakerImages(100); | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| justifyContent: "center", | ||
| }} | ||
| > | ||
| <div className='feedContainer'> | ||
| <Masonry | ||
| items={lists} | ||
| columnWidth={180} | ||
| rowGutter={10} | ||
| columnGutter={10} | ||
| maxColumnCount={5} | ||
| render={FakerCard} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function FakerCard({ data: { id, image, name } }) { | ||
| return ( | ||
| <section key={id} className='element-item'> | ||
| <img src={image} alt='' loading='lazy' /> | ||
| <div className='footer'> | ||
| <p> | ||
| <span>{name}</span> | ||
| </p> | ||
| </div> | ||
| </section> | ||
| ); | ||
| } |
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,9 @@ | ||
| export function Once(fn) { | ||
| let tag = fn; | ||
| return function () { | ||
| if (tag) { | ||
| tag.apply(this, arguments); | ||
| tag = null; | ||
| } | ||
| }; | ||
| } |
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| import { defineConfig } from 'vite' | ||
| import react from '@vitejs/plugin-react-swc' | ||
| import { defineConfig } from "vite"; | ||
| import path from "path"; | ||
| import react from "@vitejs/plugin-react-swc"; | ||
|
|
||
| // https://vitejs.dev/config/ | ||
| export default defineConfig({ | ||
| resolve: { | ||
| alias: { | ||
| "@utils": path.resolve(__dirname, "src/utils"), | ||
| "@components": path.resolve(__dirname, "src/components"), | ||
| "@store": path.resolve(__dirname, "src/store"), | ||
| }, | ||
| }, | ||
| plugins: [react()], | ||
| }) | ||
| }); |