mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-27 06:41:12 +00:00
Redirect for remote fetch
This commit is contained in:
parent
d6ed83d92f
commit
38f9c6de87
2 changed files with 54 additions and 7 deletions
|
@ -1,8 +1,10 @@
|
||||||
|
import { validInstanceTLD } from "@utils/helpers";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { NoOptionI18nKeys } from "i18next";
|
import { NoOptionI18nKeys } from "i18next";
|
||||||
import { Component, MouseEventHandler } from "inferno";
|
import { Component, MouseEventHandler, linkEvent } from "inferno";
|
||||||
import { CommunityView } from "lemmy-js-client";
|
import { CommunityView } from "lemmy-js-client";
|
||||||
import { I18NextService, UserService } from "../../services";
|
import { I18NextService, UserService } from "../../services";
|
||||||
|
import { VERSION } from "../../version";
|
||||||
import { Icon, Spinner } from "./icon";
|
import { Icon, Spinner } from "./icon";
|
||||||
|
|
||||||
interface SubscribeButtonProps {
|
interface SubscribeButtonProps {
|
||||||
|
@ -13,12 +15,14 @@ interface SubscribeButtonProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SubscribeButton({
|
export function SubscribeButton({
|
||||||
communityView,
|
communityView: {
|
||||||
|
subscribed,
|
||||||
|
community: { actor_id },
|
||||||
|
},
|
||||||
onFollow,
|
onFollow,
|
||||||
onUnFollow,
|
onUnFollow,
|
||||||
loading,
|
loading,
|
||||||
}: SubscribeButtonProps) {
|
}: SubscribeButtonProps) {
|
||||||
const { subscribed } = communityView;
|
|
||||||
let i18key: NoOptionI18nKeys;
|
let i18key: NoOptionI18nKeys;
|
||||||
|
|
||||||
switch (subscribed) {
|
switch (subscribed) {
|
||||||
|
@ -52,7 +56,7 @@ export function SubscribeButton({
|
||||||
>
|
>
|
||||||
{I18NextService.i18n.t("subscribe")}
|
{I18NextService.i18n.t("subscribe")}
|
||||||
</button>
|
</button>
|
||||||
<RemoteFetchModal />
|
<RemoteFetchModal communityActorId={actor_id} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -80,12 +84,51 @@ export function SubscribeButton({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface RemoteFetchModalProps {
|
||||||
|
communityActorId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RemoteFetchModalState {
|
||||||
|
instanceText: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInput(i: RemoteFetchModal, event: any) {
|
||||||
|
i.setState({ instanceText: event.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
function focusInput() {
|
function focusInput() {
|
||||||
document.getElementById("remoteFetchInstance")?.focus();
|
document.getElementById("remoteFetchInstance")?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
class RemoteFetchModal extends Component {
|
function submitRemoteFollow(
|
||||||
constructor(props, context) {
|
{ state: { instanceText }, props: { communityActorId } }: RemoteFetchModal,
|
||||||
|
event: Event
|
||||||
|
) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (!validInstanceTLD(instanceText)) {
|
||||||
|
// TODO: Figure out appropriate way of handling invalid domainss
|
||||||
|
console.log("I should do something about this.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^https?:\/\//.test(instanceText)) {
|
||||||
|
instanceText = `http${VERSION !== "dev" ? "s" : ""}://${instanceText}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.href = `${instanceText}/activitypub/externalInteraction?uri=${encodeURIComponent(
|
||||||
|
communityActorId
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RemoteFetchModal extends Component<
|
||||||
|
RemoteFetchModalProps,
|
||||||
|
RemoteFetchModalState
|
||||||
|
> {
|
||||||
|
state: RemoteFetchModalState = {
|
||||||
|
instanceText: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(props: any, context: any) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +169,7 @@ class RemoteFetchModal extends Component {
|
||||||
<form
|
<form
|
||||||
id="remote-fetch-form"
|
id="remote-fetch-form"
|
||||||
className="modal-body d-flex flex-column justify-content-center"
|
className="modal-body d-flex flex-column justify-content-center"
|
||||||
|
onSubmit={linkEvent(this, submitRemoteFollow)}
|
||||||
>
|
>
|
||||||
<label className="form-label" htmlFor="remoteFetchInstance">
|
<label className="form-label" htmlFor="remoteFetchInstance">
|
||||||
Enter the instance you would like to follow this community from:
|
Enter the instance you would like to follow this community from:
|
||||||
|
@ -135,6 +179,9 @@ class RemoteFetchModal extends Component {
|
||||||
id="remoteFetchInstance"
|
id="remoteFetchInstance"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
name="instance"
|
name="instance"
|
||||||
|
value={this.state.instanceText}
|
||||||
|
onInput={linkEvent(this, handleInput)}
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
<footer className="modal-footer">
|
<footer className="modal-footer">
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
export const VERSION = "unknown version";
|
export const VERSION = "unknown version" as string;
|
||||||
|
|
Loading…
Reference in a new issue