-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #691 from NatalieWilson19/allow-hosts-to-change-he…
…aders-and-subheaders-#360 Allow hosts to change headers and subheaders #360
- Loading branch information
Showing
15 changed files
with
468 additions
and
51 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
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,161 @@ | ||
import { | ||
IonButton, | ||
IonButtons, | ||
IonContent, | ||
IonHeader, | ||
IonIcon, | ||
IonInput, | ||
IonItem, | ||
IonLabel, | ||
IonList, | ||
IonModal, | ||
IonTitle, | ||
IonToolbar, | ||
useIonAlert, | ||
} from "@ionic/react"; | ||
|
||
import type { IonModalCustomEvent } from "@ionic/core"; | ||
import { RefObject, useContext, useState } from "react"; | ||
import { StoreContext } from "../Store"; | ||
import { OverlayEventDetail } from "@ionic/react/dist/types/components/react-component-lib/interfaces"; | ||
import { useTranslation } from "react-i18next"; | ||
import { chainUpdate } from "../api"; | ||
import { refreshOutline } from "ionicons/icons"; | ||
|
||
export default function EditHeaders(props: { | ||
initialHeader: string | null; | ||
headerKey: string; | ||
modal: RefObject<HTMLIonModalElement>; | ||
didDismiss?: (e: IonModalCustomEvent<OverlayEventDetail<any>>) => void; | ||
}) { | ||
const { t } = useTranslation(); | ||
const [error, setError] = useState(""); | ||
const { chain, chainHeaders } = useContext(StoreContext); | ||
|
||
const [presentAlert] = useIonAlert(); | ||
|
||
const [text, setText] = useState(props.initialHeader); | ||
|
||
function modalInit() { | ||
setText(props.initialHeader); | ||
setError(""); | ||
} | ||
|
||
function cancel() { | ||
props.modal.current?.dismiss(); | ||
} | ||
|
||
function handleSave() { | ||
if (!chain?.uid) return; | ||
const _headerKey = props.headerKey; | ||
const newH = { | ||
...chainHeaders, | ||
[_headerKey]: text, | ||
}; | ||
|
||
chainUpdate({ | ||
uid: chain.uid, | ||
headers_override: JSON.stringify(newH), | ||
}); | ||
|
||
props.modal.current?.dismiss("", "confirm"); | ||
} | ||
|
||
function reset() { | ||
if (!chain?.uid) return; | ||
const handler = () => { | ||
chainUpdate({ | ||
uid: chain.uid, | ||
headers_override: "", | ||
}); | ||
props.modal.current?.dismiss(); | ||
}; | ||
|
||
presentAlert({ | ||
header: t("resetHeaders"), | ||
subHeader: t("areYouSureYouWantToResetHeaders"), | ||
buttons: [ | ||
{ | ||
text: t("cancel"), | ||
}, | ||
{ | ||
role: "destructive", | ||
text: t("reset"), | ||
handler, | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
return ( | ||
<IonModal | ||
ref={props.modal} | ||
onIonModalWillPresent={modalInit} | ||
onIonModalDidDismiss={props.didDismiss} | ||
initialBreakpoint={0.5} | ||
breakpoints={[0, 0.5, 0.75, 1]} | ||
> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonButtons slot="start"> | ||
<IonButton onClick={cancel}>{t("cancel")}</IonButton> | ||
</IonButtons> | ||
<IonTitle>{t("update")}</IonTitle> | ||
<IonButtons slot="end"> | ||
<IonButton | ||
onClick={handleSave} | ||
color={!error ? "primary" : "danger"} | ||
disabled={text?.length == 0} | ||
> | ||
{t("save")} | ||
</IonButton> | ||
</IonButtons> | ||
</IonToolbar> | ||
</IonHeader> | ||
<IonContent fullscreen> | ||
<IonList> | ||
{chain?.headers_override ? ( | ||
<IonItem | ||
lines="full" | ||
color="dark" | ||
key="reset" | ||
className="tw-bottom-0" | ||
> | ||
<IonIcon icon={refreshOutline} className="tw-ml-0.5 tw-mr-5" /> | ||
<IonLabel className="ion-text-wrap"> | ||
<h3>{t("restHeaders")}</h3> | ||
<p>{t("resetHeadersDesc")}</p> | ||
</IonLabel> | ||
<IonButton slot="end" onClick={reset} color="danger"> | ||
{t("reset")} | ||
</IonButton> | ||
</IonItem> | ||
) : null} | ||
<IonItem | ||
lines="none" | ||
color={error === "number" ? "danger" : undefined} | ||
> | ||
{t("updateHeaderDesc")} | ||
</IonItem> | ||
<IonItem | ||
lines="none" | ||
color={error === "number" ? "danger" : undefined} | ||
> | ||
<IonInput | ||
type="text" | ||
label={t("Title")} | ||
labelPlacement="start" | ||
max={50} | ||
spellCheck | ||
autoCapitalize="words" | ||
maxlength={50} | ||
counter | ||
value={text || ""} | ||
onIonInput={(e) => setText(e.detail.value + "")} | ||
/> | ||
</IonItem> | ||
</IonList> | ||
</IonContent> | ||
</IonModal> | ||
); | ||
} |
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,39 @@ | ||
import { IonIcon, IonTitle } from "@ionic/react"; | ||
import { construct } from "ionicons/icons"; | ||
import { useLongPress } from "use-long-press"; | ||
|
||
interface Props { | ||
isChainAdmin: boolean; | ||
className: string; | ||
headerText: string; | ||
onEdit: () => void; | ||
} | ||
|
||
export default function HeaderTitle({ | ||
className, | ||
isChainAdmin, | ||
headerText, | ||
onEdit, | ||
}: Props) { | ||
const longPressHeader = useLongPress(onEdit); | ||
|
||
if (isChainAdmin) { | ||
return ( | ||
<IonTitle size="large" className={className} {...longPressHeader()}> | ||
{headerText} | ||
|
||
<IonIcon | ||
icon={construct} | ||
className="tw-text-[18px] tw-ml-1.5 !tw-text-blue tw-cursor-pointer" | ||
onClick={onEdit} | ||
/> | ||
</IonTitle> | ||
); | ||
} | ||
|
||
return ( | ||
<IonTitle size="large" className={className}> | ||
{headerText} | ||
</IonTitle> | ||
); | ||
} |
Oops, something went wrong.