2023-02-17 09:21:02 +00:00
|
|
|
import { PageLayout } from '../../components/_shared/PageLayout'
|
2022-11-28 22:14:19 +00:00
|
|
|
import styles from './Settings.module.scss'
|
2023-02-17 09:21:02 +00:00
|
|
|
import stylesSettings from '../../styles/FeedSettings.module.scss'
|
2022-11-28 22:14:19 +00:00
|
|
|
import { clsx } from 'clsx'
|
2023-09-18 16:33:22 +00:00
|
|
|
import { ProfileSettingsNavigation } from '../../components/Nav/ProfileSettingsNavigation'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { SearchField } from '../../components/_shared/SearchField'
|
2023-09-18 16:33:22 +00:00
|
|
|
import { createEffect, createSignal, For, onMount, Show } from 'solid-js'
|
|
|
|
import { Author, Topic } from '../../graphql/types.gen'
|
|
|
|
import { apiClient } from '../../utils/apiClient'
|
|
|
|
import { useSession } from '../../context/session'
|
|
|
|
import { isAuthor } from '../../utils/isAuthor'
|
|
|
|
import { useLocalize } from '../../context/localize'
|
|
|
|
import { SubscriptionFilter } from '../types'
|
|
|
|
import { Loading } from '../../components/_shared/Loading'
|
|
|
|
import { TopicCard } from '../../components/Topic/Card'
|
|
|
|
import { AuthorCard } from '../../components/Author/AuthorCard'
|
|
|
|
import { dummyFilter } from '../../utils/dummyFilter'
|
2022-11-28 22:14:19 +00:00
|
|
|
|
2023-02-10 01:19:20 +00:00
|
|
|
export const ProfileSubscriptionsPage = () => {
|
2023-09-18 16:33:22 +00:00
|
|
|
const { t, lang } = useLocalize()
|
|
|
|
const { user, isAuthenticated } = useSession()
|
|
|
|
const [following, setFollowing] = createSignal<Array<Author | Topic>>([])
|
|
|
|
const [filtered, setFiltered] = createSignal<Array<Author | Topic>>([])
|
|
|
|
const [subscriptionFilter, setSubscriptionFilter] = createSignal<SubscriptionFilter>('all')
|
|
|
|
const [searchQuery, setSearchQuery] = createSignal('')
|
|
|
|
|
|
|
|
const fetchSubscriptions = async () => {
|
|
|
|
try {
|
|
|
|
const [getAuthors, getTopics] = await Promise.all([
|
|
|
|
apiClient.getAuthorFollowingUsers({ slug: user().slug }),
|
|
|
|
apiClient.getAuthorFollowingTopics({ slug: user().slug })
|
|
|
|
])
|
|
|
|
setFollowing([...getAuthors, ...getTopics])
|
|
|
|
setFiltered([...getAuthors, ...getTopics])
|
|
|
|
} catch (error) {
|
|
|
|
console.error('[fetchSubscriptions] :', error)
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isAuthenticated()) {
|
|
|
|
await fetchSubscriptions()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
createEffect(() => {
|
2023-09-20 13:15:34 +00:00
|
|
|
console.log('!!! subscriptionFilter():', subscriptionFilter())
|
2023-09-18 16:33:22 +00:00
|
|
|
if (following()) {
|
|
|
|
if (subscriptionFilter() === 'users') {
|
|
|
|
setFiltered(following().filter((s) => 'name' in s))
|
|
|
|
} else if (subscriptionFilter() === 'topics') {
|
|
|
|
setFiltered(following().filter((s) => 'title' in s))
|
|
|
|
} else {
|
|
|
|
setFiltered(following())
|
|
|
|
}
|
|
|
|
}
|
2023-09-20 13:15:34 +00:00
|
|
|
if (searchQuery()) {
|
|
|
|
setFiltered(dummyFilter(following(), searchQuery(), lang()))
|
|
|
|
}
|
2023-09-18 16:33:22 +00:00
|
|
|
})
|
|
|
|
|
2022-11-28 22:14:19 +00:00
|
|
|
return (
|
2023-02-17 09:21:02 +00:00
|
|
|
<PageLayout>
|
2022-11-28 22:14:19 +00:00
|
|
|
<div class="wide-container">
|
2023-03-23 22:05:23 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-5">
|
2022-11-28 22:14:19 +00:00
|
|
|
<div class={clsx('left-navigation', styles.leftNavigation)}>
|
|
|
|
<ProfileSettingsNavigation />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-03-23 22:05:23 +00:00
|
|
|
<div class="col-md-19">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-20 col-lg-18 col-xl-16">
|
2023-09-18 16:33:22 +00:00
|
|
|
<h1>{t('My subscriptions')}</h1>
|
|
|
|
<p class="description">{t('Here you can manage all your Discourse subscriptions')}</p>
|
|
|
|
<Show when={following()} fallback={<Loading />}>
|
2023-03-23 22:05:23 +00:00
|
|
|
<ul class="view-switcher">
|
2023-09-18 16:33:22 +00:00
|
|
|
<li class={clsx({ 'view-switcher__item--selected': subscriptionFilter() === 'all' })}>
|
|
|
|
<button type="button" onClick={() => setSubscriptionFilter('all')}>
|
|
|
|
{t('All')}
|
|
|
|
</button>
|
2023-03-23 22:05:23 +00:00
|
|
|
</li>
|
2023-09-18 16:33:22 +00:00
|
|
|
<li class={clsx({ 'view-switcher__item--selected': subscriptionFilter() === 'users' })}>
|
|
|
|
<button type="button" onClick={() => setSubscriptionFilter('users')}>
|
|
|
|
{t('Authors')}
|
|
|
|
</button>
|
2023-03-23 22:05:23 +00:00
|
|
|
</li>
|
2023-09-18 16:33:22 +00:00
|
|
|
<li
|
|
|
|
class={clsx({ 'view-switcher__item--selected': subscriptionFilter() === 'topics' })}
|
|
|
|
>
|
|
|
|
<button type="button" onClick={() => setSubscriptionFilter('topics')}>
|
|
|
|
{t('Topics')}
|
|
|
|
</button>
|
2023-03-23 22:05:23 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
2022-11-28 22:14:19 +00:00
|
|
|
|
2023-03-23 22:05:23 +00:00
|
|
|
<div class={clsx('pretty-form__item', styles.searchContainer)}>
|
2023-09-18 16:33:22 +00:00
|
|
|
<SearchField
|
|
|
|
onChange={(value) => setSearchQuery(value)}
|
|
|
|
class={styles.searchField}
|
|
|
|
variant="bordered"
|
|
|
|
/>
|
2023-03-23 22:05:23 +00:00
|
|
|
</div>
|
2022-11-28 22:14:19 +00:00
|
|
|
|
2023-03-23 22:05:23 +00:00
|
|
|
<div class={clsx(stylesSettings.settingsList, styles.topicsList)}>
|
2023-09-18 16:33:22 +00:00
|
|
|
<For each={filtered()}>
|
|
|
|
{(followingItem) => (
|
|
|
|
<div>
|
|
|
|
{isAuthor(followingItem) ? (
|
|
|
|
<AuthorCard
|
|
|
|
author={followingItem}
|
|
|
|
hideWriteButton={true}
|
|
|
|
hasLink={true}
|
|
|
|
isTextButton={true}
|
|
|
|
truncateBio={true}
|
|
|
|
minimizeSubscribeButton={true}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<TopicCard
|
|
|
|
compact
|
|
|
|
isTopicInRow
|
|
|
|
showDescription
|
|
|
|
isCardMode
|
|
|
|
topic={followingItem}
|
|
|
|
minimizeSubscribeButton={true}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
2022-11-28 22:14:19 +00:00
|
|
|
</div>
|
2023-09-18 16:33:22 +00:00
|
|
|
</Show>
|
2023-03-23 22:05:23 +00:00
|
|
|
</div>
|
2022-11-28 22:14:19 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-17 09:21:02 +00:00
|
|
|
</PageLayout>
|
2022-11-28 22:14:19 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
export const Page = ProfileSubscriptionsPage
|