-
Notifications
You must be signed in to change notification settings - Fork 12
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 #512 from social-tw/fix/show-reputation-history-re…
…lated-to-user [Fix] [Frontend] only show the reputation history records related to the user
- Loading branch information
Showing
21 changed files
with
243 additions
and
149 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
27 changes: 27 additions & 0 deletions
27
packages/frontend/src/features/core/services/ReputationService/ReputationService.ts
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,27 @@ | ||
import { FetchReputationHistoryResponse } from '@/types/api' | ||
import { isMyEpochKey } from '@/utils/helpers/epochKey' | ||
import { RelayApiService } from '../RelayApiService/RelayApiService' | ||
|
||
export class ReputationService extends RelayApiService { | ||
async fetchReputationHistory(fromEpoch: number, toEpoch: number) { | ||
const client = this.getClient() | ||
const searchParams = new URLSearchParams() | ||
searchParams.append('from_epoch', fromEpoch.toString()) | ||
searchParams.append('to_epoch', toEpoch.toString()) | ||
const response = await client.get<FetchReputationHistoryResponse>( | ||
`/reputation/history?${searchParams.toString()}`, | ||
) | ||
return response.data | ||
} | ||
|
||
async fetchMyReputationHistory(fromEpoch: number, toEpoch: number) { | ||
const userState = this.getUserState() | ||
const reputationRecords = await this.fetchReputationHistory( | ||
fromEpoch, | ||
toEpoch, | ||
) | ||
return reputationRecords.filter((record) => | ||
isMyEpochKey(userState, record.epoch, record.epochKey), | ||
) | ||
} | ||
} |
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
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
12 changes: 8 additions & 4 deletions
12
...ReputationHistory/useReputationHistory.ts → ...putationHistory/useMyReputationHistory.ts
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 |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import { QueryKeys } from '@/constants/queryKeys' | ||
import { ReputationService, useUserState } from '@/features/core' | ||
import { | ||
FromToEpoch, | ||
ValidFromToEpoch, | ||
} from '@/features/shared/services/EpochDateService' | ||
import { fetchReputationHistory } from '@/utils/api' | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
export function useReputationHistory(fromToEpoch: FromToEpoch) { | ||
export function useMyReputationHistory(fromToEpoch: FromToEpoch) { | ||
const { userState } = useUserState() | ||
|
||
return useQuery({ | ||
queryKey: [ | ||
QueryKeys.ReputationHistory, | ||
fromToEpoch.from, | ||
fromToEpoch.to, | ||
userState?.id.toString(), | ||
], | ||
queryFn: async () => { | ||
return await fetchReputationHistory( | ||
const reputationService = new ReputationService(userState) | ||
return reputationService.fetchMyReputationHistory( | ||
fromToEpoch.from, | ||
fromToEpoch.to, | ||
) | ||
}, | ||
enabled: fromToEpoch instanceof ValidFromToEpoch, | ||
enabled: fromToEpoch instanceof ValidFromToEpoch && !!userState, | ||
}) | ||
} |
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
4 changes: 2 additions & 2 deletions
4
packages/frontend/src/features/reporting/components/Adjudicate/AdjudicateForm.tsx
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
Oops, something went wrong.