Skip to content

Instantly share code, notes, and snippets.

@Jpoliachik
Last active January 9, 2024 15:50
Show Gist options
  • Select an option

  • Save Jpoliachik/41c6033a3405a00d8c69cc0f2c02edcd to your computer and use it in GitHub Desktop.

Select an option

Save Jpoliachik/41c6033a3405a00d8c69cc0f2c02edcd to your computer and use it in GitHub Desktop.

Revisions

  1. Jpoliachik revised this gist Jan 9, 2024. 1 changed file with 0 additions and 35 deletions.
    35 changes: 0 additions & 35 deletions QuestionScreen.tsx
    Original file line number Diff line number Diff line change
    @@ -1,35 +0,0 @@
    import React, { FC } from "react"
    import { observer } from "mobx-react-lite"
    import { TextStyle, View, ViewStyle } from "react-native"
    import { AppStackScreenProps } from "app/navigators"
    import { Screen, Text } from "app/components"
    import { spacing } from "app/theme"
    // import { useNavigation } from "@react-navigation/native"
    // import { useStores } from "app/models"

    interface QuestionScreenProps extends AppStackScreenProps<"Question"> {}

    export const QuestionScreen: FC<QuestionScreenProps> = observer(function QuestionScreen() {
    // Pull in one of our MST stores
    // const { someStore, anotherStore } = useStores()

    // Pull in navigation via hook
    // const navigation = useNavigation()
    return (
    <Screen style={$root} preset="scroll">
    <View style={$header}>
    <Text preset="heading" text="question" tx={"questionScreen.title"} />
    </View>
    </Screen>
    )
    })

    const $root: ViewStyle = {
    flex: 1,
    paddingHorizontal: spacing.lg,
    }

    const $header: TextStyle = {
    marginTop: spacing.xxxl,
    marginBottom: spacing.md,
    }
  2. Jpoliachik revised this gist Jan 9, 2024. 1 changed file with 0 additions and 29 deletions.
    29 changes: 0 additions & 29 deletions decodeHtml.ts
    Original file line number Diff line number Diff line change
    @@ -1,29 +0,0 @@
    const entities = {
    amp: "&",
    apos: "'",
    lt: "<",
    gt: ">",
    quot: '"',
    nbsp: "\xa0",
    ouml: "ö",
    auml: "ä",
    uuml: "ü",
    oacute: "ó",
    aacute: "á",
    eacute: "é",
    ntilde: "ñ",
    "#039": "'",
    }
    const entityPattern = /&(([a-z0-9]|#)+);/gi

    export const decodeHTMLEntities = (text: string): string => {
    // A single replace pass with a static RegExp is faster than a loop
    return text.replace(entityPattern, (match, entity) => {
    entity = entity.toLowerCase()
    if (Object.prototype.hasOwnProperty.call(entities, entity)) {
    return entities[entity as keyof typeof entities]
    }
    // return original string if there is no matching entity (no replace)
    return match
    })
    }
  3. Jpoliachik revised this gist Jan 9, 2024. 1 changed file with 29 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions decodeHtml.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    const entities = {
    amp: "&",
    apos: "'",
    lt: "<",
    gt: ">",
    quot: '"',
    nbsp: "\xa0",
    ouml: "ö",
    auml: "ä",
    uuml: "ü",
    oacute: "ó",
    aacute: "á",
    eacute: "é",
    ntilde: "ñ",
    "#039": "'",
    }
    const entityPattern = /&(([a-z0-9]|#)+);/gi

    export const decodeHTMLEntities = (text: string): string => {
    // A single replace pass with a static RegExp is faster than a loop
    return text.replace(entityPattern, (match, entity) => {
    entity = entity.toLowerCase()
    if (Object.prototype.hasOwnProperty.call(entities, entity)) {
    return entities[entity as keyof typeof entities]
    }
    // return original string if there is no matching entity (no replace)
    return match
    })
    }
  4. Jpoliachik revised this gist Jan 9, 2024. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions Question.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    ...
    import shuffle from "lodash.shuffle"
    ...
    ...
    export const QuestionModel = types
    ...
    .views((self) => ({
    get allAnswers() {
    return shuffle([
    ...self.incorrectAnswers,
    ...(self.correctAnswer ? [self.correctAnswer] : []),
    ])
    },
    }))

    ...
  5. Jpoliachik created this gist Jan 9, 2024.
    35 changes: 35 additions & 0 deletions QuestionScreen.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    import React, { FC } from "react"
    import { observer } from "mobx-react-lite"
    import { TextStyle, View, ViewStyle } from "react-native"
    import { AppStackScreenProps } from "app/navigators"
    import { Screen, Text } from "app/components"
    import { spacing } from "app/theme"
    // import { useNavigation } from "@react-navigation/native"
    // import { useStores } from "app/models"

    interface QuestionScreenProps extends AppStackScreenProps<"Question"> {}

    export const QuestionScreen: FC<QuestionScreenProps> = observer(function QuestionScreen() {
    // Pull in one of our MST stores
    // const { someStore, anotherStore } = useStores()

    // Pull in navigation via hook
    // const navigation = useNavigation()
    return (
    <Screen style={$root} preset="scroll">
    <View style={$header}>
    <Text preset="heading" text="question" tx={"questionScreen.title"} />
    </View>
    </Screen>
    )
    })

    const $root: ViewStyle = {
    flex: 1,
    paddingHorizontal: spacing.lg,
    }

    const $header: TextStyle = {
    marginTop: spacing.xxxl,
    marginBottom: spacing.md,
    }