Skip to content

Commit

Permalink
fix: 切换语言时的代码本地保存错乱修复
Browse files Browse the repository at this point in the history
  • Loading branch information
xjq7 committed Oct 25, 2022
1 parent cc41369 commit 7b95d9c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ jobs:
- name: Build
run: pnpm build

# cdn 部署
- name: Deploy static source
run: pnpm cdn ${{ secrets.ACCESS_KEY_ID }} ${{ secrets.ACCESS_KEY_SECRET }} ${{ secrets.OSS_BUCKET }} ${{ secrets.OSS_REGION }}

# 移除 部署 cdn 的文件
- name: remove static file which is deploy cdn
run: rm -rf dist/assets

# 推到服务器
- name: Deploy to Server # 第二步,rsync推文件
uses: AEnterprise/rsync-deploy@v1.0 # 使用别人包装好的步骤镜像
env:
Expand All @@ -64,6 +67,7 @@ jobs:
USERNAME: ${{ secrets.SSH_USER }} # 引用配置,服务器登录名
SERVER_DESTINATION: /root/project/runcodeclient # 部署到目标文件夹

# nginx 重启
- name: Restart server # 第三步,重启服务
uses: appleboy/ssh-action@master
with:
Expand Down
Binary file removed client/src/assets/github.png
Binary file not shown.
7 changes: 5 additions & 2 deletions client/src/pages/editor/components/Operator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ function Operator(props: Props) {
const editor = getEditor();

if (editor) {
const debounceSaveCode = debounce(saveCode, autoSaveDelay * 1000);
const saveCodeListen = editor
?.getModel()
?.onDidChangeContent(debounce(saveCode, autoSaveDelay * 1000));
?.onDidChangeContent(debounceSaveCode);
const saveDisabledListen = editor?.getModel()?.onDidChangeContent(() => {
setSaveDisabled(false);
});
return () => {
saveCodeListen?.dispose();
saveDisabledListen?.dispose();
// 取消前一个 debounce
debounceSaveCode.cancel();
};
}
}, [autoSaveDelay]);
}, [codeType, getEditor, autoSaveDelay]);

const renderInput = () => {
return (
Expand Down
4 changes: 4 additions & 0 deletions client/src/pages/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { observer } from 'mobx-react-lite';
import EditorConfig from '~store/config/editor';
import Header, { settingDrawerId } from './components/Header';
import Operator from './components/Operator';
import storage from '~utils/storage';
import { CodeStorageKey } from '~constant/storage';

const Component = observer(() => {
const editorRef = useRef<Expose>(null);
Expand All @@ -31,6 +33,8 @@ const Component = observer(() => {
codeType={codeType}
themeType={editorThemeType}
onCodeTypeChange={(type) => {
// 切换语言前保存代码
storage.set(CodeStorageKey[codeType], getEditor()?.getValue());
setCodeType(type);
}}
onThemeTypeChange={(type) => {
Expand Down

0 comments on commit 7b95d9c

Please sign in to comment.