Skip to content

Commit

Permalink
Merge pull request #1713 from streamr-dev/front-1676-sponsorships-sho…
Browse files Browse the repository at this point in the history
…uld-be-searchable-by-their-contract-address

FRONT-1676: Sponsorships should be searchable by their contract address
  • Loading branch information
mondoreale authored Nov 14, 2023
2 parents a1c1a2d + 03faac4 commit 5ce96f8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
27 changes: 21 additions & 6 deletions src/generated/gql/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type Delegation_Filter = {

export enum Delegation_OrderBy {
Delegator = 'delegator',
DelegatorCumulativeEarningsWei = 'delegator__cumulativeEarningsWei',
DelegatorId = 'delegator__id',
DelegatorNumberOfDelegations = 'delegator__numberOfDelegations',
DelegatorTotalValueDataWei = 'delegator__totalValueDataWei',
Expand Down Expand Up @@ -146,6 +147,7 @@ export enum Delegation_OrderBy {

export type Delegator = {
__typename?: 'Delegator';
cumulativeEarningsWei: Scalars['BigInt']['output'];
delegations: Array<Delegation>;
id: Scalars['ID']['output'];
numberOfDelegations: Scalars['Int']['output'];
Expand Down Expand Up @@ -253,6 +255,7 @@ export enum DelegatorDailyBucket_OrderBy {
CumulativeEarningsWei = 'cumulativeEarningsWei',
Date = 'date',
Delegator = 'delegator',
DelegatorCumulativeEarningsWei = 'delegator__cumulativeEarningsWei',
DelegatorId = 'delegator__id',
DelegatorNumberOfDelegations = 'delegator__numberOfDelegations',
DelegatorTotalValueDataWei = 'delegator__totalValueDataWei',
Expand All @@ -265,6 +268,14 @@ export type Delegator_Filter = {
/** Filter for the block changed event. */
_change_block?: InputMaybe<BlockChangedFilter>;
and?: InputMaybe<Array<InputMaybe<Delegator_Filter>>>;
cumulativeEarningsWei?: InputMaybe<Scalars['BigInt']['input']>;
cumulativeEarningsWei_gt?: InputMaybe<Scalars['BigInt']['input']>;
cumulativeEarningsWei_gte?: InputMaybe<Scalars['BigInt']['input']>;
cumulativeEarningsWei_in?: InputMaybe<Array<Scalars['BigInt']['input']>>;
cumulativeEarningsWei_lt?: InputMaybe<Scalars['BigInt']['input']>;
cumulativeEarningsWei_lte?: InputMaybe<Scalars['BigInt']['input']>;
cumulativeEarningsWei_not?: InputMaybe<Scalars['BigInt']['input']>;
cumulativeEarningsWei_not_in?: InputMaybe<Array<Scalars['BigInt']['input']>>;
delegations_?: InputMaybe<Delegation_Filter>;
id?: InputMaybe<Scalars['ID']['input']>;
id_gt?: InputMaybe<Scalars['ID']['input']>;
Expand Down Expand Up @@ -295,6 +306,7 @@ export type Delegator_Filter = {
};

export enum Delegator_OrderBy {
CumulativeEarningsWei = 'cumulativeEarningsWei',
Delegations = 'delegations',
Id = 'id',
NumberOfDelegations = 'numberOfDelegations',
Expand Down Expand Up @@ -2615,6 +2627,7 @@ export enum QueueEntry_OrderBy {
Amount = 'amount',
Date = 'date',
Delegator = 'delegator',
DelegatorCumulativeEarningsWei = 'delegator__cumulativeEarningsWei',
DelegatorId = 'delegator__id',
DelegatorNumberOfDelegations = 'delegator__numberOfDelegations',
DelegatorTotalValueDataWei = 'delegator__totalValueDataWei',
Expand Down Expand Up @@ -4493,7 +4506,8 @@ export type SponsorshipFieldsFragment = { __typename?: 'Sponsorship', id: string
export type GetAllSponsorshipsQueryVariables = Exact<{
first?: InputMaybe<Scalars['Int']['input']>;
skip?: InputMaybe<Scalars['Int']['input']>;
streamContains: Scalars['String']['input'];
searchQuery: Scalars['String']['input'];
id: Scalars['ID']['input'];
orderBy?: InputMaybe<Sponsorship_OrderBy>;
orderDirection?: InputMaybe<OrderDirection>;
}>;
Expand All @@ -4504,7 +4518,8 @@ export type GetAllSponsorshipsQuery = { __typename?: 'Query', sponsorships: Arra
export type GetSponsorshipsByCreatorQueryVariables = Exact<{
first?: InputMaybe<Scalars['Int']['input']>;
skip?: InputMaybe<Scalars['Int']['input']>;
streamContains: Scalars['String']['input'];
searchQuery: Scalars['String']['input'];
id: Scalars['ID']['input'];
creator: Scalars['String']['input'];
orderBy?: InputMaybe<Sponsorship_OrderBy>;
orderDirection?: InputMaybe<OrderDirection>;
Expand Down Expand Up @@ -4913,11 +4928,11 @@ export const GetOperatorByOwnerAddressDocument = gql`
${OperatorFieldsFragmentDoc}`;
export type GetOperatorByOwnerAddressQueryResult = Apollo.QueryResult<GetOperatorByOwnerAddressQuery, GetOperatorByOwnerAddressQueryVariables>;
export const GetAllSponsorshipsDocument = gql`
query getAllSponsorships($first: Int, $skip: Int, $streamContains: String!, $orderBy: Sponsorship_orderBy, $orderDirection: OrderDirection) {
query getAllSponsorships($first: Int, $skip: Int, $searchQuery: String!, $id: ID!, $orderBy: Sponsorship_orderBy, $orderDirection: OrderDirection) {
sponsorships(
first: $first
skip: $skip
where: {stream_contains_nocase: $streamContains}
where: {or: [{stream_contains_nocase: $searchQuery}, {id: $id}]}
orderBy: $orderBy
orderDirection: $orderDirection
) {
Expand All @@ -4927,11 +4942,11 @@ export const GetAllSponsorshipsDocument = gql`
${SponsorshipFieldsFragmentDoc}`;
export type GetAllSponsorshipsQueryResult = Apollo.QueryResult<GetAllSponsorshipsQuery, GetAllSponsorshipsQueryVariables>;
export const GetSponsorshipsByCreatorDocument = gql`
query getSponsorshipsByCreator($first: Int, $skip: Int, $streamContains: String!, $creator: String!, $orderBy: Sponsorship_orderBy, $orderDirection: OrderDirection) {
query getSponsorshipsByCreator($first: Int, $skip: Int, $searchQuery: String!, $id: ID!, $creator: String!, $orderBy: Sponsorship_orderBy, $orderDirection: OrderDirection) {
sponsorships(
first: $first
skip: $skip
where: {creator: $creator, stream_contains_nocase: $streamContains}
where: {and: [{creator: $creator}, {or: [{stream_contains_nocase: $searchQuery}, {id: $id}]}]}
orderBy: $orderBy
orderDirection: $orderDirection
) {
Expand Down
14 changes: 8 additions & 6 deletions src/getters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@ export async function getFirstEnsNameFor(address: string): Promise<string> {
export async function getAllSponsorships({
first,
skip,
streamId = '',
searchQuery = '',
orderBy = DEFAULT_SPONSORSHIP_ORDER_BY,
orderDirection = DEFAULT_ORDER_DIRECTION,
force = false,
}: {
first?: number
skip?: number
streamId?: string
searchQuery?: string
orderBy?: Sponsorship_OrderBy
orderDirection?: OrderDirection
force?: boolean
Expand All @@ -294,7 +294,8 @@ export async function getAllSponsorships({
variables: {
first,
skip,
streamContains: streamId,
searchQuery,
id: searchQuery.toLowerCase(),
orderBy,
orderDirection,
},
Expand Down Expand Up @@ -349,14 +350,14 @@ export async function getSponsorshipsByCreator(
{
first,
skip,
streamId = '',
searchQuery = '',
orderBy = DEFAULT_SPONSORSHIP_ORDER_BY,
orderDirection = DEFAULT_ORDER_DIRECTION,
force = false,
}: {
first?: number
skip?: number
streamId?: string
searchQuery?: string
orderBy?: Sponsorship_OrderBy
orderDirection?: OrderDirection
force?: boolean
Expand All @@ -372,7 +373,8 @@ export async function getSponsorshipsByCreator(
variables: {
first,
skip,
streamContains: streamId,
searchQuery,
id: searchQuery.toLowerCase(),
creator,
orderBy,
orderDirection,
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/sponsorships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ export function useSponsorshipsForCreatorQuery(
address: string | undefined,
{
pageSize = 10,
streamId,
searchQuery,
orderBy,
orderDirection,
}: {
pageSize?: number
streamId?: string
searchQuery?: string
orderBy?: string
orderDirection?: 'asc' | 'desc'
} = {},
Expand All @@ -105,7 +105,7 @@ export function useSponsorshipsForCreatorQuery(
'useSponsorshipsForCreatorQuery',
creator,
pageSize,
streamId,
searchQuery,
orderBy,
orderDirection,
],
Expand All @@ -122,7 +122,7 @@ export function useSponsorshipsForCreatorQuery(
getSponsorshipsByCreator(creator, {
first: pageSize,
skip,
streamId,
searchQuery,
orderBy: mapSponsorshipOrder(orderBy),
orderDirection: orderDirection as OrderDirection,
force: true,
Expand All @@ -148,20 +148,20 @@ function invalidateAllSponsorshipsQueries() {

export function useAllSponsorshipsQuery({
pageSize = 10,
streamId,
searchQuery,
orderBy,
orderDirection,
}: {
pageSize?: number
streamId?: string
searchQuery?: string
orderBy?: string
orderDirection?: 'asc' | 'desc'
}) {
return useInfiniteQuery({
queryKey: [
'useAllSponsorshipsQuery',
pageSize,
streamId,
searchQuery,
orderBy,
orderDirection,
],
Expand All @@ -171,7 +171,7 @@ export function useAllSponsorshipsQuery({
getAllSponsorships({
first: pageSize,
skip,
streamId,
searchQuery,
orderBy: mapSponsorshipOrder(orderBy),
orderDirection: orderDirection as OrderDirection,
force: true,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SponsorshipsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export const SponsorshipsPage = () => {

const allSponsorshipsQuery = useAllSponsorshipsQuery({
pageSize: PAGE_SIZE,
streamId: searchQuery,
searchQuery,
orderBy,
orderDirection,
})

const mySponsorshipsQuery = useSponsorshipsForCreatorQuery(wallet, {
pageSize: PAGE_SIZE,
streamId: searchQuery,
searchQuery,
orderBy,
orderDirection,
})
Expand Down
15 changes: 11 additions & 4 deletions src/queries/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,15 @@ gql`
query getAllSponsorships(
$first: Int
$skip: Int
$streamContains: String!
$searchQuery: String!
$id: ID!
$orderBy: Sponsorship_orderBy
$orderDirection: OrderDirection
) {
sponsorships(
first: $first
skip: $skip
where: { stream_contains_nocase: $streamContains }
where: { or: [{ stream_contains_nocase: $searchQuery }, { id: $id }] }
orderBy: $orderBy
orderDirection: $orderDirection
) {
Expand All @@ -230,15 +231,21 @@ gql`
query getSponsorshipsByCreator(
$first: Int
$skip: Int
$streamContains: String!
$searchQuery: String!
$id: ID!
$creator: String!
$orderBy: Sponsorship_orderBy
$orderDirection: OrderDirection
) {
sponsorships(
first: $first
skip: $skip
where: { creator: $creator, stream_contains_nocase: $streamContains }
where: {
and: [
{ creator: $creator }
{ or: [{ stream_contains_nocase: $searchQuery }, { id: $id }] }
]
}
orderBy: $orderBy
orderDirection: $orderDirection
) {
Expand Down

0 comments on commit 5ce96f8

Please sign in to comment.