This commit is contained in:
tonyrewin 2022-09-14 14:40:51 +03:00
commit ff35862e02
10 changed files with 25 additions and 16 deletions

View File

@ -32,10 +32,8 @@ export const TopicCard = (props: TopicProps) => {
const subscribe = async (really = true) => {
if (really) {
follow({ what: FollowingEntity.Topic, slug: topic().slug })
// TODO: setSubscribers(topic().stat?.followers as number + 1)
} else {
unfollow({ what: FollowingEntity.Topic, slug: topic().slug })
// TODO: setSubscribers(topic().stat?.followers as number - 1)
}
}
return (

View File

@ -1,5 +1,5 @@
import { Show, createMemo } from 'solid-js'
import type { Author, Shout } from '../../graphql/types.gen'
import type { Author, Reaction, Shout } from '../../graphql/types.gen'
import Row2 from '../Feed/Row2'
import Row3 from '../Feed/Row3'
import Beside from '../Feed/Beside'
@ -13,13 +13,16 @@ import '../../styles/Topic.scss'
import { useStore } from '@nanostores/solid'
import { useTopicsStore } from '../../stores/zine/topics'
// TODO: load reactions on client
type AuthorProps = {
authorArticles: Shout[]
author: Author
// FIXME author topics fro server
// topics: Topic[]
}
export const AuthorPage = (props: AuthorProps) => {
const { getSortedArticles: articles, getArticlesByAuthor } = useArticlesStore({
const { getSortedArticles: articles } = useArticlesStore({
sortedArticles: props.authorArticles
})
const { getAuthorEntities: authors } = useAuthorsStore({ authors: [props.author] })

View File

@ -100,7 +100,7 @@ export const FeedPage = (props: FeedProps) => {
</div>
<ul class="beside-column">
<For each={getTopAuthors()}>
<For each={getTopAuthors().slice(0, 5)}>
{(author) => (
<li>
<AuthorCard author={author} compact={true} hasLink={true} />
@ -129,7 +129,7 @@ export const FeedPage = (props: FeedProps) => {
<Show when={getTopTopics().length > 0}>
<section class="feed-topics">
<h4>{t('Topics')}</h4>
<For each={getTopTopics()}>
<For each={getTopTopics().slice(0, 5)}>
{(topic) => <TopicCard topic={topic} subscribeButtonBottom={true} />}
</For>
</section>

View File

@ -31,16 +31,13 @@ export const SearchPage = (props: Props) => {
<div class="search-page wide-container">
<form action="/search" class="search-form row">
<div class="col-sm-9">
{/*FIXME t*/}
<input type="search" name="q" onChange={handleQueryChange} placeholder="Введите текст..." />
<input type="search" name="q" placeholder="Введите текст..." />
</div>
<div class="col-sm-3">
<button class="button" type="submit" onClick={handleSubmit}>
{t('Search')}
</button>
<button class="button" type="submit">
{t('Search')}
</button>
</div>
</form>

View File

@ -1,7 +1,7 @@
import { gql } from '@urql/core'
export default gql`
query RefreshSessionQuery {
mutation RefreshSessionMutation {
refreshSession {
error
token

View File

@ -1,5 +1,5 @@
import { persistentAtom } from '@nanostores/persistent'
import { action, atom } from 'nanostores'
import { atom } from 'nanostores'
import { useStore } from '@nanostores/solid'
export const locale = persistentAtom<string>('locale', 'ru')

View File

@ -7,7 +7,7 @@ import { byCreated, byStat } from '../../utils/sortby'
export type AuthorsSortBy = 'created' | 'name'
const sortByStore = atom<AuthorsSortBy>('created')
const sortAllByStore = atom<AuthorsSortBy>('created')
let authorEntitiesStore: WritableAtom<{ [authorSlug: string]: Author }>
let authorsByTopicStore: WritableAtom<{ [topicSlug: string]: Author[] }>
@ -21,7 +21,7 @@ const initStore = (initial: { [authorSlug: string]: Author }) => {
authorEntitiesStore = atom(initial)
sortedAuthorsStore = computed([authorEntitiesStore, sortByStore], (authorEntities, sortBy) => {
sortedAuthorsStore = computed([authorEntitiesStore, sortAllByStore], (authorEntities, sortBy) => {
const authors = Object.values(authorEntities)
switch (sortBy) {
case 'created': {
@ -42,6 +42,10 @@ const initStore = (initial: { [authorSlug: string]: Author }) => {
})
}
export const setSortAllBy = (sortBy: AuthorsSortBy) => {
sortAllByStore.set(sortBy)
}
const addAuthors = (authors: Author[]) => {
const newAuthorEntities = authors.reduce((acc, author) => {
acc[author.slug] = author

View File

@ -3,6 +3,7 @@ import { apiClient } from '../../utils/apiClient'
export const follow = async ({ what, slug }: { what: FollowingEntity; slug: string }) => {
await apiClient.follow({ what, slug })
// refresh session
// TODO: _store update code
}
export const unfollow = async ({ what, slug }: { what: FollowingEntity; slug: string }) => {

View File

@ -4,10 +4,11 @@ import { atom, computed } from 'nanostores'
import type { Topic } from '../../graphql/types.gen'
import { useStore } from '@nanostores/solid'
import { byCreated, byStat } from '../../utils/sortby'
import type { AuthorsSortBy } from './authors'
export type TopicsSortBy = 'created' | 'name'
const sortByStore = atom<TopicsSortBy>('created')
const sortAllByStore = atom<TopicsSortBy>('created')
let topicEntitiesStore: WritableAtom<{ [topicSlug: string]: Topic }>
let sortedTopicsStore: ReadableAtom<Topic[]>
@ -22,7 +23,7 @@ const initStore = (initial?: Record<string, Topic>) => {
topicEntitiesStore = atom<Record<string, Topic>>(initial)
sortedTopicsStore = computed([topicEntitiesStore, sortByStore], (topicEntities, sortBy) => {
sortedTopicsStore = computed([topicEntitiesStore, sortAllByStore], (topicEntities, sortBy) => {
const topics = Object.values(topicEntities)
switch (sortBy) {
case 'created': {
@ -48,6 +49,10 @@ const initStore = (initial?: Record<string, Topic>) => {
})
}
export const setSortAllBy = (sortBy: TopicsSortBy) => {
sortAllByStore.set(sortBy)
}
const addTopics = (...args: Topic[][]) => {
const allTopics = args.flatMap((topics) => topics || [])

View File

@ -24,6 +24,7 @@ export const byLength = (a: any[], b: any[]) => {
return 0
}
// FIXME keyof TopicStat
export const byStat = (metric: keyof Stat) => {
return (a, b) => {
const x = (a?.stat && a.stat[metric]) || 0