-
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.
Merge pull request #27 from IFRCGo/feature/source-feeds
Add View all source
- Loading branch information
Showing
11 changed files
with
760 additions
and
504 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
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={5} | ||
/> | ||
<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,39 @@ | ||
.source-card { | ||
display: flex; | ||
gap: var(--go-ui-spacing-md); | ||
transition: box-shadow var(--go-ui-duration-transition-slow) ease-in-out; | ||
border-radius: var(--go-ui-border-radius-lg); | ||
box-shadow: var(--go-ui-box-shadow-md); | ||
text-decoration: none; | ||
|
||
&:hover { | ||
box-shadow: var(--go-ui-box-shadow-xl); | ||
} | ||
|
||
.source-detail { | ||
display: flex; | ||
gap: var(--go-ui-spacing-lg); | ||
border-radius: var(--go-ui-border-radius-lg); | ||
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,120 @@ | ||
import { | ||
useCallback, | ||
useMemo, | ||
useState, | ||
} from 'react'; | ||
import { | ||
gql, | ||
useQuery, | ||
} from '@apollo/client'; | ||
import { | ||
Container, | ||
Pager, | ||
RawList, | ||
} from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
import { | ||
isDefined, | ||
isNotDefined, | ||
} from '@togglecorp/fujs'; | ||
|
||
import Page from '#components/Page'; | ||
import { | ||
SourceFeedsQuery, | ||
SourceFeedsQueryVariables, | ||
} from '#generated/types/graphql'; | ||
|
||
import SourceCard from './SourceCard'; | ||
|
||
import i18n from './i18n.json'; | ||
|
||
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 | ||
title="AlertHub - Sources" | ||
heading={strings.sourceFeedsTitle} | ||
> | ||
<Container | ||
footerActions={( | ||
<Pager | ||
activePage={activePage} | ||
itemsCount={sourceFeedsResponse?.public?.feeds?.count ?? MAX_ITEM_PER_PAGE} | ||
maxItemsPerPage={MAX_ITEM_PER_PAGE} | ||
onActivePageChange={setActivePage} | ||
/> | ||
)} | ||
contentViewType="grid" | ||
numPreferredGridContentColumns={3} | ||
pending={sourceFeedsLoading} | ||
errored={isDefined(sourceFeedsError)} | ||
errorMessage={sourceFeedsError?.message} | ||
empty={isNotDefined(sourceFeedsResponse) | ||
|| sourceFeedsResponse.public.feeds.items.length === 0} | ||
spacing="comfortable" | ||
> | ||
<RawList | ||
data={sourceFeedsResponse?.public.feeds.items} | ||
renderer={SourceCard} | ||
rendererParams={rendererParams} | ||
keySelector={keySelector} | ||
/> | ||
</Container> | ||
</Page> | ||
); | ||
} | ||
|
||
Component.displayName = 'SourcesList'; |
Oops, something went wrong.