Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
vicotor
frontend
Commits
7dc8252b
Commit
7dc8252b
authored
Jul 17, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add try-catch
parent
fbc0ac74
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
17 deletions
+33
-17
useRatings.tsx
ui/marketplace/Rating/useRatings.tsx
+33
-17
No files found.
ui/marketplace/Rating/useRatings.tsx
View file @
7dc8252b
...
@@ -12,7 +12,7 @@ import * as mixpanel from 'lib/mixpanel/index';
...
@@ -12,7 +12,7 @@ import * as mixpanel from 'lib/mixpanel/index';
import
{
ADDRESS_COUNTERS
}
from
'
stubs/address
'
;
import
{
ADDRESS_COUNTERS
}
from
'
stubs/address
'
;
const
feature
=
config
.
features
.
marketplace
;
const
feature
=
config
.
features
.
marketplace
;
const
bas
e
=
(
feature
.
isEnabled
&&
feature
.
rating
)
?
const
airtabl
e
=
(
feature
.
isEnabled
&&
feature
.
rating
)
?
new
Airtable
({
apiKey
:
feature
.
rating
.
airtableApiKey
}).
base
(
feature
.
rating
.
airtableBaseId
)
:
new
Airtable
({
apiKey
:
feature
.
rating
.
airtableApiKey
}).
base
(
feature
.
rating
.
airtableBaseId
)
:
undefined
;
undefined
;
...
@@ -57,13 +57,21 @@ export default function useRatings() {
...
@@ -57,13 +57,21 @@ export default function useRatings() {
const
[
canRate
,
setCanRate
]
=
useState
<
boolean
|
undefined
>
(
undefined
);
const
[
canRate
,
setCanRate
]
=
useState
<
boolean
|
undefined
>
(
undefined
);
const
fetchRatings
=
useCallback
(
async
()
=>
{
const
fetchRatings
=
useCallback
(
async
()
=>
{
if
(
!
bas
e
)
{
if
(
!
airtabl
e
)
{
return
;
return
;
}
}
const
data
=
await
base
(
'
apps_ratings
'
).
select
({
fields
:
[
'
appId
'
,
'
rating
'
]
}).
all
();
try
{
const
ratings
=
formatRatings
(
data
);
const
data
=
await
airtable
(
'
apps_ratings
'
).
select
({
fields
:
[
'
appId
'
,
'
rating
'
]
}).
all
();
setRatings
(
ratings
);
const
ratings
=
formatRatings
(
data
);
},
[]);
setRatings
(
ratings
);
}
catch
(
error
)
{
toast
({
status
:
'
error
'
,
title
:
'
Error loading ratings
'
,
description
:
'
Please try again later
'
,
});
}
},
[
toast
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
async
function
fetch
()
{
async
function
fetch
()
{
...
@@ -78,18 +86,26 @@ export default function useRatings() {
...
@@ -78,18 +86,26 @@ export default function useRatings() {
async
function
fetchUserRatings
()
{
async
function
fetchUserRatings
()
{
setIsUserRatingLoading
(
true
);
setIsUserRatingLoading
(
true
);
let
userRatings
=
{}
as
Record
<
string
,
AppRating
>
;
let
userRatings
=
{}
as
Record
<
string
,
AppRating
>
;
if
(
address
&&
base
)
{
if
(
address
&&
airtable
)
{
const
data
=
await
base
(
'
users_ratings
'
).
select
({
try
{
filterByFormula
:
`address = "
${
address
}
"`
,
const
data
=
await
airtable
(
'
users_ratings
'
).
select
({
fields
:
[
'
appId
'
,
'
rating
'
],
filterByFormula
:
`address = "
${
address
}
"`
,
}).
all
();
fields
:
[
'
appId
'
,
'
rating
'
],
userRatings
=
formatRatings
(
data
);
}).
all
();
userRatings
=
formatRatings
(
data
);
}
catch
(
error
)
{
toast
({
status
:
'
error
'
,
title
:
'
Error loading user ratings
'
,
description
:
'
Please try again later
'
,
});
}
}
}
setUserRatings
(
userRatings
);
setUserRatings
(
userRatings
);
setIsUserRatingLoading
(
false
);
setIsUserRatingLoading
(
false
);
}
}
fetchUserRatings
();
fetchUserRatings
();
},
[
address
]);
},
[
address
,
toast
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
// TODO: uncomment validation after testing
// TODO: uncomment validation after testing
...
@@ -108,12 +124,12 @@ export default function useRatings() {
...
@@ -108,12 +124,12 @@ export default function useRatings() {
setIsSending
(
true
);
setIsSending
(
true
);
try
{
try
{
if
(
!
address
||
!
bas
e
)
{
if
(
!
address
||
!
airtabl
e
)
{
throw
new
Error
(
'
Address is missing
'
);
throw
new
Error
(
'
Address is missing
'
);
}
}
if
(
!
appRecordId
)
{
if
(
!
appRecordId
)
{
const
records
=
await
bas
e
(
'
apps_ratings
'
).
create
([
{
fields
:
{
appId
}
}
]);
const
records
=
await
airtabl
e
(
'
apps_ratings
'
).
create
([
{
fields
:
{
appId
}
}
]);
appRecordId
=
records
[
0
].
id
;
appRecordId
=
records
[
0
].
id
;
if
(
!
appRecordId
)
{
if
(
!
appRecordId
)
{
throw
new
Error
(
'
Record ID is missing
'
);
throw
new
Error
(
'
Record ID is missing
'
);
...
@@ -121,7 +137,7 @@ export default function useRatings() {
...
@@ -121,7 +137,7 @@ export default function useRatings() {
}
}
if
(
!
userRecordId
)
{
if
(
!
userRecordId
)
{
const
userRecords
=
await
bas
e
(
'
users_ratings
'
).
create
([
const
userRecords
=
await
airtabl
e
(
'
users_ratings
'
).
create
([
{
{
fields
:
{
fields
:
{
address
,
address
,
...
@@ -132,7 +148,7 @@ export default function useRatings() {
...
@@ -132,7 +148,7 @@ export default function useRatings() {
]);
]);
userRecordId
=
userRecords
[
0
].
id
;
userRecordId
=
userRecords
[
0
].
id
;
}
else
{
}
else
{
await
bas
e
(
'
users_ratings
'
).
update
(
userRecordId
,
{
rating
});
await
airtabl
e
(
'
users_ratings
'
).
update
(
userRecordId
,
{
rating
});
}
}
setUserRatings
({
setUserRatings
({
...
...
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