Skip to content

Commit

Permalink
#40 persisted MR settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Polsky committed Oct 22, 2023
1 parent 792911c commit 684d2c3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
6 changes: 3 additions & 3 deletions board/frontend/lib/api/gitlab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get } from "svelte/store";
import { settings } from "../store.js";
import { settingsMergeRequests } from "../store.js";

const GITLAB_API_URL = import.meta.env.VITE_GITLAB_API_URL;
const GITLAB_API_TOKEN = import.meta.env.VITE_GITLAB_API_TOKEN;
Expand Down Expand Up @@ -80,7 +80,7 @@ export const getAllProjectsIssues = async (projectIds) => {
};

export const getProjectIssues = async (projectId) => {
const storeSettings = get(settings);
const storeSettingsMergeRequests = get(settingsMergeRequests);
const perPage = 100;
const issues = [];
let page = 1;
Expand All @@ -101,7 +101,7 @@ export const getProjectIssues = async (projectId) => {
for (const i of data) {
i.merge_requests = [];

if (storeSettings.general.mergeRequests) {
if (storeSettingsMergeRequests) {
i.merge_requests = await getProjectIssueMergeRequests(projectId, i.iid);
}
}
Expand Down
4 changes: 2 additions & 2 deletions board/frontend/lib/components/board/UserBoard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import IssuesColumn from "./IssuesColumn.svelte";
import IssuesRow from "./IssuesRow.svelte";
import { beforeUpdate, afterUpdate } from "svelte";
import { settings, issues, activeProjectFilter, teamprojects, displaymode, teams } from "../../store";
import { settingsMergeRequests, issues, activeProjectFilter, teamprojects, displaymode, teams } from "../../store";
import { getLabelNameById } from "../utils/labels";
import { getTeamColumns } from "../utils/columns";
import { getMemberAvatar } from "../utils/member";
Expand Down Expand Up @@ -42,7 +42,7 @@
return i;
}
if ($settings.general.mergeRequests) {
if ($settingsMergeRequests) {
// Issues by merge requests
if (i.merge_requests.filter(mr => member.id && mr.assignee && mr.assignee.id == member.id).length > 0 && col.gitlab_label_ids.filter(x => i.labels.includes(getLabelNameById(x))).length > 0) {
return i;
Expand Down
4 changes: 2 additions & 2 deletions board/frontend/lib/components/pages/Home.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { onMount } from "svelte";
import {
settings,
settingsMergeRequests,
projects,
teamprojects,
members,
Expand Down Expand Up @@ -97,7 +97,7 @@
$members = await getAllProjectsMembers($projects.map(({id}) => id));
$members = [...$members, {name: "No Assignee", id: null}].sort((a, b) => a.name.localeCompare(b.name));
if ($settings.general.mergeRequests) {
if ($settingsMergeRequests) {
$loadingBoardInfo = "Fetching issues and pull requests...";
} else {
$loadingBoardInfo = "Fetching issues...";
Expand Down
8 changes: 3 additions & 5 deletions board/frontend/lib/components/pages/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
} from "sveltestrap";
import Navbar from "../layout/Navbar.svelte";
import Footer from "../layout/Footer.svelte";
import {settings} from "../../store.js";
import {settingsMergeRequests} from "../../store.js";
const handleChangeSettingGeneralMergeRequests = async (e) => {
console.log($settings);
$settings.general.mergeRequests = e.target.checked;
console.log($settings);
$settingsMergeRequests = e.target.checked;
}
</script>

Expand Down Expand Up @@ -40,7 +38,7 @@
<div class="col-auto">
<input
type="checkbox"
bind:checked={$settings.general.mergeRequests}
checked={$settingsMergeRequests == "true"}
on:change={handleChangeSettingGeneralMergeRequests}/>
</div>
</div>
Expand Down
15 changes: 5 additions & 10 deletions board/frontend/lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { writable, readable } from "svelte/store";
export const loadingBoardInfo = writable("Loading...");
export let authorized = writable(false);

export const settings = writable({
general: {
mergeRequests: false
}
});
const storedSettingsMergeRequests = localStorage.getItem("settingsMergeRequests")
export const settingsMergeRequests = writable(storedSettingsMergeRequests);
settingsMergeRequests.subscribe(val => {
localStorage.setItem("settingsMergeRequests", val);
})

export const projects = writable([]);
export const teamprojects = writable({});
Expand All @@ -33,9 +33,4 @@ export const setAuthorized = (value) => {
authorized = value;
};

export const setSettingGeneralMergeRequests = (value) => {
console.log(settings);
settings.general.mergeRequests = value;
};

export const displaymode = writable("kanban");

0 comments on commit 684d2c3

Please sign in to comment.