Skip to content

Commit

Permalink
fix: random seed seq
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Dec 15, 2023
1 parent 6cd5785 commit e3970c9
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 117 deletions.
10 changes: 10 additions & 0 deletions admin/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math"
"strings"
)

func GetInvitationPagination(db *sql.DB, page int64) PaginationForm {
Expand Down Expand Up @@ -62,12 +63,21 @@ func NewInvitationCode(db *sql.DB, code string, quota float32, t string) error {
func GenerateInvitations(db *sql.DB, num int, quota float32, t string) InvitationGenerateResponse {
arr := make([]string, 0)
idx := 0
retry := 0
for idx < num {
code := fmt.Sprintf("%s-%s", t, utils.GenerateChar(24))
if err := NewInvitationCode(db, code, quota, t); err != nil {
// ignore duplicate code
if errors.Is(err, sql.ErrNoRows) {
continue
}

if retry < 100 && strings.Contains(err.Error(), "Duplicate entry") {
retry++
continue
}

retry = 0
return InvitationGenerateResponse{
Status: false,
Message: err.Error(),
Expand Down
26 changes: 26 additions & 0 deletions app/src/assets/admin/all.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,29 @@
min-height: calc(100vh - 56px);
height: max-content;
}

.object-id {
display: flex;
flex-direction: row;
align-items: center;
justify-items: center;
border-radius: var(--radius);
border: 1px solid hsl(var(--border));
color: hsl(var(--text-secondary));
user-select: none;
font-size: 0.75rem;
height: 2.5rem;
padding: 0.5rem 1.25rem;
cursor: pointer;
transition: 0.25s;
flex-shrink: 0;

&:hover {
color: hsl(var(--text));
border-color: hsl(var(--border-hover));
}

svg {
transform: translateY(1px);
}
}
26 changes: 0 additions & 26 deletions app/src/assets/admin/charge.less
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,6 @@
color: hsl(var(--text-secondary));
user-select: none;
}

.target {
display: flex;
flex-direction: row;
align-items: center;
justify-items: center;
border-radius: var(--radius);
border: 1px solid hsl(var(--border));
color: hsl(var(--text-secondary));
user-select: none;
font-size: 0.75rem;
height: 2.5rem;
padding: 0.5rem 1rem;
cursor: pointer;
transition: 0.25s;
flex-shrink: 0;

&:hover {
color: hsl(var(--text));
border-color: hsl(var(--border-hover));
}

svg {
transform: translateY(1px);
}
}
}


Expand Down
17 changes: 9 additions & 8 deletions app/src/components/PopupDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ function PopupDialog({
{t("cancel")}
</Button>
<Button
onClick={() => {
onSubmit &&
onSubmit(value).then((success) => {
if (success) {
setOpen(false);
setValue(defaultValue || "");
}
});
loading={true}
onClick={async () => {
if (!onSubmit) return;

const status: boolean = await onSubmit(value);
if (status) {
setOpen(false);
setValue(defaultValue || "");
}
}}
>
{t("confirm")}
Expand Down
10 changes: 7 additions & 3 deletions app/src/components/admin/ChargeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ function ChargeEditor({
return form.models.length === 0;
}, [form.models]);

const [loading, setLoading] = useState(false);

async function post() {
const resp = await setCharge(preflight({ ...form }));
toastState(toast, t, resp, true);
Expand Down Expand Up @@ -329,7 +331,7 @@ function ChargeEditor({
<div
className={`flex flex-row w-full h-max mt-5 gap-2 items-center flex-wrap`}
>
<div className={`target`}>
<div className={`object-id`}>
<span className={`mr-2`}>ID</span>
{form.id === -1 ? (
<Plus className={`w-3 h-3`} />
Expand All @@ -349,16 +351,18 @@ function ChargeEditor({
<Button
disabled={disabled}
onClick={post}
loading={true}
onLoadingChange={setLoading}
className={`whitespace-nowrap shrink-0`}
>
{form.id === -1 ? (
<>
<Plus className={`w-4 h-4 mr-2`} />
{!loading && <Plus className={`w-4 h-4 mr-2`} />}
{t("admin.charge.add-rule")}
</>
) : (
<>
<PencilLine className={`w-4 h-4 mr-2`} />
{!loading && <PencilLine className={`w-4 h-4 mr-2`} />}
{t("admin.charge.update-rule")}
</>
)}
Expand Down
21 changes: 16 additions & 5 deletions app/src/components/admin/InvitationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import { useTranslation } from "react-i18next";
import { useState } from "react";
import { InvitationForm, InvitationResponse } from "@/admin/types.ts";
import { Button } from "@/components/ui/button.tsx";
import { ChevronLeft, ChevronRight, RotateCw } from "lucide-react";
import { ChevronLeft, ChevronRight, Download, RotateCw } from "lucide-react";
import { useEffectAsync } from "@/utils/hook.ts";
import { generateInvitation, getInvitationList } from "@/admin/api/chart.ts";
import { Input } from "@/components/ui/input.tsx";
import { useToast } from "@/components/ui/use-toast.ts";
import { Textarea } from "@/components/ui/textarea.tsx";
import { saveAsFile } from "@/utils/dom.ts";

function GenerateDialog() {
const { t } = useTranslation();
Expand All @@ -39,7 +40,7 @@ function GenerateDialog() {
return value.replace(/[^\d.]/g, "");
}

async function generate() {
async function generateCode() {
const data = await generateInvitation(type, Number(quota), Number(number));
if (data.status) setData(data.data.join("\n"));
else
Expand All @@ -58,6 +59,10 @@ function GenerateDialog() {
setData("");
}

function downloadCode() {
return saveAsFile("invitation.txt", data);
}

return (
<>
<Dialog open={open} onOpenChange={setOpen}>
Expand Down Expand Up @@ -89,10 +94,10 @@ function GenerateDialog() {
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant={`ghost`} onClick={() => setOpen(false)}>
<Button variant={`outline`} onClick={() => setOpen(false)}>
{t("admin.cancel")}
</Button>
<Button variant={`default`} onClick={generate}>
<Button variant={`default`} loading={true} onClick={generateCode}>
{t("admin.confirm")}
</Button>
</DialogFooter>
Expand All @@ -112,7 +117,13 @@ function GenerateDialog() {
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button onClick={close}>{t("close")}</Button>
<Button variant={`outline`} onClick={close}>
{t("close")}
</Button>
<Button variant={`default`} onClick={downloadCode}>
<Download className={`h-4 w-4 mr-2`} />
{t("download")}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
Expand Down
19 changes: 16 additions & 3 deletions app/src/components/admin/assemblies/ChannelEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Button } from "@/components/ui/button.tsx";
import { useTranslation } from "react-i18next";
import { useMemo, useReducer, useState } from "react";
import Required from "@/components/Require.tsx";
import { Search, X } from "lucide-react";
import { Plus, Search, X } from "lucide-react";
import {
DropdownMenu,
DropdownMenuContent,
Expand Down Expand Up @@ -410,12 +410,25 @@ function ChannelEditor({ display, id, setEnabled }: ChannelEditorProps) {
/>
</div>
</div>
<div className={`mt-4 flex flex-row w-full h-max pr-2`}>
<div className={`mt-4 flex flex-row w-full h-max pr-2 items-center`}>
<div className={`object-id`}>
<span className={`mr-2`}>ID</span>
{edit.id === -1 ? (
<Plus className={`w-3 h-3`} />
) : (
<span className={`id`}>{edit.id}</span>
)}
</div>
<div className={`grow`} />
<Button variant={`outline`} onClick={() => close()}>
{t("cancel")}
</Button>
<Button className={`ml-2`} onClick={post} disabled={!enabled}>
<Button
className={`ml-2`}
loading={true}
onClick={post}
disabled={!enabled}
>
{t("confirm")}
</Button>
</div>
Expand Down
7 changes: 6 additions & 1 deletion app/src/components/home/ConversationSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ function ConversationSegment({
if (state) setOffset(new Date().getTime());
}}
>
<DropdownMenuTrigger>
<DropdownMenuTrigger
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
>
<MoreHorizontal className={`more h-5 w-5 p-0.5`} />
</DropdownMenuTrigger>
<DropdownMenuContent>
Expand Down
Loading

0 comments on commit e3970c9

Please sign in to comment.