-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate Polls plugin to new plugin infra (#3500)
* feat: migrate Polls plugin to new plugin infra * fix: add worker * chore: migrate to new dialog entry * feat: load worker correctly * chore: change publisher * chore: remove message register from old arch * fixup! chore: remove message register from old arch Co-authored-by: Jack Works <[email protected]>
- Loading branch information
1 parent
9caa747
commit a8e0077
Showing
14 changed files
with
85 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...book/src/plugins/Polls/UI/PollsInPost.tsx → .../plugins/Polls/SNSAdaptor/PollsInPost.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Plugin } from '@masknet/plugin-infra' | ||
import { base } from '../base' | ||
import { POLL_META_KEY_1 } from '../constants' | ||
import type { PollMetaData } from '../types' | ||
import { PollMetadataReader } from '../helpers' | ||
import PollsDialog from './PollsDialog' | ||
import PollsInPost from './PollsInPost' | ||
|
||
const sns: Plugin.SNSAdaptor.Definition = { | ||
...base, | ||
init(signal) {}, | ||
DecryptedInspector: function Comp(props) { | ||
const metadata = PollMetadataReader(props.message.meta) | ||
if (!metadata.ok) return null | ||
return <PollsInPost {...props} /> | ||
}, | ||
CompositionDialogMetadataBadgeRender: new Map([ | ||
[POLL_META_KEY_1, (meta: PollMetaData) => `a poll of '${meta.question}' from ${meta.sender}`], | ||
]), | ||
CompositionDialogEntry: { label: '🗳️ Poll', dialog: PollsDialog }, | ||
} | ||
|
||
export default sns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Plugin } from '@masknet/plugin-infra' | ||
import { base } from '../base' | ||
import '../messages' | ||
|
||
const worker: Plugin.Worker.Definition = { | ||
...base, | ||
init(signal) {}, | ||
} | ||
export default worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Plugin } from '@masknet/plugin-infra' | ||
import { PLUGIN_ID, PLUGIN_ICON, PLUGIN_NAME, PLUGIN_DESCRIPTION } from './constants' | ||
|
||
export const base: Plugin.Shared.Definition = { | ||
ID: PLUGIN_ID, | ||
icon: PLUGIN_ICON, | ||
name: { fallback: PLUGIN_NAME }, | ||
description: { fallback: PLUGIN_DESCRIPTION }, | ||
publisher: { name: { fallback: 'XiChi' }, link: 'https://github.com/xichi' }, | ||
enableRequirement: { | ||
architecture: { app: false, web: true }, | ||
networks: { type: 'opt-out', networks: {} }, | ||
target: 'stable', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createTypedMessageMetadataReader, createRenderWithMetadata } from '../../protocols/typed-message/metadata' | ||
import type { PollMetaData } from './types' | ||
import { POLL_META_KEY_1 } from './constants' | ||
import schema from './schema.json' | ||
|
||
export const PollMetadataReader = createTypedMessageMetadataReader<PollMetaData>(POLL_META_KEY_1, schema) | ||
export const renderWithPollMetadata = createRenderWithMetadata(PollMetadataReader) | ||
if (import.meta.webpackHot) import.meta.webpackHot.accept() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { registerPlugin } from '@masknet/plugin-infra' | ||
import { base } from './base' | ||
|
||
registerPlugin({ | ||
...base, | ||
SNSAdaptor: { | ||
load: () => import('./SNSAdaptor'), | ||
hotModuleReload: (hot) => | ||
import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), | ||
}, | ||
Worker: { | ||
load: () => import('./Worker'), | ||
hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), | ||
}, | ||
}) |
8 changes: 1 addition & 7 deletions
8
packages/maskbook/src/plugins/Polls/utils.ts → ...es/maskbook/src/plugins/Polls/messages.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters