Skip to content

Commit

Permalink
feat(ui): add info card (#16931)
Browse files Browse the repository at this point in the history
* feat: init

* feat: stfuf

* fix:error message

* fix: responseive

* fix: switch in inline

* fix: use wrapper

* fix: add layout switch

* fix: disable tags

* fix: make whole card clickable

* chore: reduce columns

* feat: updated status logic

* feat: add time values

* feat: add time part

* chore: change props name

* chore: remove conidtional

* chore: remove imports

* fix: wrong message id

* fix: add /en locale

* fix: undefined if empty array

* chore: simplify card

* chore: fix color

* fix: simplify card

* fix: increase border radius

* fix: bunny comments

* fix: add key

* fix: something

* chore: fix codeowners

* chore: CODEOWNERS indentation

* feat: update pagination

* chore: fix

* chore: fix nr2

* feat: PAGED

* chore: codeowners

* chore: remove improts

* chore: revert

* fix: review comments

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thorkellmani and kodiakhq[bot] authored Dec 17, 2024
1 parent c07421f commit 7e8c82f
Show file tree
Hide file tree
Showing 19 changed files with 501 additions and 206 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ codemagic.yaml
/apps/services/regulations-admin-backend/ @island-is/hugsmidjan
/apps/services/user-profile/ @island-is/hugsmidjan @island-is/juni @island-is/aranja
/apps/web/components/Grant/ @island-is/hugsmidjan
/apps/web/components/PlazaCard/ @island-is/hugsmidjan
/apps/web/screens/Grants/ @island-is/hugsmidjan
/apps/web/screens/Regulations/ @island-is/hugsmidjan
/apps/web/components/Regulations/ @island-is/hugsmidjan
Expand Down
5 changes: 0 additions & 5 deletions apps/web/components/PlazaCard/PlazaCard.css.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/web/components/real.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

export * from './Card/Card'
export * from './PlazaCard/PlazaCard'
export * from './Header/Header'
export * from './SearchInput/SearchInput'
export * from './LanguageToggler/LanguageToggler'
Expand Down
1 change: 0 additions & 1 deletion apps/web/screens/Grants/Grant/GrantSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Stack,
Text,
} from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { Locale } from '@island.is/shared/types'
import { isDefined } from '@island.is/shared/utils'
import { InstitutionPanel } from '@island.is/web/components'
Expand Down
69 changes: 54 additions & 15 deletions apps/web/screens/Grants/SearchResults/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useState } from 'react'
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
import { useIntl } from 'react-intl'
import { useWindowSize } from 'react-use'
import debounce from 'lodash/debounce'
Expand All @@ -16,6 +16,7 @@ import {
BreadCrumbItem,
Breadcrumbs,
FilterInput,
Pagination,
Text,
} from '@island.is/island-ui/core'
import { theme } from '@island.is/island-ui/theme'
Expand Down Expand Up @@ -55,9 +56,11 @@ export interface SearchState {
organization?: Array<string>
}

const PAGE_SIZE = 8

const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
locale,
initialGrants,
initialGrantList,
tags,
}) => {
const { formatMessage } = useIntl()
Expand All @@ -67,7 +70,12 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
const parentUrl = linkResolver('styrkjatorg', [], locale).href
const currentUrl = linkResolver('styrkjatorgsearch', [], locale).href

const [grants, setGrants] = useState<Array<Grant>>(initialGrants ?? [])
const [grants, setGrants] = useState<Array<Grant>>(
initialGrantList?.items ?? [],
)
const [totalHits, setTotalHits] = useState<number | undefined>(
initialGrantList?.total ?? 0,
)
const [searchState, setSearchState] = useState<SearchState>()
const [initialRender, setInitialRender] = useState<boolean>(true)

Expand All @@ -89,7 +97,7 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
const organizations = searchParams.getAll('organization')

setSearchState({
page: page ? Number.parseInt(page) : undefined,
page: page ? Number.parseInt(page) : 1,
query: searchParams.get('query') ?? undefined,
status: statuses.length ? statuses : undefined,
category: categories.length ? categories : undefined,
Expand All @@ -98,6 +106,13 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
})
}, [])

const totalPages = useMemo(() => {
if (!totalHits) {
return
}
return totalHits > PAGE_SIZE ? Math.ceil(totalHits / PAGE_SIZE) : 1
}, [totalHits])

const updateUrl = useCallback(() => {
if (!searchState) {
return
Expand Down Expand Up @@ -134,7 +149,7 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
organizations: searchState?.organization,
page: searchState?.page,
search: searchState?.query,
size: 8,
size: PAGE_SIZE,
statuses: searchState?.status,
types: searchState?.type,
},
Expand All @@ -143,6 +158,7 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
.then((res) => {
if (res.data) {
setGrants(res.data.getGrants.items)
setTotalHits(res.data.getGrants.total)
} else if (res.error) {
setGrants([])
console.error('Error fetching grants', res.error)
Expand Down Expand Up @@ -199,7 +215,7 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({

const onResetFilter = () => {
setSearchState({
page: undefined,
page: 1,
query: undefined,
status: undefined,
category: undefined,
Expand All @@ -210,18 +226,18 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
}

const hitsMessage = useMemo(() => {
if (!grants) {
if (!totalHits) {
return
}
if (grants.length === 1) {
if (totalHits === 1) {
return formatMessage(m.search.resultFound, {
arg: <strong>{grants.length}</strong>,
arg: <strong>{totalHits}</strong>,
})
}
return formatMessage(m.search.resultsFound, {
arg: <strong>{grants.length}</strong>,
arg: <strong>{totalHits}</strong>,
})
}, [formatMessage, grants])
}, [formatMessage, totalHits])

return (
<GrantWrapper
Expand Down Expand Up @@ -290,6 +306,28 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({
locale={locale}
/>
</Box>
{totalPages && totalPages > 1 ? (
<Box marginTop={2} marginBottom={0}>
<Pagination
variant="purple"
page={searchState?.page ?? 1}
itemsPerPage={PAGE_SIZE}
totalItems={totalHits}
totalPages={totalPages}
renderLink={(page, className, children) => (
<Box
cursor="pointer"
className={className}
onClick={() => {
updateSearchStateValue('page', page)
}}
>
{children}
</Box>
)}
/>
</Box>
) : undefined}
</SidebarLayout>
)}
{isMobile && (
Expand Down Expand Up @@ -335,19 +373,19 @@ const GrantsSearchResultsPage: CustomScreen<GrantsHomeProps> = ({

interface GrantsHomeProps {
locale: Locale
initialGrants?: Array<Grant>
initialGrantList?: GrantList
tags?: Array<GenericTag>
}

const GrantsSearchResults: CustomScreen<GrantsHomeProps> = ({
initialGrants,
initialGrantList,
tags,
customPageData,
locale,
}) => {
return (
<GrantsSearchResultsPage
initialGrants={initialGrants}
initialGrantList={initialGrantList}
tags={tags}
locale={locale}
customPageData={customPageData}
Expand Down Expand Up @@ -404,8 +442,9 @@ GrantsSearchResults.getProps = async ({ apolloClient, locale, query }) => {
},
}),
])

return {
initialGrants: getGrants.items,
initialGrantList: getGrants,
tags: getGenericTagsInTagGroups ?? undefined,
locale: locale as Locale,
themeConfig: {
Expand Down
Loading

0 comments on commit 7e8c82f

Please sign in to comment.