Skip to content

Commit

Permalink
Fix tab navigation (#2328)
Browse files Browse the repository at this point in the history
Fix local storage issue
  • Loading branch information
Fosol authored Nov 12, 2024
1 parent 2b56983 commit ae2ad68
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
7 changes: 3 additions & 4 deletions app/editor/src/features/content/form/ContentNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { FaChevronLeft, FaChevronRight, FaSpinner } from 'react-icons/fa';
import { useNavigate } from 'react-router-dom';
import { useLocalStorage } from 'store/hooks';
import { IContentSearchResult } from 'store/slices';
import { Button, ButtonVariant, Row, Show, Spinner } from 'tno-core';

import { useContentForm } from './hooks';
Expand Down Expand Up @@ -31,7 +30,7 @@ export const ContentNavigation: React.FC<IContentNavigationProps> = ({
const navigate = useNavigate();
const { isProcessing } = useContentForm(values);

const [currentItems] = useLocalStorage<IContentSearchResult[] | null>('currentContent', null);
const [currentItems] = useLocalStorage<number[] | null>('currentContent', null);
const [, setCurrentItemId] = useLocalStorage('currentContentItemId', -1);

const [indexPosition, setIndexPosition] = React.useState(0);
Expand All @@ -40,7 +39,7 @@ export const ContentNavigation: React.FC<IContentNavigationProps> = ({

React.useEffect(() => {
if (currentItems != null) {
let index = !!values.id ? currentItems.findIndex((c) => c.id === +values.id) ?? -1 : -1;
let index = !!values.id ? currentItems.findIndex((c) => c === +values.id) ?? -1 : -1;
setIndexPosition(index);
setEnablePrev(index > 0);
setEnableNext(index < (currentItems.length ?? 0) - 1);
Expand All @@ -49,7 +48,7 @@ export const ContentNavigation: React.FC<IContentNavigationProps> = ({

const handleNavigate = (offset: number) => {
if (currentItems != null) {
const targetId = currentItems[indexPosition + offset]?.id;
const targetId = currentItems[indexPosition + offset];
if (!!targetId) {
setCurrentItemId(targetId);
navigate(getContentPath(targetId, values.contentType));
Expand Down
4 changes: 2 additions & 2 deletions app/editor/src/features/content/list-view/ContentListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const ContentListView: React.FC = () => {
const [, { findWorkOrders }] = useWorkOrders();
// This configures the shared storage between this list and any content tabs
// that are opened. Mainly used for navigation in the tab
const [, setCurrentItems] = useLocalStorage('currentContent', {} as IContentSearchResult[]);
const [, setCurrentItems] = useLocalStorage('currentContent', {} as number[]);
const [currentItemId, setCurrentItemId] = useLocalStorage('currentContentItemId', -1);

const [focusedRowIndex, setFocusedRowIndex] = React.useState(id);
Expand All @@ -80,7 +80,7 @@ const ContentListView: React.FC = () => {
// Stores the current page
const [currentResultsPage, setCurrentResultsPage] = React.useState(defaultPage);
React.useEffect(() => {
setCurrentItems(currentResultsPage.items);
setCurrentItems(currentResultsPage.items.map((i) => i.id));
}, [currentResultsPage, setCurrentItems]);
// if the user navigates next/previous in another window change the highlighted row
React.useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions app/editor/src/features/content/papers/Papers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Papers: React.FC<IPapersProps> = (props) => {

// This configures the shared storage between this list and any content tabs
// that are opened. Mainly used for navigation in the tab
const [, setCurrentItems] = useLocalStorage('currentContent', {} as IContentSearchResult[]);
const [, setCurrentItems] = useLocalStorage('currentContent', {} as number[]);
const [currentItemId, setCurrentItemId] = useLocalStorage('currentContentItemId', -1);

const [isLoading, setIsLoading] = React.useState(false);
Expand Down Expand Up @@ -116,8 +116,8 @@ const Papers: React.FC<IPapersProps> = (props) => {

// Stores the current page
React.useEffect(() => {
setCurrentItems(currentResultsPage.items);
}, [currentResultsPage, setCurrentItems]);
setCurrentItems(currentResultsPage.items.map((i) => i.id));
}, [currentResultsPage.items, setCurrentItems]);

// if the user navigates next/previous in another window change the highlighted row
React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ export function useLocalStorage<T>(key: string, initialValue: T): [T, SetValue<T
// Return a wrapped version of useState's setter function that ...
// ... persists the new value to localStorage.
const setValue: SetValue<T> = useEventCallback((value) => {
// Prevent build error "window is undefined" but keeps working
if (typeof window === 'undefined') {
// console.warn(
// `Tried setting localStorage key “${key}” even though environment is not a client`,
// );
}

try {
// Allow value to be a function so we have the same API as useState
const newValue = value instanceof Function ? value(storedValue) : value;
Expand All @@ -56,7 +49,7 @@ export function useLocalStorage<T>(key: string, initialValue: T): [T, SetValue<T
// We dispatch a custom event so every useLocalStorage hook are notified
window.dispatchEvent(new Event('local-storage'));
} catch (error) {
// console.warn(`Error setting localStorage key “${key}”:`, error);
console.error(`Error setting localStorage key “${key}”:`, error);
}
});

Expand Down
1 change: 0 additions & 1 deletion app/subscriber/src/features/search-page/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export const SearchPage: React.FC<ISearchType> = ({ showAdvanced }) => {
currEndDate.endOf('day');

setStartDate(currStartDate);
console.debug('start', currStartDate.toString());
if (filter.startDate && filter.endDate) {
newFilter = {
...filter,
Expand Down
7 changes: 4 additions & 3 deletions tools/mov-converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ The simple solution is to download and add the `ffmpeg` binary to the path.

4. Fiddle with the Mac OS to allow execution of `ffmpeg`. Using Finder, open the file `/usr/local/ffmpeg` and allow it to run.
5. Create folder `~/Movies/MMI-inbox`
6. Create Automator script
6. Create folder `~/Movies/MMI-outbox`
7. Create Automator script

Choose "Folder Action"
Select the `~/Movies/MMI-inbox` folder
Expand All @@ -44,13 +45,13 @@ do
name=${filename%.*}

cd $path
/usr/local/bin/ffmpeg -y -hide_banner -loglevel error -i $f ${name}.mp4
/usr/local/bin/ffmpeg -y -hide_banner -loglevel error -i $f -c copy ../MMI-outbox/${name}.mp4
done
```

Save the Automator as "Auto Convert to mp4"

7. Create Automator script
8. Create Automator script

Choose "Quick Actions"
Select "Automatic (files or folders)" in "any application"
Expand Down

0 comments on commit ae2ad68

Please sign in to comment.