mirror of
https://github.com/plankanban/planka.git
synced 2025-12-25 09:15:00 +03:00
Initial commit
This commit is contained in:
11
client/src/utils/access-token-storage.js
Executable file
11
client/src/utils/access-token-storage.js
Executable file
@@ -0,0 +1,11 @@
|
||||
const ACCESS_TOKEN_KEY = 'accessToken';
|
||||
|
||||
export const getAccessToken = () => localStorage.getItem(ACCESS_TOKEN_KEY);
|
||||
|
||||
export const setAccessToken = (accessToken) => {
|
||||
localStorage.setItem(ACCESS_TOKEN_KEY, accessToken);
|
||||
};
|
||||
|
||||
export const removeAccessToken = () => {
|
||||
localStorage.removeItem(ACCESS_TOKEN_KEY);
|
||||
};
|
||||
3
client/src/utils/local-id.js
Executable file
3
client/src/utils/local-id.js
Executable file
@@ -0,0 +1,3 @@
|
||||
export const nextLocalId = (maxId = 0) => maxId + Date.now() / 10000000000000;
|
||||
|
||||
export const isLocalId = (id) => id % 1 !== 0;
|
||||
16
client/src/utils/match-paths.js
Executable file
16
client/src/utils/match-paths.js
Executable file
@@ -0,0 +1,16 @@
|
||||
import { matchPath } from 'react-router-dom';
|
||||
|
||||
export default (pathname, paths) => {
|
||||
for (let i = 0; i < paths.length; i += 1) {
|
||||
const match = matchPath(pathname, {
|
||||
path: paths[i],
|
||||
exact: true,
|
||||
});
|
||||
|
||||
if (match) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
42
client/src/utils/timer.js
Normal file
42
client/src/utils/timer.js
Normal file
@@ -0,0 +1,42 @@
|
||||
// eslint-disable-next-line max-len
|
||||
const getFullSeconds = ({ startedAt, total }) => (startedAt ? Math.floor((new Date() - startedAt) / 1000) + total : total);
|
||||
|
||||
export const createTimer = ({ hours, minutes, seconds }) => ({
|
||||
startedAt: null,
|
||||
total: hours * 60 * 60 + minutes * 60 + seconds,
|
||||
});
|
||||
|
||||
export const updateTimer = ({ startedAt }, parts) => ({
|
||||
...createTimer(parts),
|
||||
startedAt: startedAt && new Date(),
|
||||
});
|
||||
|
||||
export const startTimer = (timer) => ({
|
||||
startedAt: new Date(),
|
||||
total: timer ? timer.total : 0,
|
||||
});
|
||||
|
||||
export const stopTimer = (timer) => ({
|
||||
startedAt: null,
|
||||
total: getFullSeconds(timer),
|
||||
});
|
||||
|
||||
export const getTimerParts = (timer) => {
|
||||
const fullSeconds = getFullSeconds(timer);
|
||||
|
||||
const hours = Math.floor(fullSeconds / 3600);
|
||||
const minutes = Math.floor((fullSeconds - hours * 3600) / 60);
|
||||
const seconds = fullSeconds - hours * 3600 - minutes * 60;
|
||||
|
||||
return {
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
};
|
||||
};
|
||||
|
||||
export const formatTimer = (timer) => {
|
||||
const { hours, minutes, seconds } = getTimerParts(timer);
|
||||
|
||||
return [hours, ...[minutes, seconds].map((part) => (part < 10 ? `0${part}` : part))].join(':');
|
||||
};
|
||||
Reference in New Issue
Block a user