Skip to content

Commit da8d572

Browse files
authored
Merge pull request #114 from ClayPulse/dev
Add debounce option when saving file using react-api & add android publishing workflow
2 parents 55630b6 + f63270c commit da8d572

File tree

11 files changed

+153
-23
lines changed

11 files changed

+153
-23
lines changed

.changeset/beige-pumas-run.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pulse-editor/shared-utils": patch
3+
"@pulse-editor/react-api": patch
4+
---
5+
6+
Add rebounce option for useFile hook's saveFile

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"afraid-moments-punch",
1313
"angry-llamas-smash",
1414
"beige-pandas-rhyme",
15+
"beige-pumas-run",
1516
"bumpy-parents-pull",
1617
"calm-rivers-march",
1718
"chatty-trains-beam",
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Publish Android
2+
3+
env:
4+
ANDROID_SDK_VERSION: "36.1.0"
5+
6+
on:
7+
push:
8+
tags:
9+
- "v*.*.*"
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
strategy:
17+
matrix:
18+
target: [android]
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Set up JDK 21
26+
uses: actions/setup-java@v3
27+
with:
28+
java-version: "21"
29+
distribution: "temurin"
30+
31+
- name: Setup Android SDK
32+
uses: android-actions/setup-android@v3
33+
34+
- name: Install Android SDK build tools
35+
run: |
36+
sdkmanager "build-tools;${{env.ANDROID_SDK_VERSION}}"
37+
echo "$ANDROID_SDK_ROOT/build-tools/${{env.ANDROID_SDK_VERSION}}" >> $GITHUB_PATH
38+
39+
- name: Get Keystore
40+
run: |
41+
mkdir ~/.keystore
42+
echo ${{ secrets.ANDROID_KEYSTORE }} | base64 --decode > ~/.keystore/pulse-editor.keystore
43+
44+
- name: Setup Node.js
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: 20
48+
49+
- name: Install shared-utils dependencies
50+
run: npm install --workspace=npm-packages/shared-utils
51+
52+
- name: Build shared-utils
53+
run: npm run shared-utils-build
54+
55+
- name: Install web dependencies
56+
run: npm install --workspace=web
57+
58+
- name: Save public env variables into .env file
59+
run: |
60+
echo NEXT_PUBLIC_BACKEND_URL=$NEXT_PUBLIC_BACKEND_URL >> ./web/.env
61+
echo NEXT_PUBLIC_CDN_URL=$NEXT_PUBLIC_CDN_URL >> ./web/.env
62+
echo NEXT_PUBLIC_STORAGE_CONTAINER=$NEXT_PUBLIC_STORAGE_CONTAINER >> ./web/.env
63+
env:
64+
NEXT_PUBLIC_BACKEND_URL: ${{ vars.NEXT_PUBLIC_BACKEND_URL }}
65+
NEXT_PUBLIC_CDN_URL: ${{ vars.NEXT_PUBLIC_CDN_URL }}
66+
NEXT_PUBLIC_STORAGE_CONTAINER: ${{ vars.NEXT_PUBLIC_STORAGE_CONTAINER }}
67+
68+
- name: Build Web App
69+
run: npm run web-build
70+
71+
- name: Install mobile dependencies
72+
run: npm install --workspace=mobile
73+
74+
- name: Change Android Project Permission
75+
run: chmod +x mobile/android/gradlew
76+
77+
- name: Sync Capacitor App
78+
run: npx cap sync
79+
working-directory: mobile
80+
81+
- name: Build Capacitor App
82+
run: npx cap build android --keystorepath ~/.keystore/pulse-editor.keystore --keystorepass ${{ secrets.ANDROID_KEYSTORE_PASS }} --keystorealias ${{ secrets.ANDROID_KEYSTORE_ALIAS }} --keystorealiaspass ${{ secrets.ANDROID_KEYSTORE_ALIAS_PASS }} --androidreleasetype AAB --signing-type jarsigner
83+
working-directory: mobile
84+
85+
- name: Publish to Play Store
86+
uses: r0adkll/upload-google-play@v1
87+
with:
88+
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
89+
packageName: com.pulse_editor.app
90+
releaseFiles: mobile/android/app/build/outputs/bundle/release/app-release-signed.aab
91+
track: internal
92+
status: draft

mobile/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Android release
22
```bash
33
npx cap sync
4-
# Build .aab file (will fail signing, use the next command to fix)
5-
npx cap build android --keystorepath "<path_to_keystore>" --keystorepass "<keystore_pass>" --keystorealias "<keystore_alias>" --keystorealiaspass "<keystore_alias_pass>" --androidreleasetype AAB
6-
# Sign the .aab
7-
jarsigner -verbose -keystore "<path_to_keystore>" "<path_to_aab>" "<keystore_alias>"
4+
# Build .aab file
5+
npx cap build android --keystorepath "<path_to_keystore>" --keystorepass "<keystore_pass>" --keystorealias "<keystore_alias>" --keystorealiaspass "<keystore_alias_pass>" --androidreleasetype AAB --signing-type jarsigner
86
```
97

108
Then, `mobile/android/app/build/outputs/bundle/release/app-released.aab` is a signed .aab ready for publishing.

mobile/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
applicationId "com.pulse_editor.app"
88
minSdkVersion rootProject.ext.minSdkVersion
99
targetSdkVersion rootProject.ext.targetSdkVersion
10-
versionCode 1
10+
versionCode 2
1111
versionName "v0.1.1-beta"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
aaptOptions {

npm-packages/react-api/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @pulse-editor/react-api
22

3+
## 0.1.1-beta.57
4+
5+
### Patch Changes
6+
7+
- Add rebounce option for useFile hook's saveFile
8+
- Updated dependencies
9+
- @pulse-editor/shared-utils@0.1.1-beta.57
10+
311
## 0.1.1-beta.56
412

513
### Patch Changes

npm-packages/react-api/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/react-api",
3-
"version": "0.1.1-beta.56",
3+
"version": "0.1.1-beta.57",
44
"main": "dist/main.js",
55
"files": [
66
"dist"
@@ -37,8 +37,11 @@
3737
"typescript-eslint": "^8.30.1"
3838
},
3939
"peerDependencies": {
40-
"@pulse-editor/shared-utils": "0.1.1-beta.56",
40+
"@pulse-editor/shared-utils": "0.1.1-beta.57",
4141
"react": "^19.0.0",
4242
"react-dom": "^19.0.0"
43+
},
44+
"dependencies": {
45+
"use-debounce": "^10.0.6"
4346
}
4447
}

npm-packages/react-api/src/hooks/editor/use-file.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/shared-utils";
22
import { useCallback, useEffect, useState } from "react";
3+
import { useDebouncedCallback } from "use-debounce";
34
import useIMC from "../imc/use-imc";
45

5-
export default function useFile(uri: string | undefined) {
6+
/**
7+
*
8+
* @param uri The file URI to read/write
9+
* @param debounce Debounce time in ms for write operations
10+
* @returns
11+
*/
12+
export default function useFile(uri: string | undefined, debounce = 0) {
613
const [file, setFile] = useState<File | undefined>(undefined);
714

815
const receiverHandlerMap = new Map<
@@ -20,26 +27,32 @@ export default function useFile(uri: string | undefined) {
2027

2128
const { imc, isReady } = useIMC(receiverHandlerMap, "file");
2229

30+
const sendFileDebounced = useDebouncedCallback(
31+
async (newFile: File) => {
32+
if (!isReady || !uri) return;
33+
await imc?.sendMessage(IMCMessageTypeEnum.PlatformWriteFile, {
34+
uri,
35+
file: newFile,
36+
});
37+
},
38+
debounce,
39+
{ maxWait: debounce * 2 },
40+
);
41+
2342
const saveFile = useCallback(
24-
(fileContent: string) => {
25-
if (!uri) return;
26-
else if (!file) return;
43+
async (fileContent: string) => {
44+
if (!uri || !file) return;
2745

28-
// Update file content
2946
const newFile = new File([fileContent], file.name, {
3047
type: file.type,
3148
lastModified: Date.now(),
3249
});
3350
setFile(newFile);
3451

35-
if (isReady && uri) {
36-
imc?.sendMessage(IMCMessageTypeEnum.PlatformWriteFile, {
37-
uri,
38-
file: newFile,
39-
});
40-
}
52+
// ✅ This now waits until the debounced write actually finishes
53+
await sendFileDebounced(newFile);
4154
},
42-
[uri, file, isReady],
55+
[file, uri, sendFileDebounced],
4356
);
4457

4558
// Read file when uri changes

npm-packages/shared-utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @pulse-editor/shared-utils
22

3+
## 0.1.1-beta.57
4+
5+
### Patch Changes
6+
7+
- Add rebounce option for useFile hook's saveFile
8+
39
## 0.1.1-beta.56
410

511
### Patch Changes

npm-packages/shared-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/shared-utils",
3-
"version": "0.1.1-beta.56",
3+
"version": "0.1.1-beta.57",
44
"main": "dist/main.js",
55
"files": [
66
"dist"

0 commit comments

Comments
 (0)