-
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.
Add Carts and statice data for view all source
- Add query to display the source details in view all source - Fix source feed styling - Add source pagination
- Loading branch information
1 parent
42f28d2
commit fadd1f6
Showing
11 changed files
with
753 additions
and
503 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
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
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,6 @@ | ||
{ | ||
"namespace": "sourceCard", | ||
"strings": { | ||
"sourceCardAlt": "Logo" | ||
} | ||
} |
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,52 @@ | ||
import { Link } from 'react-router-dom'; | ||
import { | ||
Container, | ||
Header, | ||
} from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
|
||
import { SourceFeedsQuery } from '#generated/types/graphql'; | ||
|
||
import i18n from './i18n.json'; | ||
import styles from './styles.module.css'; | ||
|
||
type SourceFeed = NonNullable<NonNullable<SourceFeedsQuery['public']>['feeds']>['items'][number]; | ||
|
||
interface Props { | ||
data: SourceFeed; | ||
} | ||
|
||
function SourceCard(props: Props) { | ||
const { | ||
data, | ||
} = props; | ||
|
||
const strings = useTranslation(i18n); | ||
|
||
return ( | ||
<Link | ||
className={styles.sourceCard} | ||
to={data?.url} | ||
> | ||
<Container | ||
childrenContainerClassName={styles.sourceDetail} | ||
> | ||
<img | ||
className={styles.figure} | ||
src={data?.languages?.map((image) => image.logo)?.[0] || ''} | ||
alt={strings.sourceCardAlt} | ||
/> | ||
<div className={styles.title}> | ||
<Header | ||
heading={data?.languages?.map((lang) => lang.name)} | ||
headingLevel={6} | ||
/> | ||
<div className={styles.language}> | ||
{data?.languages?.map((name) => name.language)} | ||
</div> | ||
</div> | ||
</Container> | ||
</Link> | ||
); | ||
} | ||
export default SourceCard; |
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,33 @@ | ||
.source-card { | ||
display: flex; | ||
gap: var(--go-ui-spacing-md); | ||
text-decoration: none; | ||
|
||
.source-detail { | ||
display: flex; | ||
gap: var(--go-ui-spacing-lg); | ||
border-radius: var(--go-ui-border-radius-lg); | ||
box-shadow: var(--go-ui-box-shadow-md); | ||
padding: var(--go-ui-spacing-lg); | ||
|
||
.title { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--go-ui-spacing-md); | ||
justify-content: space-between; | ||
color: var(--go-ui-color-text); | ||
} | ||
|
||
.language { | ||
width: fit-content; | ||
text-decoration: none; | ||
color: var(--go-ui-color-gray-60); | ||
font-weight: var(--go-ui-font-weight-medium); | ||
} | ||
|
||
.figure { | ||
width: 10rem; | ||
height: 4rem; | ||
} | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"namespace": "viewAllSource", | ||
"strings": { | ||
"sourceFeedsTitle":"Source Feeds" | ||
} | ||
} |
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,115 @@ | ||
import { | ||
useCallback, | ||
useMemo, | ||
useState, | ||
} from 'react'; | ||
import { | ||
gql, | ||
useQuery, | ||
} from '@apollo/client'; | ||
import { | ||
Container, | ||
List, | ||
Pager, | ||
} from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
import { isDefined } from '@togglecorp/fujs'; | ||
|
||
import Page from '#components/Page'; | ||
import { | ||
SourceFeedsQuery, | ||
SourceFeedsQueryVariables, | ||
} from '#generated/types/graphql'; | ||
|
||
import SourceCard from './SourceCard'; | ||
|
||
import i18n from './i18n.json'; | ||
import styles from './style.module.css'; | ||
|
||
const SOURCE_FEEDS = gql` | ||
query SourceFeeds($pagination: OffsetPaginationInput) { | ||
public { | ||
feeds(pagination: $pagination) { | ||
limit | ||
offset | ||
items { | ||
languages { | ||
logo | ||
name | ||
language | ||
id | ||
} | ||
id | ||
url | ||
} | ||
count | ||
} | ||
} | ||
} | ||
`; | ||
|
||
type SourceFeed = NonNullable<NonNullable<SourceFeedsQuery['public']>['feeds']>['items'][number]; | ||
|
||
const MAX_ITEM_PER_PAGE = 21; | ||
|
||
const keySelector = (source: SourceFeed) => source.id; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function Component() { | ||
const strings = useTranslation(i18n); | ||
const [activePage, setActivePage] = useState(1); | ||
|
||
const variables = useMemo(() => ({ | ||
pagination: { | ||
offset: (activePage - 1) * MAX_ITEM_PER_PAGE, | ||
limit: MAX_ITEM_PER_PAGE, | ||
}, | ||
}), [ | ||
activePage, | ||
]); | ||
|
||
const { | ||
data: sourceFeedsResponse, | ||
loading: sourceFeedsLoading, | ||
error: sourceFeedsError, | ||
} = useQuery<SourceFeedsQuery, SourceFeedsQueryVariables>( | ||
SOURCE_FEEDS, | ||
{ | ||
variables, | ||
}, | ||
); | ||
|
||
const rendererParams = useCallback((_: string, value: SourceFeed) => ({ | ||
data: value, | ||
}), []); | ||
|
||
return ( | ||
<Page> | ||
<Container | ||
heading={strings.sourceFeedsTitle} | ||
withHeaderBorder | ||
footerActions={( | ||
<Pager | ||
activePage={activePage} | ||
itemsCount={sourceFeedsResponse?.public?.feeds?.count ?? MAX_ITEM_PER_PAGE} | ||
maxItemsPerPage={MAX_ITEM_PER_PAGE} | ||
onActivePageChange={setActivePage} | ||
/> | ||
)} | ||
> | ||
<List | ||
className={styles.sourcesList} | ||
data={sourceFeedsResponse?.public.feeds.items} | ||
renderer={SourceCard} | ||
rendererParams={rendererParams} | ||
keySelector={keySelector} | ||
pending={sourceFeedsLoading} | ||
filtered={false} | ||
errored={isDefined(sourceFeedsError)} | ||
/> | ||
</Container> | ||
</Page> | ||
); | ||
} | ||
|
||
Component.displayName = 'SourcesList'; |
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,5 @@ | ||
.sources-list { | ||
display: grid; | ||
grid-template-columns: repeat(auto-fit, minmax(23rem, 1fr)); | ||
grid-gap: var(--go-ui-spacing-lg); | ||
} |
Oops, something went wrong.