Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
travel
Commits
f9ed2d93
Commit
f9ed2d93
authored
Jul 06, 2022
by
백승민
Browse files
pic pagination
parent
58a76189
Changes
5
Hide whitespace changes
Inline
Side-by-side
frontend/package.json
View file @
f9ed2d93
...
...
@@ -29,6 +29,7 @@
"webpack-dev-server"
:
"^4.9.2"
},
"dependencies"
:
{
"axios"
:
"^0.27.2"
,
"react"
:
"^18.2.0"
,
"react-dom"
:
"^18.2.0"
,
"react-router-dom"
:
"^6.3.0"
...
...
frontend/src/Pages/picpagination.tsx
0 → 100644
View file @
f9ed2d93
import
React
from
"
react
"
;
type
num
=
{
total
:
number
,
page
:
number
,
setPage
:
Function
}
export
default
function
Pagination
({
total
,
page
,
setPage
}
:
num
)
{
const
numPages
=
Math
.
ceil
(
total
/
15
);
return
(
<
div
>
<
button
onClick
=
{
()
=>
setPage
(
page
-
1
)
}
disabled
=
{
page
===
1
}
>
<
</
button
>
{
Array
(
numPages
)
.
fill
(
1
)
.
map
((
_
,
i
)
=>
(
<
button
key
=
{
i
+
1
}
onClick
=
{
()
=>
setPage
(
i
+
1
)
}
>
{
i
+
1
}
</
button
>
))
}
<
button
onClick
=
{
()
=>
setPage
(
page
+
1
)
}
disabled
=
{
page
===
numPages
}
>
>
</
button
>
</
div
>
);
};
frontend/src/pages/body.tsx
View file @
f9ed2d93
import
React
,
{
useEffect
,
MouseEvent
}
from
"
react
"
;
import
React
,
{
useEffect
,
MouseEvent
,
useState
}
from
"
react
"
;
import
{
Outlet
,
useSearchParams
}
from
"
react-router-dom
"
;
import
Theme
from
"
./theme
"
;
import
Citylist
from
"
./citylist
"
;
import
{
getPicure
}
from
"
./pic
"
;
import
Pagination
from
"
./picpagination
"
import
{
LibManifestPlugin
}
from
"
webpack
"
;
const
initSearchParams
=
{
"
theme
"
:
""
,
"
city
"
:
""
}
export
default
function
Body
()
{
let
limit
=
15
;
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
(
initSearchParams
);
const
[
page
,
setPage
]
=
useState
(
1
);
const
offset
=
(
page
-
1
)
*
limit
;
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
(
initSearchParams
)
let
getPics
=
getPicure
();
useEffect
(()
=>
{
...
...
@@ -31,11 +37,16 @@ export default function Body() {
city
:
event
.
currentTarget
.
id
})
}
let
themechange
=
searchParams
.
get
(
'
theme
'
);
let
citylistchange
=
searchParams
.
get
(
'
city
'
);
const
Idpics
=
getPics
.
filter
(
p
=>
{
return
(
p
.
themeid
==
searchParams
.
get
(
'
theme
'
)
&&
p
.
cityid
==
searchParams
.
get
(
'
city
'
))
||
(
p
.
themeid
==
searchParams
.
get
(
'
theme
'
)
&&
searchParams
.
get
(
'
city
'
)
==
""
)
||
(
searchParams
.
get
(
'
theme
'
)
==
""
&&
p
.
cityid
==
searchParams
.
get
(
'
city
'
))
||
(
searchParams
.
get
(
'
theme
'
)
==
""
&&
searchParams
.
get
(
'
city
'
)
==
""
)
return
(
p
.
themeid
==
themechange
&&
p
.
cityid
==
citylistchange
)
||
(
p
.
themeid
==
themechange
&&
citylistchange
==
""
)
||
(
themechange
==
""
&&
p
.
cityid
==
citylistchange
)
||
(
themechange
==
""
&&
citylistchange
==
""
)
})
...
...
@@ -44,14 +55,16 @@ export default function Body() {
<
Theme
handleClick
=
{
themeHandleClick
}
/>
<
div
className
=
"flex flex-col md:flex-row py-10 "
>
<
Citylist
handleClick
=
{
cityHandleClick
}
/>
<
div
className
=
"flex md:mr-10 md:basis-4/5 grid grid-rows-3 grid-cols-5"
>
{
Idpics
.
map
((
pic
,
index
:
number
)
=>
(
<
div
className
=
"flex
-row
md:mr-10 md:basis-4/5 grid grid-rows-3 grid-cols-5"
>
{
Idpics
.
slice
(
offset
,
offset
+
limit
).
map
((
pic
,
index
:
number
)
=>
(
<
div
className
=
"m-1 shrink-0 bg-gray-200 rounded overflow-hidden shadow-md"
key
=
{
index
}
>
<
img
src
=
{
pic
.
url
}
className
=
"w-full h-10 md:h-20 object-c
ov
er"
/>
<
img
src
=
{
pic
.
url
}
className
=
"w-full h-10 md:h-20 object-c
ent
er"
/>
<
p
className
=
"text-center text-xs"
>
{
pic
.
name
}
</
p
>
</
div
>
))
}
<
Pagination
total
=
{
Idpics
.
length
}
page
=
{
page
}
setPage
=
{
setPage
}
/>
</
div
>
</
div
>
<
Outlet
/>
</
div
>
...
...
frontend/webpack.dev.js
View file @
f9ed2d93
...
...
@@ -6,5 +6,13 @@ const common = require("./webpack.common.js");
module
.
exports
=
merge
(
common
,
{
mode
:
"
development
"
,
devtool
:
"
inline-source-map
"
,
devServer
:
{
historyApiFallback
:
true
},
devServer
:
{
proxy
:
[
{
context
:
[
"
/api
"
],
target
:
"
http://localhost:3000
"
,
changeOrigin
:
true
,
},
],
historyApiFallback
:
true
},
});
src/app.ts
View file @
f9ed2d93
...
...
@@ -9,7 +9,6 @@ app.use(express.urlencoded({ extended: true }));
app
.
use
(
cookieParser
());
app
.
use
(
"
/api
"
,
router
);
app
.
use
((
err
:
any
,
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
console
.
log
(
"
익스프레스 에러:
"
,
err
);
res
.
status
(
err
.
statusCode
||
500
).
send
(
err
.
message
||
"
서버 에러
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment