-
Notifications
You must be signed in to change notification settings - Fork 49
feat(web): starred-cases #1794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(web): starred-cases #1794
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3aff981
feat(web): starred-cases
tractorss 3785d5a
refactor(web): rabbit-feedback
tractorss 4bf05d1
Merge branch 'dev' into feat/case-bookmark
tractorss d7416a6
Merge branch 'dev' into feat/case-bookmark
alcercu 2d3fa5b
Merge branch 'dev' into feat/case-bookmark
tractorss f5e6562
refactor(web): use-set-to-store-favorite-case-ids
tractorss 165bfdc
refactor(web): update-favorite-cases-style
tractorss 1e74faa
Merge branch 'dev' into feat/case-bookmark
alcercu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,58 @@ | ||
import React, { useMemo } from "react"; | ||
import styled, { css } from "styled-components"; | ||
|
||
import { Button, Tooltip } from "@kleros/ui-components-library"; | ||
|
||
import Star from "svgs/icons/star.svg"; | ||
|
||
import useIsDesktop from "hooks/useIsDesktop"; | ||
import useStarredCases from "hooks/useStarredCases"; | ||
|
||
const StyledButton = styled(Button)<{ starred: boolean }>` | ||
background: none; | ||
padding: 0 0 2px 0; | ||
|
||
.button-svg { | ||
width: 24px; | ||
height: 24px; | ||
margin: 0; | ||
fill: none; | ||
|
||
path { | ||
stroke: ${({ theme }) => theme.secondaryPurple}; | ||
} | ||
${({ starred }) => | ||
starred && | ||
css` | ||
fill: ${({ theme }) => theme.secondaryPurple}; | ||
`}; | ||
} | ||
|
||
:hover { | ||
background: none; | ||
} | ||
`; | ||
|
||
const CaseStarButton: React.FC<{ id: string }> = ({ id }) => { | ||
const { starredCases, starCase } = useStarredCases(); | ||
const isDesktop = useIsDesktop(); | ||
const starred = useMemo(() => Boolean(starredCases.has(id)), [id, starredCases]); | ||
const text = starred ? "Remove from favorite" : "Add to favorite"; | ||
return ( | ||
<Tooltip {...{ text }} place={isDesktop ? "right" : "bottom"}> | ||
<StyledButton | ||
Icon={Star} | ||
text="" | ||
starred={starred} | ||
aria-label={text} | ||
aria-checked={starred} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
starCase(id); | ||
}} | ||
/> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default CaseStarButton; |
This file contains hidden or 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,81 @@ | ||
import React, { useMemo, useState } from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { StandardPagination } from "@kleros/ui-components-library"; | ||
|
||
import useStarredCases from "hooks/useStarredCases"; | ||
import { isUndefined } from "utils/index"; | ||
|
||
import { DisputeDetailsFragment, useCasesQuery } from "queries/useCasesQuery"; | ||
|
||
import { responsiveSize } from "styles/responsiveSize"; | ||
|
||
import DisputeView from "components/DisputeView"; | ||
import { SkeletonDisputeCard } from "components/StyledSkeleton"; | ||
|
||
const Container = styled.div` | ||
margin-top: ${responsiveSize(48, 80)}; | ||
`; | ||
|
||
const Title = styled.h1` | ||
margin-bottom: 4px; | ||
`; | ||
|
||
const DisputeContainer = styled.div` | ||
--gap: 16px; | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(min(100%, max(312px, (100% - var(--gap) * 2)/3)), 1fr)); | ||
align-items: stretch; | ||
gap: var(--gap); | ||
`; | ||
|
||
const StyledLabel = styled.label` | ||
display: block; | ||
color: ${({ theme }) => theme.primaryBlue}; | ||
cursor: pointer; | ||
margin-bottom: ${responsiveSize(12, 16)}; | ||
:hover { | ||
color: ${({ theme }) => theme.secondaryBlue}; | ||
} | ||
`; | ||
|
||
const StyledPagination = styled(StandardPagination)` | ||
margin-top: 24px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
`; | ||
|
||
const FavoriteCases: React.FC = () => { | ||
const { starredCaseIds, clearAll } = useStarredCases(); | ||
|
||
const [currentPage, setCurrentPage] = useState(1); | ||
const casesPerPage = 3; | ||
const totalPages = Math.ceil(starredCaseIds.length / casesPerPage); | ||
|
||
const { data } = useCasesQuery((currentPage - 1) * casesPerPage, casesPerPage, { | ||
id_in: starredCaseIds, | ||
}); | ||
|
||
const disputes: DisputeDetailsFragment[] = useMemo(() => data?.disputes as DisputeDetailsFragment[], [data]); | ||
|
||
return starredCaseIds.length > 0 && (isUndefined(disputes) || disputes.length > 0) ? ( | ||
<Container> | ||
<Title>Favorite Cases</Title> | ||
<StyledLabel onClick={clearAll}>Clear all</StyledLabel> | ||
<DisputeContainer> | ||
{isUndefined(disputes) | ||
? Array.from({ length: 3 }).map((_, index) => <SkeletonDisputeCard key={index} />) | ||
: disputes.map((dispute) => <DisputeView key={dispute.id} {...dispute} overrideIsList />)} | ||
</DisputeContainer> | ||
{totalPages > 1 ? ( | ||
<StyledPagination | ||
currentPage={currentPage} | ||
numPages={totalPages} | ||
callback={(page: number) => setCurrentPage(page)} | ||
/> | ||
) : null} | ||
</Container> | ||
) : null; | ||
}; | ||
|
||
export default FavoriteCases; |
This file contains hidden or 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,26 @@ | ||
import { useMemo } from "react"; | ||
|
||
import { useLocalStorage } from "./useLocalStorage"; | ||
|
||
const useStarredCases = () => { | ||
const initialValue = new Set<string>(); | ||
|
||
const [localStarredCases, setLocalStarredCases] = useLocalStorage("starredCases", Array.from(initialValue)); | ||
|
||
const starredCases = useMemo(() => new Set<string>(localStarredCases), [localStarredCases]); | ||
const starredCaseIds = Array.from(starredCases.keys()); | ||
|
||
const starCase = (id: string) => { | ||
if (starredCases.has(id)) starredCases.delete(id); | ||
else starredCases.add(id); | ||
|
||
setLocalStarredCases(Array.from(starredCases)); | ||
}; | ||
|
||
const clearAll = () => { | ||
setLocalStarredCases(Array.from(initialValue)); | ||
}; | ||
return { starredCases, starredCaseIds, starCase, clearAll }; | ||
}; | ||
|
||
export default useStarredCases; |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.