-
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.
Allow users to share the symptom history as text (#575)
* Allow users to share the symptom history as text Why: ---- When users add their symptoms to the log, there might be a case where that log would be valuable to send to someone of the users choosing. We need to allow users to pick that data from their log history and take it with them in a text format that can be shared. This Commit: ---- - Create a format for the symptom history to be shared, the format is of the shape: ``` Symptom history from Oct 20, '20 to Oct 7, '20 Oct 20, '20 No symptoms were logged Oct 19, '20 You felt well Oct 18, '20 You did not feel well, symptoms included: Cough, Fever (for the next 14 entries) ... ``` - Use formatter class to export a symptom history into this format - Add a share button to the right of the header on the symptom history screen that will open up the share menu with the symptom history in text format to be shared - Fix typo on symptom checker copy `learn move` => `learn more` Co-authored-by: Devin Jameson <[email protected]> Co-authored-by: Matt Buckley <[email protected]> * Update style and class naming Co-authored-by: Devin Jameson <[email protected]> Co-authored-by: Matt Buckley <[email protected]>
- Loading branch information
1 parent
074f20a
commit 5797233
Showing
4 changed files
with
184 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { TFunction } from "i18next" | ||
|
||
import { posixToDayjs } from "../utils/dateTime" | ||
import { SymptomHistory, SymptomEntry } from "./symptomHistory" | ||
import * as Symptom from "./symptom" | ||
|
||
class SymptomHistoryFormatter { | ||
private DATE_FORMAT = "MMM D, 'YY" | ||
private t: TFunction | ||
private symptomHistory: SymptomHistory | ||
|
||
public static forSharing = ( | ||
t: TFunction, | ||
symptomHistory: SymptomHistory, | ||
): string => { | ||
const formatter = new SymptomHistoryFormatter(t, symptomHistory) | ||
return formatter.toShareableText() | ||
} | ||
|
||
private constructor(t: TFunction, symptomHistory: SymptomHistory) { | ||
this.t = t | ||
this.symptomHistory = symptomHistory | ||
} | ||
|
||
private toShareableText = (): string => { | ||
const { | ||
symptomHistory, | ||
sharedHistoryHeader, | ||
toFormattedSymptomEntry, | ||
} = this | ||
const NEW_EMPTY_LINE = "\n\n" | ||
|
||
const header = sharedHistoryHeader() | ||
|
||
const allEntriesFormatted = symptomHistory.map(toFormattedSymptomEntry) | ||
|
||
return [header, ...allEntriesFormatted].join(NEW_EMPTY_LINE) | ||
} | ||
|
||
private sharedHistoryHeader = (): string => { | ||
const { t, symptomHistory, DATE_FORMAT } = this | ||
const fromEntry = symptomHistory[0] | ||
const toEntry = symptomHistory[symptomHistory.length - 1] | ||
|
||
const firstEntryDayJSDate = posixToDayjs(fromEntry.date) | ||
const lastEntryDayJSDate = posixToDayjs(toEntry.date) | ||
|
||
const startDate = firstEntryDayJSDate?.local().format(DATE_FORMAT) || "" | ||
const endDate = lastEntryDayJSDate?.local().format(DATE_FORMAT) || "" | ||
|
||
return t("symptom_history.sharing.header", { startDate, endDate }) | ||
} | ||
|
||
private toFormattedSymptomEntry = (symptomEntry: SymptomEntry): string => { | ||
const { symptomEntryDetails, DATE_FORMAT } = this | ||
const NEW_LINE = "\n" | ||
|
||
const date = symptomEntry.date | ||
const entryDateDayJs = posixToDayjs(date) | ||
|
||
const entryDate = entryDateDayJs?.local().format(DATE_FORMAT) || "" | ||
const entryDetails = symptomEntryDetails(symptomEntry) | ||
|
||
return [entryDate, entryDetails].join(NEW_LINE) | ||
} | ||
|
||
private symptomEntryDetails = (symptomEntry: SymptomEntry): string => { | ||
const { t, translatedSymptoms } = this | ||
let details = "" | ||
|
||
if (symptomEntry.kind === "NoUserInput") { | ||
details = t("symptom_history.sharing.no_symptoms_were_logged") | ||
} else { | ||
if (symptomEntry.symptoms.size > 0) { | ||
details = t("symptom_history.sharing.you_did_not_feel_well", { | ||
symptomList: translatedSymptoms([...symptomEntry.symptoms]), | ||
}) | ||
} else { | ||
details = t("symptom_history.sharing.you_felt_well") | ||
} | ||
} | ||
|
||
return details | ||
} | ||
|
||
private translatedSymptoms = (symptoms: Symptom.Symptom[]): string => { | ||
const { t } = this | ||
|
||
return symptoms | ||
.map((symptom: Symptom.Symptom) => Symptom.toTranslation(t, symptom)) | ||
.join(", ") | ||
} | ||
} | ||
|
||
export default SymptomHistoryFormatter |
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