diff --git a/src/shared/components/instance-picker.tsx b/src/shared/components/instance-picker.tsx new file mode 100644 index 0000000..72d43b6 --- /dev/null +++ b/src/shared/components/instance-picker.tsx @@ -0,0 +1,154 @@ +import classNames from "classnames"; +import { Component, linkEvent } from "inferno"; +import { All_TOPIC, TOPICS, Topic } from "./instances-definitions"; +import { LANGUAGES, i18n } from "../i18next"; +import { I18nKeys } from "i18next"; +import { Icon } from "./icon"; + +enum Step { + Interest, + Language, + Join, +} + +interface State { + activeStep: Step; + topic?: Topic; + language?: string; +} + +export class InstancePicker extends Component { + state: State = { + activeStep: Step.Interest, + }; + constructor(props: any, context: any) { + super(props, context); + } + + render() { + return ( + +
+ +
+
+
+ +
+
+ {this.state.activeStep == Step.Interest && ( + <> +

+ {i18n.t("what_topic")} +

+ {TOPICS.map(c => ( +
+ +
+ ))} + + )} + {this.state.activeStep == Step.Language && ( + <> +

+ {i18n.t("what_language")} +

+
+ +
+ {LANGUAGES.map(l => ( +
+ +
+ ))} + + )} + +
    +
  • + {i18n.t("interests")} +
  • +
  • + {i18n.t("languages")} +
  • +
  • + {i18n.t("join")} +
  • +
+
+
+
+ ); + } +} + +function handleTopicChange(i: InstancePicker, event: any) { + i.setState({ + topic: TOPICS.find(c => c.name == event.target.value) ?? All_TOPIC, + activeStep: Step.Language, + }); +} + +function handleLanguageChange(i: InstancePicker, event: any) { + i.setState({ language: event.target.value }); + const url = `/instances?topic=${i.state.topic?.name ?? All_TOPIC}&language=${ + i.state.language + }&scroll=true`; + + // Requires a page reload unfortunately + window.location.href = url; +} + +function handleResetInterests(i: InstancePicker) { + i.setState({ topic: undefined, activeStep: Step.Interest }); +}