Skip to content

Commit

Permalink
fix: fix subscription time pointer is nil error (#90) and send key er…
Browse files Browse the repository at this point in the history
…ror (#87)
  • Loading branch information
zmh-program committed Mar 8, 2024
1 parent 70aadd5 commit 9916b45
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
34 changes: 29 additions & 5 deletions app/src/components/home/assemblies/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,36 @@ function ChatInput({
placeholder={sender ? t("chat.placeholder-enter") : t("chat.placeholder")}
onKeyDown={async (e) => {
if (e.key === "Enter") {
if (sender || e.ctrlKey) {
// condition sender: Ctrl + Enter if false, Enter if true
// condition e.ctrlKey: Ctrl + Enter if true, Enter if false
if (sender) {
// on Enter, clear the input
// on Ctrl + Enter, keep the input

e.preventDefault();
onEnterPressed();
if (!e.ctrlKey) {
e.preventDefault();
onEnterPressed();
} else {
// add Enter to the input
e.preventDefault();

if (!target || !target.current) return;
const input = target.current as HTMLTextAreaElement;
const value = input.value;
const selectionStart = input.selectionStart;
const selectionEnd = input.selectionEnd;
input.value =
value.slice(0, selectionStart) +
"\n" +
value.slice(selectionEnd);
input.selectionStart = input.selectionEnd = selectionStart + 1;
onValueChange(input.value);
}
} else {
// on Enter, keep the input
// on Ctrl + Enter, clear the input
if (e.ctrlKey) {
e.preventDefault();
onEnterPressed();
}
}
}
}}
Expand Down
2 changes: 1 addition & 1 deletion app/src/conf/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function setAnnouncement(announcement: string): void {
* set the announcement in localStorage
*/
if (!announcement || announcement.trim() === "") return;

const firstReceived = getMemory("announcement") !== announcement;
setMemory("announcement", announcement);

Expand Down
7 changes: 0 additions & 7 deletions app/src/dialogs/ApikeyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog.tsx";
Expand All @@ -11,7 +10,6 @@ import "@/assets/pages/api.less";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import {
closeDialog,
dialogSelector,
setDialog,
keySelector,
Expand Down Expand Up @@ -133,11 +131,6 @@ function ApikeyDialog() {
</div>
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant={`outline`} onClick={() => dispatch(closeDialog())}>
{t("close")}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
Expand Down
7 changes: 6 additions & 1 deletion app/src/routes/Sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ function Sharing() {
}, []);

return (
<div className={cn(`sharing-page`, loading && "flex flex-row items-center justify-center")}>
<div
className={cn(
`sharing-page`,
loading && "flex flex-row items-center justify-center",
)}
>
{loading ? (
<div className={`animate-spin select-none`}>
<Loader2 className={`loader w-12 h-12`} />
Expand Down
7 changes: 6 additions & 1 deletion auth/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ func (u *User) GetSubscription(db *sql.DB) (time.Time, int) {
return time.Unix(0, 0), 0
}

u.Subscription = utils.ConvertTime(expiredAt)
t := utils.ConvertTime(expiredAt)
if t == nil {
t = utils.ToPtr(time.Unix(0, 0))
}

u.Subscription = t
return *u.Subscription, u.Level
}

Expand Down

0 comments on commit 9916b45

Please sign in to comment.