Skip to content

Commit

Permalink
update to check whether profiles already exist and update button text…
Browse files Browse the repository at this point in the history
… accordingly

Tested working updated logic for connection button based on profiles existing

cleanup
  • Loading branch information
djschnei21 authored and TonyGiorgio committed May 9, 2024
1 parent 07a6d12 commit 9cde791
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/components/PendingNwc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
createResource,
createSignal,
For,
Match,
Show,
Switch
Show
} from "solid-js";

import { ButtonCard, GenericItem, InfoBox, NiceP } from "~/components";
Expand Down Expand Up @@ -37,8 +35,11 @@ export function PendingNwc() {

const navigate = useNavigate();

const [hasPreConfiguredNWC, setHasPreConfiguredNWC] = createSignal(false);

async function fetchPendingRequests() {
const profiles = await sw.get_nwc_profiles();
setHasPreConfiguredNWC(!!profiles && profiles.length > 0);
if (!profiles) return [];

const contacts: TagItem[] | undefined = await sw.get_contacts_sorted();
Expand Down Expand Up @@ -159,18 +160,22 @@ export function PendingNwc() {
});

return (
<Switch>
<Match
<>
<ButtonCard onClick={() => navigate("/settings/connections")}>
<div class="flex items-center gap-2">
<PlugZap class="inline-block text-m-red" />
<NiceP>
{hasPreConfiguredNWC()
? i18n.t("home.connection_edit")
: i18n.t("home.connection")}
</NiceP>
</div>
</ButtonCard>
<Show
when={
pendingRequests.latest && pendingRequests.latest!.length > 0
}
>
<ButtonCard onClick={() => navigate("/settings/connections")}>
<div class="flex items-center gap-2">
<PlugZap class="inline-block text-m-red" />
<NiceP>{i18n.t("home.connection_edit")}</NiceP>
</div>
</ButtonCard>
<div class="flex w-full justify-around">
<button
class="flex items-center gap-1 font-semibold text-m-green active:-mb-[1px] active:mt-[1px] active:text-m-green/80"
Expand Down Expand Up @@ -199,7 +204,6 @@ export function PendingNwc() {
<Show when={error()}>
<InfoBox accent="red">{error()?.message}</InfoBox>
</Show>

<For each={pendingRequests.latest}>
{(pendingItem) => (
<GenericItem
Expand All @@ -218,15 +222,7 @@ export function PendingNwc() {
)}
</For>
</div>
</Match>
<Match when={true}>
<ButtonCard onClick={() => navigate("/settings/connections")}>
<div class="flex items-center gap-2">
<PlugZap class="inline-block text-m-red" />
<NiceP>{i18n.t("home.connection")}</NiceP>
</div>
</ButtonCard>
</Match>
</Switch>
</Show>
</>
);
}

0 comments on commit 9cde791

Please sign in to comment.