mirror of https://github.com/msgbyte/tailchat
parent
c5b79ae603
commit
5a126eb9e7
@ -1,7 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
externalDeps: ['react', 'styled-components'],
|
externalDeps: ['react', 'react-router', 'axios', 'styled-components', 'zustand', 'zustand/middleware/immer'],
|
||||||
pluginRoot: path.resolve(__dirname, './web'),
|
pluginRoot: path.resolve(__dirname, './web'),
|
||||||
outDir: path.resolve(__dirname, '../../public'),
|
outDir: path.resolve(__dirname, '../../public'),
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
externalDeps: ['react', 'styled-components'],
|
externalDeps: ['react', 'react-router', 'axios', 'styled-components', 'zustand', 'zustand/middleware/immer'],
|
||||||
pluginRoot: path.resolve(__dirname, './web'),
|
pluginRoot: path.resolve(__dirname, './web'),
|
||||||
outDir: path.resolve(__dirname, '../../public'),
|
outDir: path.resolve(__dirname, '../../public'),
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
externalDeps: ['react', 'styled-components'],
|
externalDeps: [
|
||||||
|
'react',
|
||||||
|
'styled-components',
|
||||||
|
'zustand',
|
||||||
|
'zustand/middleware/immer',
|
||||||
|
],
|
||||||
pluginRoot: path.resolve(__dirname, './web'),
|
pluginRoot: path.resolve(__dirname, './web'),
|
||||||
outDir: path.resolve(__dirname, '../../public'),
|
outDir: path.resolve(__dirname, '../../public'),
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
import create from 'zustand';
|
||||||
|
import { immer } from 'zustand/middleware/immer';
|
||||||
|
|
||||||
|
import type { GroupTopic } from './types';
|
||||||
|
|
||||||
|
interface TopicPanelMap {
|
||||||
|
[panelId: string]: GroupTopic[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TopicStoreState {
|
||||||
|
topicMap: TopicPanelMap;
|
||||||
|
addTopicPanel: (panelId: string, topicList: GroupTopic[]) => void;
|
||||||
|
addTopicItem: (panelId: string, topic: GroupTopic) => void;
|
||||||
|
updateTopicItem: (panelId: string, topic: GroupTopic) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useTopicStore = create<
|
||||||
|
TopicStoreState,
|
||||||
|
[['zustand/immer', never]]
|
||||||
|
>(
|
||||||
|
immer((set) => ({
|
||||||
|
topicMap: {},
|
||||||
|
addTopicPanel: (panelId, topicList) => {
|
||||||
|
set((state) => {
|
||||||
|
state.topicMap[panelId] = topicList;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
addTopicItem: (panelId, topic) => {
|
||||||
|
set((state) => {
|
||||||
|
if (state.topicMap[panelId]) {
|
||||||
|
state.topicMap[panelId].unshift(topic);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updateTopicItem: (panelId, topic) => {
|
||||||
|
set((state) => {
|
||||||
|
if (state.topicMap[panelId]) {
|
||||||
|
const findedTopicIndex = state.topicMap[panelId].findIndex(
|
||||||
|
(t) => t._id === topic._id
|
||||||
|
);
|
||||||
|
if (findedTopicIndex >= 0) {
|
||||||
|
state.topicMap[panelId][findedTopicIndex] = topic;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
);
|
Loading…
Reference in New Issue