feat: initial commit

This commit is contained in:
caturbgs
2021-12-09 09:01:39 +07:00
parent f8fdeefa22
commit f27ddcfe90
55 changed files with 16928 additions and 0 deletions

View 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
View 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
View 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
View 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
View 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;
}
}