Skip to content

Commit

Permalink
MobX
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Jan 8, 2025
1 parent b24fc07 commit add61ef
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
10 changes: 10 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"bootstrap": "^5.3.3",
"mobx": "^6.13.5",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/ConfigAbout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function ConfigAbout() {
size=""
body={
<>
<p>About: <a href="https://github.com/aceberg/AnyAppStart">https://github.com/aceberg/AnyAppStart</a></p>
<p>Donate: <a href="https://github.com/aceberg#donate">https://github.com/aceberg#donate</a></p>
<p>About: <a href="https://github.com/aceberg/AnyAppStart" target="_blank">https://github.com/aceberg/AnyAppStart</a></p>
<p>Donate: <a href="https://github.com/aceberg#donate" target="_blank">https://github.com/aceberg#donate</a></p>
</>
}
onClose={handleCloseModal}
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/EditItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from "react";
import BootstrapModal from "./Modal";
import { apiSaveItem, Item } from "../functions/api";
import mobxStore from "../functions/store";

function EditItem(_props: any) {

Expand Down Expand Up @@ -55,6 +56,13 @@ function EditItem(_props: any) {
setModalOpen(false);
}

const handleSelectType = (event: React.ChangeEvent<HTMLSelectElement>) => {
setFormData((prev) => ({
...prev,
Type: event.target.value,
}));
};

return (
<>
<span onClick={handleEdit}>{_props.btnContent}</span>
Expand All @@ -69,7 +77,11 @@ function EditItem(_props: any) {
<label htmlFor="nid" className="form-label text-primary">Name</label>
<input className="form-control mb-3" defaultValue={item.Name} id="nid" name="Name" onChange={handleChange} placeholder="Not empty string"></input>
<label htmlFor="tid" className="form-label text-primary">Type</label>
<input className="form-control mb-3" defaultValue={item.Type} id="tid" name="Type" onChange={handleChange}></input>
<select className="form-select mb-3" id="tid" onChange={handleSelectType} value={formData.Type}>
{mobxStore?.typeList.map((t, i) => (
<option key={i} value={t.Name}>{t.Name}</option>
))}
</select>
<label htmlFor="lid" className="form-label text-primary">Link</label>
<input className="form-control mb-3" defaultValue={item.Link} id="lid" name="Link" onChange={handleChange} placeholder="URL"></input>
<hr></hr>
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/TypesList.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { useEffect, useState } from "react";
import { getTypes, TypeStruct } from "../functions/api";
import TypeEdit from "./TypeEdit";
import mobxStore from "../functions/store";

function TypesList(_props:any) {

const [types, setTypes] = useState<TypeStruct[]>([]);

useEffect(() => {
const fetchData = async () => {

setTypes(await getTypes());

const t = await getTypes();
setTypes(t);
mobxStore.setTypeList(t);
};

fetchData();
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/functions/store.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { makeAutoObservable } from 'mobx';
import { TypeStruct } from './api';

class MobxStore {
typeList:TypeStruct[] = [];

constructor() {
makeAutoObservable(this);
}

setTypeList(list:TypeStruct[]) {
this.typeList = list;
}
}

const mobxStore = new MobxStore();
export default mobxStore;

0 comments on commit add61ef

Please sign in to comment.