ramda#trim TypeScript Examples
The following examples show how to use
ramda#trim.
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: qr.ts From back-home-safe with GNU General Public License v3.0 | 6 votes |
getVenueName = (
decodedJson: DecodedJSON | Location | null,
language: languageType
) => {
if (!decodedJson) return "";
const trimmedZhName = trim(propOr("", "nameZh", decodedJson));
const trimmedEnName = trim(propOr("", "nameEn", decodedJson));
const venueId = trim(propOr("", "venueId", decodedJson));
const chineseName = !isEmpty(trimmedZhName)
? trimmedZhName
: !isEmpty(trimmedEnName)
? trimmedEnName
: // used for taxi license
venueId;
const englishName = !isEmpty(trimmedEnName)
? trimmedEnName
: !isEmpty(trimmedZhName)
? trimmedZhName
: // used for taxi license
venueId;
return language === languageType.EN ? englishName : chineseName;
}
Example #2
Source File: index.tsx From back-home-safe with GNU General Public License v3.0 | 5 votes |
QRReader = () => {
const { t } = useTranslation("qr_reader");
const [qrResult, setQrResult] = useState<string | null>(null);
const browserHistory = useHistory();
const { createTravelRecord } = useTravelRecord();
const { language } = useI18n();
const handleScan = ({ data }: QRCode) => {
if (!data || isEmpty(data)) return;
const decodedJson = qrDecode(data);
if (!decodedJson) return;
setQrResult(data);
};
useEffect(() => {
if (!qrResult) return;
const decodedJson = qrDecode(qrResult);
if (!decodedJson || !getVenueName(decodedJson, language)) return;
const trimmedZhName = trim(propOr("", "nameZh", decodedJson));
const trimmedEnName = trim(propOr("", "nameEn", decodedJson));
const id = uuid();
const now = dayjs();
const record = {
id: uuid(),
venueId: decodedJson.venueId,
nameZh: trimmedZhName,
nameEn: trimmedEnName,
type: locationType.PLACE,
inputType: travelRecordInputType.SCAN,
inTime: now.toISOString(),
outTime: now.add(4, "hour").toISOString(),
originalData: decodedJson,
};
createTravelRecord(record);
browserHistory.push({ pathname: `/confirm/${id}`, state: record });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [qrResult, browserHistory]);
return (
<PageWrapper>
<Header backPath="/" name={t("name")} />
<Message>{t("message.scan_qr_code")}</Message>
<VideoContainer>
<Overlay />
<QRCodeReader onDecode={handleScan} />
</VideoContainer>
</PageWrapper>
);
}
Example #3
Source File: Home.tsx From back-home-safe with GNU General Public License v3.0 | 4 votes |
Home = () => {
const { t } = useTranslation("main_screen");
const [place, setPlace] = useState("");
const [license, setLicense] = useState("");
const [leaveModalOpen, setLeaveModalOpen] = useState(false);
const [leaveId, setLeaveId] = useState<null | string>(null);
const { currentTravelRecord, updateTravelRecord } = useTravelRecord();
const { enterLocation } = useTravelRecord();
const { currentTime } = useTime();
const { language } = useI18n();
const {
createBookmarkLocation,
getBookmarkLocationId,
removeBookmarkLocation,
} = useBookmarkLocation();
const today = useMemo(() => {
return currentTime.format("YYYY-MM-DD, dddd");
}, [currentTime]);
const handlePlaceSubmit = () => {
enterLocation({
nameZh: place,
type: locationType.PLACE,
inputType: travelRecordInputType.MANUALLY,
});
};
const handleTaxiSubmit = () => {
enterLocation({
venueId: license,
type: locationType.TAXI,
inputType: travelRecordInputType.MANUALLY,
});
};
const handleLeave = (date: Dayjs) => {
if (!leaveId) return;
updateTravelRecord(leaveId, {
outTime: date.startOf("minute").toISOString(),
});
setLeaveModalOpen(false);
};
useEffect(() => {
if (leaveId) setLeaveModalOpen(true);
}, [leaveId]);
useEffect(() => {
if (!leaveModalOpen) setLeaveId(null);
}, [leaveModalOpen]);
return (
<PageWrapper>
{leaveId && (
<LeaveModal
id={leaveId}
visible={leaveModalOpen}
onDiscard={() => {
setLeaveModalOpen(false);
}}
onFinish={handleLeave}
/>
)}
<Welcome>
<Title>
<div>{today}</div>
<h2>{t("home.record_your_visit")}</h2>
</Title>
</Welcome>
<SliderWrapper>
<Slider>
<StyledCard>
<CardContent>
<Typography color="textSecondary" gutterBottom>
{t("home.form.venue_name.label")}
</Typography>
<StyledPlace
value={place}
onChange={setPlace}
placeholder={t("home.form.venue_name.placeholder")}
/>
</CardContent>
<CardActions>
<Button
size="small"
color="primary"
disabled={isEmpty(trim(place))}
onClick={handlePlaceSubmit}
>
{t("home.button.go")}
</Button>
<Link to="/qrReader">
<Button size="small" color="primary">
{t("home.button.scan_qr_code")}
</Button>
</Link>
</CardActions>
</StyledCard>
<StyledCard>
<CardContent>
<Typography color="textSecondary" gutterBottom>
{t("home.form.taxi.label")}
</Typography>
<StyledPlace
value={license}
onChange={setLicense}
placeholder={t("home.form.taxi.placeholder")}
/>
</CardContent>
<CardActions>
<Button
size="small"
color="primary"
disabled={isEmpty(trim(license))}
onClick={handleTaxiSubmit}
>
{t("home.button.ride")}
</Button>
</CardActions>
</StyledCard>
</Slider>
</SliderWrapper>
<TravelRecordWrapper>
<TravelRecordInner>
<h3>{t("home.you_have_entered")}</h3>
{isEmpty(currentTravelRecord) && (
<Msg>{t("travel_record.message.empty")}</Msg>
)}
{currentTravelRecord.map((item) => {
const bookmarkId = getBookmarkLocationId(item);
return (
<Item key={item.id}>
<CardHeader
avatar={
item.type === locationType.TAXI ? (
<LocalTaxiIcon />
) : (
<StoreIcon />
)
}
action={
<IconButton
aria-label="settings"
onClick={() => {
bookmarkId
? removeBookmarkLocation(bookmarkId)
: createBookmarkLocation(item);
}}
>
{bookmarkId ? <BookmarkIcon /> : <BookmarkBorderIcon />}
</IconButton>
}
title={getVenueName(item, language)}
subheader={`${dayjs(item.inTime).format(
"YYYY-MM-DD HH:mm"
)} - ${
item.outTime
? dayjs(item.outTime).format("YYYY-MM-DD HH:mm")
: ""
}`}
/>
<CardActions disableSpacing>
<Button
size="small"
color="primary"
onClick={() => {
setLeaveId(item.id);
}}
>
{t("global:button.leave")}
</Button>
<Link to={`/confirm/${item.id}`}>
<Button size="small" color="primary">
{t("global:button.confirm_page")}
</Button>
</Link>
</CardActions>
</Item>
);
})}
</TravelRecordInner>
</TravelRecordWrapper>
</PageWrapper>
);
}