Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vsa-frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Alvarez
vsa-frontend
Commits
dd92051f
Commit
dd92051f
authored
Nov 29, 2023
by
Carlos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
saving progress
parent
d023f720
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
6 deletions
+107
-6
App.css
src/App.css
+10
-4
App.tsx
src/App.tsx
+17
-2
index.tsx
src/components/productListItem/index.tsx
+80
-0
No files found.
src/App.css
View file @
dd92051f
...
...
@@ -10,16 +10,22 @@
#findings-section
{
@apply
mt-4
max-h-96
overflow-scroll;
div
{
@apply
mb-
8
border
rounded-lg
h-16
;
@apply
flex
flex-col
justify-center;
>
div
{
@apply
mb-
3
border
rounded-lg
cursor-pointer
h-32
;
}
div
:last-child
{
>
div
:last-child
{
@apply
mb-0
}
}
}
.tran
{
-webkit-transition
:
height
1.60s
ease
;
-moz-transition
:
height
1.25s
ease
;
transition
:
height
1.25s
ease
;
}
#root
{
max-width
:
1280px
;
margin
:
0
auto
;
...
...
src/App.tsx
View file @
dd92051f
...
...
@@ -3,7 +3,8 @@ import "./App.css";
import
useSpeechToText
from
"react-hook-speech-to-text"
;
import
micIcon
from
"./assets/1608550_microphone_icon.png"
;
import
useFetch
from
"./hooks/useFetch"
;
import
{
useEffect
}
from
"react"
;
import
ProductListItem
from
"./components/productListItem"
;
import
{
useEffect
,
useState
}
from
"react"
;
function
App
()
{
const
{
...
...
@@ -26,6 +27,8 @@ function App() {
response
,
}
=
useFetch
(
`
${
import
.
meta
.
env
.
VITE_API_ENDPOINT
}
/todos`
);
const
[
currentProductId
,
setCurrentProductId
]
=
useState
<
null
|
number
>
(
null
);
useEffect
(()
=>
{
if
(
results
.
length
>
0
)
{
(
async
()
=>
{
...
...
@@ -79,7 +82,19 @@ function App() {
{
!
loading
&&
!
responseError
&&
response
&&
response
.
length
>
0
&&
(
<
div
id=
"findings-section"
>
{
response
.
map
((
content
)
=>
{
return
<
div
>
{
content
.
title
}
</
div
>;
return
(
<
ProductListItem
expandCallback=
{
(
pid
:
number
)
=>
setCurrentProductId
(
pid
)
}
current=
{
currentProductId
}
category=
{
content
.
category
}
price=
{
content
.
price
}
rating=
{
content
.
rating
}
id=
{
content
.
id
}
title=
{
content
.
title
}
description=
{
content
.
description
}
imgLink=
{
content
.
image
}
></
ProductListItem
>
);
})
}
</
div
>
)
}
...
...
src/components/productListItem/index.tsx
0 → 100644
View file @
dd92051f
import
React
,
{
useEffect
,
useRef
}
from
"react"
;
const
shouldUpdate
=
(
prevProps
,
nextProps
)
=>
{
// Custom comparison logic based on prevProps and nextProps
// Return true if props are equal, return false otherwise
return
!
prevProps
.
id
===
nextProps
.
id
;
};
const
ProductListItem
=
React
.
memo
((
props
:
{
id
:
number
;
title
:
string
;
description
:
string
;
imgLink
:
string
;
current
:
number
|
null
;
category
:
string
;
price
:
number
;
rating
:
{
rate
:
number
;
count
:
number
;
};
expandCallback
(
id
:
number
):
void
;
})
=>
{
const
currentElement
=
useRef
(
null
);
useEffect
(()
=>
{
debugger
const
newHeight
=
(
props
.
current
&&
props
.
current
==
props
.
id
)
?
`auto`
:
`8rem`
;
if
(
currentElement
.
current
)
currentElement
.
current
.
setAttribute
(
"style"
,
`height:
${
newHeight
}
`
);
},
[
props
])
return
(
<
div
id=
{
props
.
id
.
toString
()
}
className=
{
`flex tran`
}
onClick=
{
()
=>
{
// const newHeight = (props.current && props.current == props.id) ? `auto` : `8rem`;
// if(currentElement.current) currentElement.current.setAttribute("style",`height:$
{
newHeight
}
`);
props.expandCallback(props.id);
}
}
ref=
{
currentElement
}
>
<
div
className=
"mt-auto mb-auto ml-2 mr-2"
>
<
div
className=
"w-16"
>
<
img
src=
{
props
.
imgLink
}
></
img
>
</
div
>
</
div
>
<
div
className=
"flex flex-col p-2 pb-3"
>
<
div
className=
"text-left font-semibold"
id=
"header"
>
<
span
>
{
props
.
title
}
</
span
>
</
div
>
<
div
id=
"content"
className=
"overflow-scroll text-left text-sm"
>
<
span
>
{
props
.
description
}
</
span
>
{
props
.
current
&&
props
.
current
==
props
.
id
&&
(
<
div
className=
"flex flex-col"
>
<
div
>
<
span
className=
"font-semibold"
>
Category:
</
span
>
{
" "
}
<
span
>
{
props
.
category
}
</
span
>
{
" "
}
</
div
>
<
div
>
<
span
className=
"font-semibold"
>
Price:
</
span
>
{
" "
}
<
span
>
{
props
.
price
}
</
span
>
</
div
>
<
div
>
<
span
className=
"font-semibold"
>
Rating:
</
span
>
{
" "
}
<
span
>
{
props
.
rating
.
rate
}
</
span
>
</
div
>
<
div
>
<
span
className=
"font-semibold text-blue-web"
>
Click here to get the location
</
span
>
</
div
>
</
div
>
)
}
</
div
>
</
div
>
</
div
>
);
},
shouldUpdate
);
export
default
ProductListItem
;
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