Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'

import type { TArticle } from '@/spec'
import { ICON } from '@/config'
import { Br } from '@/components/Common'

Expand All @@ -14,7 +15,12 @@ import {
Text,
} from './styles/article_sticker'

const CommonSticker = ({ show, viewing }) => {
type TProps = {
show: boolean
viewing: TArticle
}

const ArticleSticker: React.FC<TProps> = ({ show, viewing }) => {
return (
<Wrapper show={show}>
<ItemWrapper>
Expand All @@ -37,4 +43,4 @@ const CommonSticker = ({ show, viewing }) => {
)
}

export default React.memo(CommonSticker)
export default React.memo(ArticleSticker)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import {
/* eslint-disable-next-line */
const log = buildLog('c:CommentSticker:index')

const CommentSticker = ({
type TProps = {
show: boolean
data?: any // TODO
}

const CommentSticker: React.FC<TProps> = ({
show,
data: { pagedCommentsParticipators: users },
}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'

import type { TViewing } from '@/spec'
import { ICON_BASE } from '@/config'
import { Button } from '@/components/Buttons'

Expand All @@ -10,7 +11,12 @@ import {
Divider,
} from './styles/community_sticker'

const CommunitySticker = () => {
type TProps = {
data?: TViewing
show?: boolean
}

const CommunitySticker: React.FC<TProps> = ({ show, data }) => {
return (
<React.Fragment>
<ItemWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import {
} from '../styles/left_sticker/toc'
import { toggleTocMenu } from '../logic'

const Toc = ({ show }) => {
type TProps = {
show: boolean
testid?: string
}

const Toc: React.FC<TProps> = ({ show, testid = 'article-sticker-toc' }) => {
return (
<Wrapper>
<Wrapper testid={testid}>
<HeaderWrapper onClick={toggleTocMenu}>
<TitleWrapper>
<TocIcon src={`${ICON}/article/outline.svg`} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ import {
BackText,
} from '../styles/left_sticker'

const LeftSticker = ({ show, title, isTocMenuOpened }) => {
type TProps = {
show: boolean
title: string
isTocMenuOpened: boolean
testid?: string
}

const LeftSticker: React.FC<TProps> = ({
show,
title,
isTocMenuOpened,
testid = 'article-sticker-left-sidebar',
}) => {
return (
<Wrapper show={show}>
<Wrapper show={show} testid={testid}>
<BackWrapper>
<ArrowIcon src={`${ICON}/shape/arrow-simple.svg`} />
<BackText>Elixir 社区</BackText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

import React from 'react'
import T from 'prop-types'

import { pluggedIn, buildLog } from '@/utils'

import Sticky from '@/components/Sticky'
import GotoTop from '@/components/GotoTop'

import type { TStore } from './store'

import LeftSticker from './LeftSticker/index'
import CommunitySticker from './CommunitySticker'
import ArticleSticker from './ArticleSticker'
Expand All @@ -25,7 +26,15 @@ import { useInit } from './logic'
/* eslint-disable-next-line */
const log = buildLog('C:ArticleSticker')

const ArticleStickerContainer = ({ articleSticker: store, testid }) => {
type TProps = {
articleSticker?: TStore
testid?: string
}

const ArticleStickerContainer: React.FC<TProps> = ({
articleSticker: store,
testid = 'article-sticker',
}) => {
useInit(store)

const {
Expand Down Expand Up @@ -65,13 +74,4 @@ const ArticleStickerContainer = ({ articleSticker: store, testid }) => {
)
}

ArticleStickerContainer.propTypes = {
articleSticker: T.any.isRequired,
testid: T.string,
}

ArticleStickerContainer.defaultProps = {
testid: 'article-sticker',
}

export default pluggedIn(ArticleStickerContainer)
export default pluggedIn(ArticleStickerContainer) as React.FC<TProps>
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { useEffect } from 'react'

import { buildLog } from '@/utils'
// import S from './service'
import type { TStore } from './store'

let store = null
let store: TStore | undefined

/* eslint-disable-next-line */
const log = buildLog('L:ArticleSticker')

export const toggleTocMenu = () => {
export const toggleTocMenu = (): void => {
const isTocMenuOpened = !store.isTocMenuOpened
const isLeftStickerLocked = isTocMenuOpened

Expand All @@ -20,7 +21,7 @@ export const toggleTocMenu = () => {
// init & uninit handlers
// ###############################

export const useInit = (_store) => {
export const useInit = (_store: TStore): void => {
useEffect(() => {
store = _store
log('useInit: ', store)
Expand Down
61 changes: 0 additions & 61 deletions src/containers/tool/ArticleSticker/store.js

This file was deleted.

66 changes: 66 additions & 0 deletions src/containers/tool/ArticleSticker/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* ArticleSticker store
*
*/

import { types as T, getParent, Instance } from 'mobx-state-tree'
// import {} from 'ramda'

import type { TRootStore, TViewing, TScrollDirection } from '@/spec'
import { markStates, buildLog } from '@/utils'
/* eslint-disable-next-line */
const log = buildLog('S:ArticleSticker')

const ArticleSticker = T.model('ArticleSticker', {
isTocMenuOpened: T.optional(T.boolean, false),
// is TOC is opend, then lock the lefsidebar
isLeftStickerLocked: T.optional(T.boolean, false),
})
.views((self) => ({
get viewingData(): TViewing {
const root = getParent(self) as TRootStore
return root.viewingData
},
get bodyScrollDirection(): TScrollDirection {
const root = getParent(self) as TRootStore
return root.globalLayout.bodyScrollDirection
},
get isArticleDigestInViewport(): boolean {
const root = getParent(self) as TRootStore
return root.articleDigest.inViewport
},
get isArticleInViewport(): boolean {
const root = getParent(self) as TRootStore
const { articleInViewport } = root.postContent

return articleInViewport
},
get showLeftSticker(): boolean {
const {
isArticleDigestInViewport,
isLeftStickerLocked,
bodyScrollDirection,
} = self as TStore

if (isArticleDigestInViewport) return false
if (isLeftStickerLocked) return true

return bodyScrollDirection === 'down'
},
get showCommunity(): boolean {
const { isArticleDigestInViewport, isArticleInViewport } = self as TStore
return !isArticleDigestInViewport && isArticleInViewport
},
get showCommentSticker(): boolean {
const { isArticleInViewport } = self as TStore
return !isArticleInViewport
},
}))
.actions((self) => ({
mark(sobj: Record<string, unknown>): void {
markStates(sobj, self)
},
}))

export type TStore = Instance<typeof ArticleSticker>
export default ArticleSticker
1 change: 1 addition & 0 deletions src/spec/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type TArticle = {
nickname: string
avatar: string
}
starredCount?: number
origialCommunity?: TCommunity
commentsParticipators?: TUser
insertedAt?: string
Expand Down