-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Frontend][Update][Version] Lexicon version v2.1.0 (#59)
- Loading branch information
1 parent
fdd8930
commit a54e815
Showing
252 changed files
with
11,495 additions
and
2,895 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
import { TopicPoster } from '../types'; | ||
import { PosterUnion } from '../types'; | ||
|
||
import { getPosterTypeDetails } from './getPosterTypeDetails'; | ||
|
||
export function getTopicAuthor( | ||
posters: Readonly<Array<TopicPoster>>, | ||
): TopicPoster | undefined { | ||
posters: Readonly<Array<PosterUnion>>, | ||
): PosterUnion | undefined { | ||
return posters.find((poster) => { | ||
const { isAuthor } = getPosterTypeDetails(poster.description); | ||
return isAuthor; | ||
}); | ||
} | ||
|
||
export function getTopicAuthorUserId( | ||
posters: Readonly<Array<TopicPoster>>, | ||
posters: Readonly<Array<PosterUnion>>, | ||
): number | undefined { | ||
const author = getTopicAuthor(posters); | ||
|
||
return author?.userId ?? author?.user?.id; | ||
if (author) { | ||
if ('userId' in author) { | ||
return author.userId; | ||
} else if ('user' in author) { | ||
return author.user.id; | ||
} | ||
} | ||
} |
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,56 @@ | ||
import { Poll, PollsVotes, PreloaderUnion } from '../types'; | ||
|
||
/** | ||
* This helper is used for formatting preloadedVoters data | ||
* that is returned in a poll, from a key-value object to an array. | ||
*/ | ||
export function formatPreloadedVoters(preloadedVoters: PreloaderUnion) { | ||
if (!preloadedVoters) { | ||
return { preloadedVoters: null }; | ||
} | ||
|
||
const pollOptionIds = Object.keys(preloadedVoters); | ||
const formattedPreloadedVoters = Array.isArray(preloadedVoters) | ||
? [{ pollOptionId: '', users: preloadedVoters }] | ||
: typeof preloadedVoters === 'object' | ||
? pollOptionIds.map((pollOptionId) => ({ | ||
pollOptionId, | ||
users: preloadedVoters[pollOptionId], | ||
})) | ||
: null; | ||
|
||
return { preloadedVoters: formattedPreloadedVoters }; | ||
} | ||
|
||
export function formatPolls( | ||
polls?: Array<Poll> | null, | ||
pollsVotes?: PollsVotes | null, | ||
) { | ||
if (!polls) { | ||
return { formattedPolls: null, formattedPollsVotes: null }; | ||
} | ||
|
||
const formattedPolls = polls.map((poll) => { | ||
return { ...poll, ...formatPreloadedVoters(poll.preloadedVoters) }; | ||
}); | ||
const formattedPollsVotes = formatPollsVotes(pollsVotes); | ||
|
||
return { formattedPolls, formattedPollsVotes }; | ||
} | ||
|
||
/** | ||
* This helper is used for formatting pollsVotes data | ||
* that is returned in a post, from a key-value object to an array. | ||
*/ | ||
export function formatPollsVotes(pollsVotes?: PollsVotes | null) { | ||
if (!pollsVotes) { | ||
return null; | ||
} | ||
const pollNames = Object.keys(pollsVotes); | ||
const formattedPollVotes = pollNames.map((pollName) => ({ | ||
pollName, | ||
pollOptionIds: pollsVotes[pollName], | ||
})); | ||
|
||
return formattedPollVotes; | ||
} |
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
Oops, something went wrong.