2024-04-08 14:48:58 +00:00
|
|
|
import { clsx } from "clsx";
|
|
|
|
import { For, Show, createEffect, createSignal, onMount } from "solid-js";
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-04-08 14:48:58 +00:00
|
|
|
import { useFollowing } from "../../../context/following";
|
|
|
|
import { useLocalize } from "../../../context/localize";
|
|
|
|
import { useSession } from "../../../context/session";
|
|
|
|
import { apiClient } from "../../../graphql/client/core";
|
|
|
|
import { Author, Topic } from "../../../graphql/schema/core.gen";
|
|
|
|
import { SubscriptionFilter } from "../../../pages/types";
|
|
|
|
import { dummyFilter } from "../../../utils/dummyFilter";
|
2023-09-21 11:38:22 +00:00
|
|
|
// TODO: refactor styles
|
2024-04-08 14:48:58 +00:00
|
|
|
import { isAuthor } from "../../../utils/isAuthor";
|
|
|
|
import { AuthorBadge } from "../../Author/AuthorBadge";
|
|
|
|
import { ProfileSettingsNavigation } from "../../Nav/ProfileSettingsNavigation";
|
|
|
|
import { TopicBadge } from "../../Topic/TopicBadge";
|
|
|
|
import { Loading } from "../../_shared/Loading";
|
|
|
|
import { SearchField } from "../../_shared/SearchField";
|
2023-09-21 11:38:22 +00:00
|
|
|
|
2024-04-08 14:48:58 +00:00
|
|
|
import styles from "../../../pages/profile/Settings.module.scss";
|
|
|
|
import stylesSettings from "../../../styles/FeedSettings.module.scss";
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-09-27 14:33:06 +00:00
|
|
|
export const ProfileSubscriptions = () => {
|
2024-04-08 14:48:58 +00:00
|
|
|
const { t, lang } = useLocalize();
|
|
|
|
const { author, session } = useSession();
|
|
|
|
const { subscriptions } = useFollowing();
|
|
|
|
const [following, setFollowing] = createSignal<Array<Author | Topic>>([]);
|
|
|
|
const [filtered, setFiltered] = createSignal<Array<Author | Topic>>([]);
|
|
|
|
const [subscriptionFilter, setSubscriptionFilter] =
|
|
|
|
createSignal<SubscriptionFilter>("all");
|
|
|
|
const [searchQuery, setSearchQuery] = createSignal("");
|
2023-09-21 11:38:22 +00:00
|
|
|
|
2024-04-08 12:49:40 +00:00
|
|
|
createEffect(() => {
|
2024-04-08 14:48:58 +00:00
|
|
|
const { authors, topics } = subscriptions;
|
2024-04-08 13:14:19 +00:00
|
|
|
if (authors || topics) {
|
2024-04-08 14:48:58 +00:00
|
|
|
const fdata = [...(authors || []), ...(topics || [])];
|
|
|
|
setFollowing(fdata);
|
|
|
|
if (subscriptionFilter() === "authors") {
|
|
|
|
setFiltered(fdata.filter((s) => "name" in s));
|
|
|
|
} else if (subscriptionFilter() === "topics") {
|
|
|
|
setFiltered(fdata.filter((s) => "title" in s));
|
2024-04-08 13:14:19 +00:00
|
|
|
} else {
|
2024-04-08 14:48:58 +00:00
|
|
|
setFiltered(fdata);
|
2024-04-08 13:04:10 +00:00
|
|
|
}
|
2023-09-21 11:38:22 +00:00
|
|
|
}
|
2024-04-08 14:48:58 +00:00
|
|
|
});
|
2023-09-21 11:38:22 +00:00
|
|
|
|
|
|
|
createEffect(() => {
|
|
|
|
if (searchQuery()) {
|
2024-04-08 14:48:58 +00:00
|
|
|
setFiltered(dummyFilter(following(), searchQuery(), lang()));
|
2023-09-21 11:38:22 +00:00
|
|
|
}
|
2024-04-08 14:48:58 +00:00
|
|
|
});
|
2023-09-21 11:38:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div class="wide-container">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-5">
|
2024-04-08 14:48:58 +00:00
|
|
|
<div class={clsx("left-navigation", styles.leftNavigation)}>
|
2023-09-21 11:38:22 +00:00
|
|
|
<ProfileSettingsNavigation />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-md-19">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-20 col-lg-18 col-xl-16">
|
2024-04-08 14:48:58 +00:00
|
|
|
<h1>{t("My subscriptions")}</h1>
|
|
|
|
<p class="description">
|
|
|
|
{t("Here you can manage all your Discours subscriptions")}
|
|
|
|
</p>
|
2023-09-21 11:38:22 +00:00
|
|
|
<Show when={following()} fallback={<Loading />}>
|
|
|
|
<ul class="view-switcher">
|
2024-04-08 14:48:58 +00:00
|
|
|
<li
|
|
|
|
class={clsx({
|
|
|
|
"view-switcher__item--selected":
|
|
|
|
subscriptionFilter() === "all",
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => setSubscriptionFilter("all")}
|
|
|
|
>
|
|
|
|
{t("All")}
|
2023-09-21 11:38:22 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
2024-04-08 14:48:58 +00:00
|
|
|
<li
|
|
|
|
class={clsx({
|
|
|
|
"view-switcher__item--selected":
|
|
|
|
subscriptionFilter() === "authors",
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => setSubscriptionFilter("authors")}
|
|
|
|
>
|
|
|
|
{t("Authors")}
|
2023-09-21 11:38:22 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
2024-04-08 14:48:58 +00:00
|
|
|
<li
|
|
|
|
class={clsx({
|
|
|
|
"view-switcher__item--selected":
|
|
|
|
subscriptionFilter() === "topics",
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => setSubscriptionFilter("topics")}
|
|
|
|
>
|
|
|
|
{t("Topics")}
|
2023-09-21 11:38:22 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
2024-04-08 14:48:58 +00:00
|
|
|
<div class={clsx("pretty-form__item", styles.searchContainer)}>
|
2023-09-21 11:38:22 +00:00
|
|
|
<SearchField
|
|
|
|
onChange={(value) => setSearchQuery(value)}
|
|
|
|
class={styles.searchField}
|
|
|
|
variant="bordered"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2024-04-08 14:48:58 +00:00
|
|
|
<div
|
|
|
|
class={clsx(stylesSettings.settingsList, styles.topicsList)}
|
|
|
|
>
|
2023-09-21 11:38:22 +00:00
|
|
|
<For each={filtered()}>
|
|
|
|
{(followingItem) => (
|
|
|
|
<div>
|
|
|
|
{isAuthor(followingItem) ? (
|
2024-04-08 14:48:58 +00:00
|
|
|
<AuthorBadge
|
|
|
|
minimizeSubscribeButton={true}
|
|
|
|
author={followingItem}
|
|
|
|
/>
|
2023-09-21 11:38:22 +00:00
|
|
|
) : (
|
2024-04-08 14:48:58 +00:00
|
|
|
<TopicBadge
|
|
|
|
minimizeSubscribeButton={true}
|
|
|
|
topic={followingItem}
|
|
|
|
/>
|
2023-09-21 11:38:22 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-08 14:48:58 +00:00
|
|
|
);
|
|
|
|
};
|