mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
dashboard/api: add support for Zeppelin staff members; add ViewGuild permission; code cleanup
This commit is contained in:
parent
7e60950900
commit
d03d729438
13 changed files with 175 additions and 75 deletions
|
@ -41,7 +41,17 @@
|
|||
AceEditor,
|
||||
},
|
||||
async mounted() {
|
||||
await this.$store.dispatch("guilds/loadAvailableGuilds");
|
||||
try {
|
||||
await this.$store.dispatch("guilds/loadGuild", this.$route.params.guildId);
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError) {
|
||||
this.$router.push('/dashboard');
|
||||
return;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (this.guild == null) {
|
||||
this.$router.push('/dashboard');
|
||||
return;
|
||||
|
@ -66,7 +76,7 @@
|
|||
computed: {
|
||||
...mapState('guilds', {
|
||||
guild() {
|
||||
return this.$store.state.guilds.available.find(g => g.id === this.$route.params.guildId);
|
||||
return this.$store.state.guilds.available.get(this.$route.params.guildId);
|
||||
},
|
||||
config() {
|
||||
return this.$store.state.guilds.configs[this.$route.params.guildId];
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
computed: {
|
||||
...mapState('guilds', {
|
||||
guilds: state => {
|
||||
const guilds = Array.from(state.available || []);
|
||||
const guilds = Array.from(state.available.values());
|
||||
guilds.sort((a, b) => {
|
||||
if (a.name > b.name) return 1;
|
||||
if (a.name < b.name) return -1;
|
||||
|
|
|
@ -7,7 +7,7 @@ export const GuildStore: Module<GuildState, RootState> = {
|
|||
|
||||
state: {
|
||||
availableGuildsLoadStatus: LoadStatus.None,
|
||||
available: [],
|
||||
available: new Map(),
|
||||
configs: {},
|
||||
},
|
||||
|
||||
|
@ -17,7 +17,22 @@ export const GuildStore: Module<GuildState, RootState> = {
|
|||
commit("setAvailableGuildsLoadStatus", LoadStatus.Loading);
|
||||
|
||||
const availableGuilds = await get("guilds/available");
|
||||
commit("setAvailableGuilds", availableGuilds);
|
||||
for (const guild of availableGuilds) {
|
||||
commit("addGuild", guild);
|
||||
}
|
||||
|
||||
commit("setAvailableGuildsLoadStatus", LoadStatus.Done);
|
||||
},
|
||||
|
||||
async loadGuild({ commit, state }, guildId) {
|
||||
if (state.available.has(guildId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const guild = await get(`guilds/${guildId}`);
|
||||
if (guild) {
|
||||
commit("addGuild", guild);
|
||||
}
|
||||
},
|
||||
|
||||
async loadConfig({ commit }, guildId) {
|
||||
|
@ -35,9 +50,8 @@ export const GuildStore: Module<GuildState, RootState> = {
|
|||
state.availableGuildsLoadStatus = status;
|
||||
},
|
||||
|
||||
setAvailableGuilds(state: GuildState, guilds) {
|
||||
state.available = guilds;
|
||||
state.availableGuildsLoadStatus = LoadStatus.Done;
|
||||
addGuild(state: GuildState, guild) {
|
||||
state.available.set(guild.id, guild);
|
||||
},
|
||||
|
||||
setConfig(state: GuildState, { guildId, config }) {
|
||||
|
|
|
@ -11,11 +11,14 @@ export interface AuthState {
|
|||
|
||||
export interface GuildState {
|
||||
availableGuildsLoadStatus: LoadStatus;
|
||||
available: Array<{
|
||||
guild_id: string;
|
||||
name: string;
|
||||
icon: string | null;
|
||||
}>;
|
||||
available: Map<
|
||||
string,
|
||||
{
|
||||
id: string;
|
||||
name: string;
|
||||
icon: string | null;
|
||||
}
|
||||
>;
|
||||
configs: {
|
||||
[key: string]: string;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue