Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Chiu committed Aug 19, 2024
1 parent 8b948ee commit 826bdda
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"i18n-ally.localesPaths": [
"messages"
]
}
16 changes: 14 additions & 2 deletions src/app/[locale]/admin/page.js → src/app/[locale]/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function AdminPage() {
const [newResource, setNewResource] = useState({ name: '', src: '', link: '' });
const [editingIndex, setEditingIndex] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const [error, setError] = useState<string | null>(null);
const router = useRouter();

const checkAuth = useCallback(async () => {
Expand Down Expand Up @@ -55,27 +55,33 @@ export default function AdminPage() {
}
};

// @ts-ignore
const handleInputChange = (e, index = null) => {
const { name, value } = e.target;
if (index !== null) {
const updatedResources = [...resources];
// @ts-ignore
updatedResources[index] = { ...updatedResources[index], [name]: value };
setResources(updatedResources);
} else {
setNewResource({ ...newResource, [name]: value });
}
};

// @ts-ignore
const handleEdit = (index) => {
setEditingIndex(index);
};
// @ts-ignore
const handleCancel = (index) => {
setEditingIndex(null);
};

// @ts-ignore
const handleSave = async (index) => {
// @ts-ignore
let updatedResources = [...resources];
if (index === -1) {
// @ts-ignore
updatedResources.push(newResource);
setNewResource({ name: '', src: '', link: '' });
}
Expand Down Expand Up @@ -127,22 +133,28 @@ export default function AdminPage() {
<TableRow key={index}>
<TableCell>
{editingIndex === index ? (
// @ts-ignore
<Input name="name" value={resource.name} onChange={(e) => handleInputChange(e, index)} />
) : (
// @ts-ignore
resource.name
)}
</TableCell>
<TableCell>
{editingIndex === index ? (
// @ts-ignore
<Input name="src" value={resource.src} onChange={(e) => handleInputChange(e, index)} />
) : (
// @ts-ignore
resource.src
)}
</TableCell>
<TableCell>
{editingIndex === index ? (
// @ts-ignore
<Input name="link" value={resource.link} onChange={(e) => handleInputChange(e, index)} />
) : (
// @ts-ignore
resource.link
)}
</TableCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function LoginPage() {
const [password, setPassword] = useState('');
const router = useRouter();

// @ts-ignore
const handleSubmit = async (e) => {
e.preventDefault();
const response = await fetch('/api/login', {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 826bdda

Please sign in to comment.