Skip to content

Commit d24f1a7

Browse files
author
Norman Meier
committed
feat: add module preamble
Signed-off-by: Norman Meier <[email protected]>
1 parent bbab755 commit d24f1a7

File tree

12 files changed

+133
-49
lines changed

12 files changed

+133
-49
lines changed

api/blmod/v1/blmod.proto

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ message ModuleInfo {
1616
IconKind icon_kind = 3;
1717
bytes icon_data = 4;
1818
string short_description = 5;
19+
string preamble = 6;
1920
}
2021

2122
service LabsModulesService {

go/pkg/blmod/blmod.pb.go

+45-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rn/html-mods/ipfs-upload-file/info.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"displayName": "IPFS File Upload",
33
"shortDescription": "Upload a file to IPFS",
44
"iconKind": 1,
5-
"iconData": "4qyG77iP"
5+
"iconData": "4qyG77iP",
6+
"preamble": "Author: Harlan T Wood <[email protected]>\n\nhttps://github.com/ipfs-examples/js-ipfs-http-client-upload-file"
67
}

rn/html-mods/ipns-publish/info.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"displayName": "IPNS Publish",
33
"shortDescription": "Publish to IPNS using JS and Go",
44
"iconKind": 1,
5-
"iconData": "8J+TsA=="
5+
"iconData": "8J+TsA==",
6+
"preamble": "Author: Doug Anderson\n\nhttps://github.com/ipfs-examples/js-ipfs-browser-ipns-publish"
67
}

rn/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"google-protobuf": "^3.19.4",
2525
"react": "17.0.2",
2626
"react-native": "0.67.2",
27+
"react-native-hyperlink": "^0.0.19",
2728
"react-native-labs-bridge": "./react-native-labs-bridge",
2829
"react-native-safe-area-context": "^3.3.2",
2930
"react-native-screens": "^3.11.1",

rn/src/api/blmod/v1/blmod_pb.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class ModuleInfo extends jspb.Message {
2121
getShortDescription(): string
2222
setShortDescription(value: string): void
2323

24+
getPreamble(): string
25+
setPreamble(value: string): void
26+
2427
serializeBinary(): Uint8Array
2528
toObject(includeInstance?: boolean): ModuleInfo.AsObject
2629
static toObject(includeInstance: boolean, msg: ModuleInfo): ModuleInfo.AsObject
@@ -38,6 +41,7 @@ export namespace ModuleInfo {
3841
iconKind: ModuleInfo.IconKindMap[keyof ModuleInfo.IconKindMap]
3942
iconData: Uint8Array | string
4043
shortDescription: string
44+
preamble: string
4145
}
4246

4347
export interface IconKindMap {

rn/src/api/blmod/v1/blmod_pb.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ proto.blmod.v1.ModuleInfo.toObject = function(includeInstance, msg) {
169169
displayName: jspb.Message.getFieldWithDefault(msg, 2, ""),
170170
iconKind: jspb.Message.getFieldWithDefault(msg, 3, 0),
171171
iconData: msg.getIconData_asB64(),
172-
shortDescription: jspb.Message.getFieldWithDefault(msg, 5, "")
172+
shortDescription: jspb.Message.getFieldWithDefault(msg, 5, ""),
173+
preamble: jspb.Message.getFieldWithDefault(msg, 6, "")
173174
};
174175

175176
if (includeInstance) {
@@ -226,6 +227,10 @@ proto.blmod.v1.ModuleInfo.deserializeBinaryFromReader = function(msg, reader) {
226227
var value = /** @type {string} */ (reader.readString());
227228
msg.setShortDescription(value);
228229
break;
230+
case 6:
231+
var value = /** @type {string} */ (reader.readString());
232+
msg.setPreamble(value);
233+
break;
229234
default:
230235
reader.skipField();
231236
break;
@@ -290,6 +295,13 @@ proto.blmod.v1.ModuleInfo.serializeBinaryToWriter = function(message, writer) {
290295
f
291296
);
292297
}
298+
f = message.getPreamble();
299+
if (f.length > 0) {
300+
writer.writeString(
301+
6,
302+
f
303+
);
304+
}
293305
};
294306

295307

@@ -417,6 +429,24 @@ proto.blmod.v1.ModuleInfo.prototype.setShortDescription = function(value) {
417429
};
418430

419431

432+
/**
433+
* optional string preamble = 6;
434+
* @return {string}
435+
*/
436+
proto.blmod.v1.ModuleInfo.prototype.getPreamble = function() {
437+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 6, ""));
438+
};
439+
440+
441+
/**
442+
* @param {string} value
443+
* @return {!proto.blmod.v1.ModuleInfo} returns this
444+
*/
445+
proto.blmod.v1.ModuleInfo.prototype.setPreamble = function(value) {
446+
return jspb.Message.setProto3StringField(this, 6, value);
447+
};
448+
449+
420450

421451

422452

rn/src/navigation/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export type ScreensParams = {
1111
ArtCollection: undefined
1212
NodeManager: undefined
1313
NodeConfig: { name: string }
14-
GoModule: { name: string; displayName: string }
14+
GoModule: { name: string; displayName?: string; preamble?: string }
1515
HTMLModule: {
1616
name: string
1717
displayName?: string
18+
preamble?: string
1819
}
1920
IPFSLogs: undefined
2021
Browser: undefined

rn/src/screens/GoModule.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export const GoModule: ScreenFC<'GoModule'> = ({
3131
}) => {
3232
const { setOptions } = useAppNavigation()
3333
React.useEffect(() => {
34-
setOptions({ title: displayName })
35-
}, [setOptions, displayName])
34+
setOptions({ title: displayName || name })
35+
}, [setOptions, displayName, name])
3636
const { state, text, error, args } = useAppSelector(state => selectModuleState(state, name))
3737
const running = state === 'running'
3838
const dispatch = useAppDispatch()

rn/src/screens/HTMLModule.tsx

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import React from 'react'
22
import { Text } from 'react-native'
33
import { WebView } from 'react-native-webview'
4+
import Hyperlink from 'react-native-hyperlink'
45

56
import { ScreenFC, useAppNavigation } from '@berty-labs/navigation'
67
import { defaultColors } from '@berty-labs/styles'
7-
import { AppScreenContainer, LoaderScreen } from '@berty-labs/components'
8+
import { AppScreenContainer, Card, LoaderScreen } from '@berty-labs/components'
89
import { useGomobileIPFS } from '@berty-labs/react-redux'
910

11+
const space = 15
12+
1013
export const HTMLModule: ScreenFC<'HTMLModule'> = ({
1114
route: {
12-
params: { name, displayName },
15+
params: { name, displayName, preamble },
1316
},
1417
}) => {
1518
const nav = useAppNavigation()
1619
const mobileIPFS = useGomobileIPFS()
1720
const [localError, setLocalError] = React.useState<string>()
1821

1922
React.useEffect(() => {
20-
if (!displayName) {
21-
return
22-
}
23-
nav.setOptions({ title: displayName })
24-
}, [nav, displayName])
23+
nav.setOptions({ title: displayName || name })
24+
}, [nav, displayName, name])
2525

2626
if (mobileIPFS.status !== 'up') {
2727
return <LoaderScreen text='Waiting for IPFS node...' />
@@ -35,6 +35,15 @@ export const HTMLModule: ScreenFC<'HTMLModule'> = ({
3535
}
3636
return (
3737
<AppScreenContainer>
38+
{!!preamble && (
39+
<Card style={{ marginBottom: space }}>
40+
<Hyperlink linkDefault={true}>
41+
<Text style={{ color: defaultColors.text }} selectable={true}>
42+
{preamble.trim()}
43+
</Text>
44+
</Hyperlink>
45+
</Card>
46+
)}
3847
<WebView
3948
style={{ backgroundColor: defaultColors.background }}
4049
source={{

rn/src/screens/home/ToolsList.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type HTMLModule = {
8383
iconKind?: 'UTF'
8484
iconUTF?: string
8585
infoError?: unknown
86+
preamble?: string
8687
}
8788

8889
const maxOpacity = 1
@@ -160,6 +161,7 @@ export const ToolsList: React.FC<{ searchText: string }> = React.memo(({ searchT
160161
shortDescription: pbInfo.shortDescription,
161162
iconKind: 'UTF',
162163
iconUTF,
164+
preamble: pbInfo.preamble,
163165
}
164166
return info
165167
} catch (err) {

rn/yarn.lock

+25
Original file line numberDiff line numberDiff line change
@@ -6594,6 +6594,13 @@ lines-and-columns@^1.1.6:
65946594
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
65956595
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
65966596

6597+
linkify-it@^2.2.0:
6598+
version "2.2.0"
6599+
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-2.2.0.tgz#e3b54697e78bf915c70a38acd78fd09e0058b1cf"
6600+
integrity sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==
6601+
dependencies:
6602+
uc.micro "^1.0.1"
6603+
65976604
locate-path@^3.0.0:
65986605
version "3.0.0"
65996606
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
@@ -6809,6 +6816,11 @@ [email protected]:
68096816
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.14.tgz#7113fc4281917d63ce29b43446f701e68c25ba50"
68106817
integrity sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==
68116818

6819+
mdurl@^1.0.0:
6820+
version "1.0.1"
6821+
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
6822+
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=
6823+
68126824
merge-options@^3.0.4:
68136825
version "3.0.4"
68146826
resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-3.0.4.tgz#84709c2aa2a4b24c1981f66c179fe5565cc6dbb7"
@@ -8103,6 +8115,14 @@ react-native-codegen@^0.0.8:
81038115
jscodeshift "^0.11.0"
81048116
nullthrows "^1.1.1"
81058117

8118+
react-native-hyperlink@^0.0.19:
8119+
version "0.0.19"
8120+
resolved "https://registry.yarnpkg.com/react-native-hyperlink/-/react-native-hyperlink-0.0.19.tgz#ca375cde1d244bb94c551736852ee0d688c8bb1f"
8121+
integrity sha512-x4wuRGDMnnpWcRr5MCK1D2UcEuzD9IHK8lfjEhO/+QqXNaX31HdeD3ss3BXXZgHxpRYtLbTB0TuFcl1HHANp3w==
8122+
dependencies:
8123+
linkify-it "^2.2.0"
8124+
mdurl "^1.0.0"
8125+
81068126
react-native-labs-bridge@./react-native-labs-bridge:
81078127
version "0.1.0"
81088128

@@ -9473,6 +9493,11 @@ ua-parser-js@^0.7.30:
94739493
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.31.tgz#649a656b191dffab4f21d5e053e27ca17cbff5c6"
94749494
integrity sha512-qLK/Xe9E2uzmYI3qLeOmI0tEOt+TBBQyUIAh4aAgU05FVYzeZrKUdkAZfBNVGRaHVgV0TDkdEngJSw/SyQchkQ==
94759495

9496+
uc.micro@^1.0.1:
9497+
version "1.0.6"
9498+
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
9499+
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==
9500+
94769501
uglify-es@^3.1.9:
94779502
version "3.3.9"
94789503
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"

0 commit comments

Comments
 (0)