Skip to content

Commit

Permalink
feat(ui): store sort order and page size of userlist in localstorage (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danshilm committed Mar 23, 2021
1 parent 1d7a938 commit f5f8269
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/components/Settings/SettingsLogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ const SettingsLogs: React.FC = () => {
const { data: appData } = useSWR('/api/v1/status/appdata');

useEffect(() => {
const displayString = window.localStorage.getItem('logs-display-settings');
const filterString = window.localStorage.getItem('logs-display-settings');

if (displayString) {
const displaySettings = JSON.parse(displayString);
if (filterString) {
const filterSettings = JSON.parse(filterString);

setCurrentFilter(displaySettings.currentFilter);
setCurrentPageSize(displaySettings.currentPageSize);
setCurrentFilter(filterSettings.currentFilter);
setCurrentPageSize(filterSettings.currentPageSize);
}
}, []);

Expand Down
23 changes: 22 additions & 1 deletion src/components/UserList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { Field, Form, Formik } from 'formik';
import Link from 'next/link';
import { useRouter } from 'next/router';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { useToasts } from 'react-toast-notifications';
import useSWR from 'swr';
Expand Down Expand Up @@ -110,6 +110,27 @@ const UserList: React.FC = () => {
const [selectedUsers, setSelectedUsers] = useState<number[]>([]);
const { user: currentUser } = useUser();

useEffect(() => {
const filterString = window.localStorage.getItem('ul-filter-settings');

if (filterString) {
const filterSettings = JSON.parse(filterString);

setCurrentSort(filterSettings.currentSort);
setCurrentPageSize(filterSettings.currentPageSize);
}
}, []);

useEffect(() => {
window.localStorage.setItem(
'ul-filter-settings',
JSON.stringify({
currentSort,
currentPageSize,
})
);
}, [currentSort, currentPageSize]);

const isUserPermsEditable = (userId: number) =>
userId !== 1 && userId !== currentUser?.id;
const isAllUsersSelected = () => {
Expand Down

0 comments on commit f5f8269

Please sign in to comment.