Skip to content

Commit

Permalink
fix: not setup prompt not dismissed after click; unused type on net id;
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-0x447f authored and Jack-Works committed Oct 9, 2019
1 parent 7867727 commit 566a9b0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/Welcomes/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function Banner({
)
}
const getStartedDefault = useCallback(() => {
setStorage(props.networkIdentifier as string, { forceDisplayWelcome: false })
setStorage(props.networkIdentifier, { forceDisplayWelcome: false })
unmount()
Services.Welcome.openWelcomePage(lastRecognizedIdentity)
}, [lastRecognizedIdentity, props.networkIdentifier, unmount])
Expand Down
9 changes: 7 additions & 2 deletions src/components/shared/NotSetupYetPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react'
import Services from '../../extension/service'
import { geti18nString } from '../../utils/i18n'
import { SnackbarContent, Button, makeStyles } from '@material-ui/core'
import { Button, makeStyles, SnackbarContent } from '@material-ui/core'
import { GetContext } from '@holoflows/kit/es'
import { useLastRecognizedIdentity } from '../DataSource/useActivatedUI'
import { getActivatedUI } from '../../social-network/ui'
import { setStorage } from '../../utils/browser.storage'

const useNotSetUpYetStyles = makeStyles({
root: {
Expand Down Expand Up @@ -53,10 +55,13 @@ export function NotSetupYetPrompt() {
return (
<NotSetupYetPromptUI
onSetupClick={() => {
if (isContent) {
setStorage(getActivatedUI().networkIdentifier, { forceDisplayWelcome: false }).then()
}
if (GetContext() === 'options') {
location.hash = '/welcome'
} else if (id) {
Services.Welcome.openWelcomePage(id)
Services.Welcome.openWelcomePage(id).then()
}
}}
preparingSetup={isContent && isCurrentIdentityUnknown()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { isMobileFacebook } from '../isMobile'
import { PostInfo } from '../../../social-network/ui'
import { injectPostInspectorDefault } from '../../../social-network/defaults/injectPostInspector'

export const defaultBehavior = injectPostInspectorDefault({
zipPost(node) {
zipEncryptedPostContent(node)
zipPostLinkPreview(node)
},
})
export function injectPostInspectorFacebook(current: PostInfo, node: DOMProxy) {
clickSeeMore(node)
return defaultBehavior(current, node)
return injectPostInspectorDefault({
zipPost(node) {
zipEncryptedPostContent(node)
zipPostLinkPreview(node)
},
})(current, node)
}
function zipPostLinkPreview(node: DOMProxy) {
const parentEle = node.current.parentElement!
Expand Down
2 changes: 1 addition & 1 deletion src/social-network-provider/twitter.com/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const instanceOfTwitterUI = defineSocialNetworkUI({
})
},
ignoreSetupAccount() {
setStorage(host, { userIgnoredWelcome: true }).then()
setStorage(host, { userIgnoredWelcome: true, forceDisplayWelcome: false }).then()
},
shouldDisplayWelcome: shouldDisplayWelcomeDefault,
})
12 changes: 8 additions & 4 deletions src/social-network-provider/twitter.com/ui/inject.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AdditionalPostBox } from '../../../components/InjectedComponents/AdditionalPostBox'
import React from 'react'
import { LiveSelector, MutationObserverWatcher as MOW } from '@holoflows/kit'
import { DOMProxy, LiveSelector, MutationObserverWatcher as MOW } from '@holoflows/kit'
import { newPostEditorBelow } from '../utils/selector'
import { renderInShadowRoot } from '../../../utils/jss/renderInShadowRoot'
import { SocialNetworkUIInjections } from '../../../social-network/ui'
import { nop } from '../../../utils/utils'
import { PostInfo, SocialNetworkUIInjections } from '../../../social-network/ui'
import { injectPostInspectorDefault } from '../../../social-network/defaults/injectPostInspector'

// Closing these shadowRoot prevents external access to them.
const newMOW = (i: LiveSelector<HTMLElement, true>) =>
Expand All @@ -20,7 +20,11 @@ const injectPostBox = () => {
renderInShadowRoot(<AdditionalPostBox />, target.firstDOMProxy.afterShadow)
}

const injectPostInspector = (current: PostInfo, node: DOMProxy) => {
return injectPostInspectorDefault({})(current, node)
}

export const twitterUIInjections: SocialNetworkUIInjections = {
injectPostBox,
injectPostInspector: nop, // TODO: implement this
injectPostInspector,
}
4 changes: 3 additions & 1 deletion src/social-network-provider/twitter.com/ui/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ const taskPasteIntoPostBox: SocialNetworkUI['taskPasteIntoPostBox'] = async (tex
const taskPasteIntoBio = async (text: string) => {
const getValue = () => editProfileTextareaSelector().evaluate()!.value
await untilDocumentReady()
await sleep(800)
try {
editProfileButtonSelector()
.evaluate()!
.click()
} catch {
prompt(geti18nString('automation_request_click_edit_bio_button'))
}
await sleep(400)
await sleep(800)
try {
const i = editProfileTextareaSelector().evaluate()!
i.focus()
await sleep(200)
dispatchCustomEvents('input', i.value + text)
} catch {
console.warn('Text not pasted to the text area')
Expand Down
11 changes: 9 additions & 2 deletions src/social-network/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ export interface SocialNetworkWorkerAndUIDefinition {
*
* For normal network, string like 'twitter.com' is enough.
*
*
* If it works across networks like mastodon,
* use 'mastodon@your-instance.org' and set this to a function
* They are not supported for now.
* To enable support for these, you may merge this type:
* ((networkIdentifier: string, env: Env, preference: Preference) => boolean)
* then use 'mastodon@your-instance.org' and set this to a function
* and resolve all type problems.
*
* At that time, we may also done this by recognize and hardcode it.
*
* @example 'twitter.com'
* (networkIdentifier) => networkIdentifier.startsWith('mastodon')
*/
networkIdentifier: string | ((networkIdentifier: string, env: Env, preference: Preference) => boolean)
networkIdentifier: string
/**
* @param env The env that Maskbook running in
* @param preference Users settings about Maskbook
Expand Down
6 changes: 4 additions & 2 deletions src/social-network/utils/getCurrentNetworkWorker.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { definedSocialNetworkWorkers, SocialNetworkWorker } from '../worker'
import { Identifier, PersonIdentifier, PostIdentifier, GroupIdentifier, PostIVIdentifier } from '../../database/type'
import { GroupIdentifier, Identifier, PersonIdentifier, PostIdentifier, PostIVIdentifier } from '../../database/type'
import { env } from '../shared'

function find(network: string) {
return (v: SocialNetworkWorker) => {
// noinspection SuspiciousTypeOfGuard
if (typeof v.networkIdentifier === 'string') return v.networkIdentifier === network
else return v.networkIdentifier(network, env, {})
// @ts-ignore this is a robust design since sometimes non-string id may supported.
return v.networkIdentifier(network, env, {})
}
}
export default function getCurrentNetworkWorker(network: string | Identifier): SocialNetworkWorker {
Expand Down

0 comments on commit 566a9b0

Please sign in to comment.