-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
88 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
import { observer } from "mobx-react-lite"; | ||
import React, { useState } from "react"; | ||
import { ShareDeckStore } from "./store/share-deck-store.ts"; | ||
import React from "react"; | ||
import { ShareDeckOneTimeLinks } from "./share-deck-one-time-links.tsx"; | ||
import { ShareDeckSettings } from "./share-deck-settings.tsx"; | ||
import { useShareDeckStore } from "./store/share-deck-store-context.tsx"; | ||
|
||
export const ShareDeckScreen = observer(() => { | ||
const [store] = useState(() => new ShareDeckStore()); | ||
|
||
const store = useShareDeckStore(); | ||
if (store.isDeckAccessesOpen.value) { | ||
return <ShareDeckOneTimeLinks store={store} />; | ||
return <ShareDeckOneTimeLinks />; | ||
} | ||
return <ShareDeckSettings store={store} />; | ||
return <ShareDeckSettings />; | ||
}); |
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 |
---|---|---|
@@ -1,94 +1,87 @@ | ||
import { observer } from "mobx-react-lite"; | ||
import { ShareDeckStore } from "./store/share-deck-store.ts"; | ||
import { useBackButton } from "../../lib/telegram/use-back-button.tsx"; | ||
import { screenStore } from "../../store/screen-store.ts"; | ||
import { useMainButton } from "../../lib/telegram/use-main-button.tsx"; | ||
import { t } from "../../translations/t.ts"; | ||
import { useTelegramProgress } from "../../lib/telegram/use-telegram-progress.tsx"; | ||
import { ShareDeckOneTimeLinks } from "./share-deck-one-time-links.tsx"; | ||
import { css } from "@emotion/css"; | ||
import { SettingsRow } from "../user-settings/settings-row.tsx"; | ||
import { RadioSwitcher } from "../../ui/radio-switcher.tsx"; | ||
import { HintTransparent } from "../../ui/hint-transparent.tsx"; | ||
import { Label } from "../../ui/label.tsx"; | ||
import { Input } from "../../ui/input.tsx"; | ||
import React from "react"; | ||
import { useShareDeckStore } from "./store/share-deck-store-context.tsx"; | ||
|
||
export const ShareDeckSettings = observer( | ||
(props: { store: ShareDeckStore }) => { | ||
const { store } = props; | ||
export const ShareDeckSettings = observer(() => { | ||
const store = useShareDeckStore(); | ||
|
||
useBackButton(() => { | ||
screenStore.back(); | ||
}); | ||
useBackButton(() => { | ||
screenStore.back(); | ||
}); | ||
|
||
useMainButton( | ||
() => { | ||
return store.form.isOneTime.value | ||
? t("share_one_time_link") | ||
: t("share_perpetual_link"); | ||
}, | ||
() => { | ||
store.shareDeck(); | ||
}, | ||
() => store.isSaveButtonVisible, | ||
); | ||
useMainButton( | ||
() => { | ||
return store.form.isOneTime.value | ||
? t("share_one_time_link") | ||
: t("share_perpetual_link"); | ||
}, | ||
() => { | ||
store.shareDeck(); | ||
}, | ||
() => store.isSaveButtonVisible, | ||
); | ||
|
||
useTelegramProgress(() => store.isSending); | ||
useTelegramProgress(() => store.isSending); | ||
|
||
if (store.isDeckAccessesOpen.value) { | ||
return <ShareDeckOneTimeLinks store={store} />; | ||
} | ||
return ( | ||
<div | ||
className={css({ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: 16, | ||
marginBottom: 16, | ||
position: "relative", | ||
})} | ||
> | ||
<h3 className={css({ textAlign: "center" })}> | ||
{t("share_deck_settings")} | ||
</h3> | ||
<SettingsRow> | ||
<span>{t("share_one_time_access_link")}</span> | ||
<RadioSwitcher | ||
isOn={store.form.isOneTime.value} | ||
onToggle={store.form.isOneTime.toggle} | ||
/> | ||
</SettingsRow> | ||
<HintTransparent marginTop={-12}> | ||
{t("share_one_time_access_link_description")} | ||
</HintTransparent> | ||
{store.form.isOneTime.value && ( | ||
<> | ||
<SettingsRow> | ||
<span>{t("share_access_duration")}</span> | ||
<RadioSwitcher | ||
isOn={store.form.isAccessDuration.value} | ||
onToggle={store.form.isAccessDuration.toggle} | ||
/> | ||
</SettingsRow> | ||
</> | ||
)} | ||
{store.form.isOneTime.value && store.form.isAccessDuration.value && ( | ||
<Label text={t("share_days")}> | ||
<Input field={store.form.accessDurationLimitDays} /> | ||
<HintTransparent>{t("share_days_description")}</HintTransparent> | ||
</Label> | ||
)} | ||
|
||
return ( | ||
<div | ||
className={css({ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: 16, | ||
marginBottom: 16, | ||
position: "relative", | ||
})} | ||
<SettingsRow | ||
onClick={() => { | ||
store.isDeckAccessesOpen.setTrue(); | ||
}} | ||
> | ||
<h3 className={css({ textAlign: "center" })}> | ||
{t("share_deck_settings")} | ||
</h3> | ||
<SettingsRow> | ||
<span>{t("share_one_time_access_link")}</span> | ||
<RadioSwitcher | ||
isOn={store.form.isOneTime.value} | ||
onToggle={store.form.isOneTime.toggle} | ||
/> | ||
</SettingsRow> | ||
<HintTransparent marginTop={-12}> | ||
{t("share_one_time_access_link_description")} | ||
</HintTransparent> | ||
{store.form.isOneTime.value && ( | ||
<> | ||
<SettingsRow> | ||
<span>{t("share_access_duration")}</span> | ||
<RadioSwitcher | ||
isOn={store.form.isAccessDuration.value} | ||
onToggle={store.form.isAccessDuration.toggle} | ||
/> | ||
</SettingsRow> | ||
</> | ||
)} | ||
{store.form.isOneTime.value && store.form.isAccessDuration.value && ( | ||
<Label text={t("share_days")}> | ||
<Input field={store.form.accessDurationLimitDays} /> | ||
<HintTransparent>{t("share_days_description")}</HintTransparent> | ||
</Label> | ||
)} | ||
|
||
<SettingsRow | ||
onClick={() => { | ||
store.isDeckAccessesOpen.setTrue(); | ||
}} | ||
> | ||
{t("share_one_time_links_usage")} | ||
</SettingsRow> | ||
</div> | ||
); | ||
}, | ||
); | ||
{t("share_one_time_links_usage")} | ||
</SettingsRow> | ||
</div> | ||
); | ||
}); |
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,19 @@ | ||
import { createContext, ReactNode, useContext } from "react"; | ||
import { ShareDeckStore } from "./share-deck-store.ts"; | ||
import { assert } from "../../../lib/typescript/assert.ts"; | ||
|
||
const Context = createContext<ShareDeckStore | null>(null); | ||
|
||
export const ShareDeckStoreProvider = (props: { children: ReactNode }) => { | ||
return ( | ||
<Context.Provider value={new ShareDeckStore()}> | ||
{props.children} | ||
</Context.Provider> | ||
); | ||
}; | ||
|
||
export const useShareDeckStore = () => { | ||
const store = useContext(Context); | ||
assert(store, "ShareDeckStoreProvider not found"); | ||
return store; | ||
}; |