ramda#last TypeScript Examples

The following examples show how to use ramda#last. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useNextQuestion.tsx    From nosgestesclimat-site with MIT License 5 votes vote down vote up
export function getNextQuestions(
	missingVariables: Array<MissingVariables>,
	questionConfig: SimulationConfig['questions'] = {},
	answeredQuestions: Array<DottedName> = [],
	situation: Simulation['situation'] = {},
	engine: Engine
): Array<DottedName> {
	const {
		'non prioritaires': notPriority = [],
		liste: whitelist = [],
		'liste noire': blacklist = [],
	} = questionConfig

	let nextSteps = difference(getNextSteps(missingVariables), answeredQuestions)
	nextSteps = nextSteps.filter(
		(step) =>
			(!whitelist.length || whitelist.some((name) => step.startsWith(name))) &&
			(!blacklist.length || !blacklist.some((name) => step.startsWith(name)))
	)

	const nextQuestions = nextSteps.filter((name) => {
		const rule = engine.getRule(name)
		return rule.rawNode.question != null
	})
	const lastStep = last(answeredQuestions)
	// L'ajout de la réponse permet de traiter les questions dont la réponse est
	// "une possibilité", exemple "contrat salarié . cdd"
	const lastStepWithAnswer =
		lastStep && situation[lastStep]
			? ([lastStep, situation[lastStep]]
					.join(' . ')
					.replace(/'/g, '')
					.trim() as DottedName)
			: lastStep
	return sortBy((question) => {
		const indexList =
			whitelist.findIndex((name) => question.startsWith(name)) + 1
		const indexNotPriority =
			notPriority.findIndex((name) => question.startsWith(name)) + 1
		const differenceCoeff = questionDifference(question, lastStepWithAnswer)
		return indexList + indexNotPriority + differenceCoeff
	}, nextQuestions)
}
Example #2
Source File: htmlImportable.ts    From reskript with MIT License 5 votes vote down vote up
extractScriptEntries = (compilations: StatsCompilation[]): string[] => {
    const entries = compilations.flatMap(c => Object.values(c.entrypoints ?? {}));
    // 这里的`assets`是有顺序的(大概),被别人依赖的在前面(大概),真正的入口是最后一个(大概)
    return uniq(reject(isNil, entries.map(v => last(v.assets ?? [])?.name)));
}
Example #3
Source File: SessionBar.tsx    From nosgestesclimat-site with MIT License 4 votes vote down vote up
export default function SessionBar({
	answerButtonOnly = false,
	noResults = false,
}) {
	const dispatch = useDispatch()
	const nextQuestions = useNextQuestions()
	const answeredQuestions = useSelector(answeredQuestionsSelector)
	const arePreviousAnswers = !!answeredQuestions.length
	useSafePreviousSimulation()
	const [showAnswerModal, setShowAnswerModal] = useState(false)

	const objectifs = useSelector(objectifsSelector)
	const conference = useSelector((state) => state.conference)
	const survey = useSelector((state) => state.survey)
	const rules = useSelector((state) => state.rules)
	const engine = useEngine(objectifs)

	const location = useLocation(),
		path = location.pathname

	const buttonStyle = (pathTarget) =>
		path.includes(pathTarget)
			? `
		font-weight: bold;
		img, svg {
		  background: var(--lighterColor);
		  border-radius: 2rem;
		}
		`
			: ''
	const persona = useSelector((state) => state.simulation?.persona)

	let elements = [
		<Button
			className="simple small"
			url={'/simulateur/bilan'}
			onClick={() => {
				nextQuestions.length ? (
					dispatch(goToQuestion(last(answeredQuestions)))
				) : (
					<Redirect to={buildEndURL(rules, engine)} />
				)
			}}
			css={`
				${buttonStyle('simulateur')};
			`}
		>
			<ProgressCircle />
			Le test
		</Button>,
		<Button
			className="simple small"
			url="/actions/liste"
			css={buttonStyle('/actions')}
		>
			<ActionsInteractiveIcon />
			Agir
		</Button>,
		<Button className="simple small" url="/profil" css={buttonStyle('profil')}>
			<img src={openmojiURL('profile')} css="width: 2rem" aria-hidden="true" />
			{!persona ? (
				'Mon profil'
			) : (
				<span
					css={`
						background: var(--color);
						color: var(--textColor);
						padding: 0 0.4rem;
						border-radius: 0.3rem;
					`}
				>
					{persona}
				</span>
			)}
		</Button>,
		NODE_ENV === 'development' && (
			<Button
				key="personas"
				className="simple small"
				url="/personas"
				css={buttonStyle('personas')}
			>
				<img
					src={openmojiURL('personas')}
					css="width: 2rem"
					aria-hidden="true"
				/>
				Personas
			</Button>
		),
		conference?.room && (
			<GroupModeMenuEntry
				title="Conférence"
				icon={conferenceImg}
				url={'/conférence/' + conference.room}
				buttonStyle={buttonStyle}
			>
				<ConferenceBarLazy />
			</GroupModeMenuEntry>
		),
		survey?.room && (
			<GroupModeMenuEntry
				title="Sondage"
				icon={openmojiURL('sondage')}
				url={'/sondage/' + survey.room}
				buttonStyle={buttonStyle}
			>
				<SurveyBarLazy />
			</GroupModeMenuEntry>
		),
	]

	if (path === '/tutoriel') return null

	return (
		<div
			css={`
				margin: 1rem 0 2rem;

				@media (max-width: 800px) {
					margin: 0;
					position: fixed;
					bottom: 0;
					left: 0;
					z-index: 100;
					width: 100%;
				}
			`}
		>
			{elements.filter(Boolean).length > 0 && (
				<NavBar>
					{elements.filter(Boolean).map((Comp, i) => (
						<li key={i}>{Comp}</li>
					))}
				</NavBar>
			)}
		</div>
	)
}