Skip to content

Commit 0fd305d

Browse files
author
poulphunter
committed
fix json loading && query with hash
1 parent cdf691c commit 0fd305d

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "tsc -b && vite build",
99
"format": "eslint . && prettier --write .",
1010
"lint": "eslint .",
11+
"lint:fix": "eslint . --fix",
1112
"preview": "vite preview"
1213
},
1314
"dependencies": {

src/components/ChatScreen.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ export interface MessageDisplay {
2424
* If the current URL contains "#m=...", prefill the message input with the value.
2525
* If the current URL contains "#q=...", prefill and SEND the message.
2626
*/
27-
let init_message_done:boolean=false;
28-
let init_query_done:boolean=false;
27+
let init_query_done: boolean = false;
2928
const prefilledMsg = {
3029
clear() {
31-
init_message_done = true;
3230
init_query_done = true;
3331
},
34-
content: function() {
35-
return init_message_done ? '' : INIT_MESSAGE;
32+
content: function () {
33+
if (init_query_done) return '';
34+
if ('' === INIT_QUERY) {
35+
return INIT_MESSAGE;
36+
} else {
37+
return INIT_QUERY;
38+
}
3639
},
37-
shouldSend: function() {
40+
shouldSend: function () {
3841
return init_query_done ? '' : INIT_QUERY;
3942
},
4043
};

src/utils/app.context.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,10 @@ export const AppContextProvider = ({
633633
const [promptSelectFirstConfig, setPromptSelectFirstConfig] =
634634
useState<number>(-1);
635635
// https://swapi.dev/api/planets/1/?format=json
636+
636637
useEffect(() => {
638+
const prt: { key: number; value: string }[] = [];
639+
if (!promptSelectConfig) {
637640
fetch('/prompts.config.json')
638641
.then((response) => {
639642
if (!response.ok) throw new Error(response.status.toString());
@@ -647,15 +650,7 @@ export const AppContextProvider = ({
647650
.catch((error) => {
648651
console.log('error: ' + error);
649652
});
650-
}, [language,
651-
setPromptSelectConfig,
652-
setPromptSelectFirstConfig,
653-
setPromptSelectOptions,
654-
promptSelectConfig
655-
]);
656-
657-
useEffect(() => {
658-
const prt: { key: number; value: string }[] = [];
653+
}
659654
if (promptSelectConfig) {
660655
let firstConfigSet = false;
661656
saveConfig(CONFIG_DEFAULT);

0 commit comments

Comments
 (0)