feat: initial commit
This commit is contained in:
27
src/store/authentication.js
Normal file
27
src/store/authentication.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import {makeAutoObservable} from "mobx";
|
||||
|
||||
export class Authentication {
|
||||
ctx;
|
||||
|
||||
accessToken = '';
|
||||
|
||||
refreshToken = '';
|
||||
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
get isLoggedIn() {
|
||||
return !!this.refreshToken;
|
||||
}
|
||||
|
||||
setInitialToken(accessToken, refreshToken) {
|
||||
this.setToken(accessToken, refreshToken);
|
||||
}
|
||||
|
||||
setToken(accessToken, refreshToken) {
|
||||
this.accessToken = accessToken;
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
}
|
||||
14
src/store/index.js
Normal file
14
src/store/index.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import {UI} from "./ui";
|
||||
import {Authentication} from "./authentication";
|
||||
import {User} from "./user";
|
||||
import {Membership} from "./membership";
|
||||
|
||||
export class Store {
|
||||
ui = new UI(this);
|
||||
authentication = new Authentication(this);
|
||||
user = new User(this);
|
||||
membership = new Membership(this);
|
||||
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
37
src/store/membership.js
Normal file
37
src/store/membership.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import {action, makeAutoObservable} from "mobx";
|
||||
import {http} from "../utils/http";
|
||||
|
||||
export class Membership {
|
||||
page = 1;
|
||||
pageSize = 10
|
||||
data = [];
|
||||
total_data = 0
|
||||
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
@action
|
||||
async getData() {
|
||||
const response = await http.get(`/user?page=${this.page}&pageSize=${this.pageSize}`);
|
||||
this.data = response.body.data ?? []
|
||||
this.total_data = response.body.total_data ?? 0
|
||||
}
|
||||
|
||||
@action
|
||||
async create(data) {
|
||||
return await http.post('/user').send(data)
|
||||
}
|
||||
|
||||
@action
|
||||
async update(id, data) {
|
||||
return await http.put('/user/' + id).send(data);
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
return await http.del('/user/' + id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
src/store/ui.js
Normal file
25
src/store/ui.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import {makeAutoObservable} from "mobx";
|
||||
|
||||
export class UI {
|
||||
mediaQuery = {
|
||||
isMobile: false,
|
||||
isDesktop: true
|
||||
};
|
||||
|
||||
testValue = "Test Mobx";
|
||||
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
setTestValue() {
|
||||
this.testValue = "yo dayo";
|
||||
}
|
||||
|
||||
setMediaQuery(data) {
|
||||
if (this.mediaQuery.isDesktop !== data.isDesktop || this.mediaQuery.isMobile !== data.isMobile) {
|
||||
this.mediaQuery = data;
|
||||
}
|
||||
};
|
||||
}
|
||||
13
src/store/user.js
Normal file
13
src/store/user.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import {action, observable} from "mobx";
|
||||
import {http} from "../utils/http";
|
||||
|
||||
export class User {
|
||||
@observable data = [];
|
||||
|
||||
@action
|
||||
async getData() {
|
||||
this.data = (await http.get('/user')).body.data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user