mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-03-28 08:15:55 +00:00
fixed bugs
This commit is contained in:
parent
203226d3d9
commit
44c6b5ad32
@ -28,7 +28,7 @@ const SortableItem = ({ id, name, app }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContextMenuPinnedApps app={app}>
|
<ContextMenuPinnedApps app={app} isMine={!!app?.isMine}>
|
||||||
<ButtonBase
|
<ButtonBase
|
||||||
ref={setNodeRef} {...attributes} {...listeners}
|
ref={setNodeRef} {...attributes} {...listeners}
|
||||||
sx={{
|
sx={{
|
||||||
@ -85,26 +85,51 @@ export const SortablePinnedApps = ({ myWebsite, myApp, availableQapps = [] }) =
|
|||||||
const [pinnedApps, setPinnedApps] = useRecoilState(sortablePinnedAppsAtom);
|
const [pinnedApps, setPinnedApps] = useRecoilState(sortablePinnedAppsAtom);
|
||||||
const setSettingsLocalLastUpdated = useSetRecoilState(settingsLocalLastUpdatedAtom);
|
const setSettingsLocalLastUpdated = useSetRecoilState(settingsLocalLastUpdatedAtom);
|
||||||
|
|
||||||
const transformPinnedApps = useMemo(()=> {
|
const transformPinnedApps = useMemo(() => {
|
||||||
console.log({myWebsite, myApp, availableQapps, pinnedApps})
|
console.log({ myWebsite, myApp, availableQapps, pinnedApps });
|
||||||
let pinned = [...pinnedApps]
|
|
||||||
const findMyWebsite = pinned?.find((item)=> item?.service === myWebsite?.service && item?.name === myWebsite?.name)
|
// Clone the existing pinned apps list
|
||||||
const findMyApp = pinned?.find((item)=> item?.service === myApp?.service && item?.name === myApp?.name)
|
let pinned = [...pinnedApps];
|
||||||
|
|
||||||
if(myWebsite && !findMyWebsite){
|
// Function to add or update `isMine` property
|
||||||
pinned.unshift(myWebsite)
|
const addOrUpdateIsMine = (pinnedList, appToCheck) => {
|
||||||
}
|
if (!appToCheck) return pinnedList;
|
||||||
if(myApp && !findMyApp){
|
|
||||||
pinned.unshift(myApp)
|
const existingIndex = pinnedList.findIndex(
|
||||||
}
|
(item) => item?.service === appToCheck?.service && item?.name === appToCheck?.name
|
||||||
pinned = pinned.map((pin)=> {
|
);
|
||||||
const findIndex = availableQapps?.findIndex((item)=> item?.service === pin?.service && item?.name === pin?.name)
|
|
||||||
if(findIndex !== -1) return availableQapps[findIndex]
|
if (existingIndex !== -1) {
|
||||||
|
// If the app is already in the list, update it with `isMine: true`
|
||||||
return pin
|
pinnedList[existingIndex] = { ...pinnedList[existingIndex], isMine: true };
|
||||||
})
|
} else {
|
||||||
return pinned
|
// If not in the list, add it with `isMine: true` at the beginning
|
||||||
}, [myApp, myWebsite, pinnedApps, availableQapps])
|
pinnedList.unshift({ ...appToCheck, isMine: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
return pinnedList;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update or add `myWebsite` and `myApp` while preserving their positions
|
||||||
|
pinned = addOrUpdateIsMine(pinned, myWebsite);
|
||||||
|
pinned = addOrUpdateIsMine(pinned, myApp);
|
||||||
|
|
||||||
|
// Update pinned list based on availableQapps
|
||||||
|
pinned = pinned.map((pin) => {
|
||||||
|
const findIndex = availableQapps?.findIndex(
|
||||||
|
(item) => item?.service === pin?.service && item?.name === pin?.name
|
||||||
|
);
|
||||||
|
if (findIndex !== -1) return {
|
||||||
|
...availableQapps[findIndex],
|
||||||
|
...pin
|
||||||
|
}
|
||||||
|
|
||||||
|
return pin;
|
||||||
|
});
|
||||||
|
|
||||||
|
return pinned;
|
||||||
|
}, [myApp, myWebsite, pinnedApps, availableQapps]);
|
||||||
|
|
||||||
console.log('transformPinnedApps', transformPinnedApps)
|
console.log('transformPinnedApps', transformPinnedApps)
|
||||||
// const hasSetPinned = useRef(false)
|
// const hasSetPinned = useRef(false)
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
|
@ -22,7 +22,7 @@ const CustomStyledMenu = styled(Menu)(({ theme }) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const ContextMenuPinnedApps = ({ children, app, setEnableDrag }) => {
|
export const ContextMenuPinnedApps = ({ children, app, isMine }) => {
|
||||||
const [menuPosition, setMenuPosition] = useState(null);
|
const [menuPosition, setMenuPosition] = useState(null);
|
||||||
const longPressTimeout = useRef(null);
|
const longPressTimeout = useRef(null);
|
||||||
const maxHoldTimeout = useRef(null);
|
const maxHoldTimeout = useRef(null);
|
||||||
@ -31,6 +31,7 @@ export const ContextMenuPinnedApps = ({ children, app, setEnableDrag }) => {
|
|||||||
const [sortablePinnedApps, setSortablePinnedApps] = useRecoilState(sortablePinnedAppsAtom);
|
const [sortablePinnedApps, setSortablePinnedApps] = useRecoilState(sortablePinnedAppsAtom);
|
||||||
|
|
||||||
const handleContextMenu = (event) => {
|
const handleContextMenu = (event) => {
|
||||||
|
if(isMine) return
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
preventClick.current = true;
|
preventClick.current = true;
|
||||||
@ -41,12 +42,14 @@ export const ContextMenuPinnedApps = ({ children, app, setEnableDrag }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleTouchStart = (event) => {
|
const handleTouchStart = (event) => {
|
||||||
|
if(isMine) return
|
||||||
|
|
||||||
const { clientX, clientY } = event.touches[0];
|
const { clientX, clientY } = event.touches[0];
|
||||||
startTouchPosition.current = { x: clientX, y: clientY };
|
startTouchPosition.current = { x: clientX, y: clientY };
|
||||||
|
|
||||||
longPressTimeout.current = setTimeout(() => {
|
longPressTimeout.current = setTimeout(() => {
|
||||||
preventClick.current = true;
|
preventClick.current = true;
|
||||||
setEnableDrag(false);
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
setMenuPosition({
|
setMenuPosition({
|
||||||
mouseX: clientX,
|
mouseX: clientX,
|
||||||
@ -61,6 +64,8 @@ export const ContextMenuPinnedApps = ({ children, app, setEnableDrag }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleTouchMove = (event) => {
|
const handleTouchMove = (event) => {
|
||||||
|
if(isMine) return
|
||||||
|
|
||||||
const { clientX, clientY } = event.touches[0];
|
const { clientX, clientY } = event.touches[0];
|
||||||
const { x, y } = startTouchPosition.current;
|
const { x, y } = startTouchPosition.current;
|
||||||
|
|
||||||
@ -74,9 +79,10 @@ export const ContextMenuPinnedApps = ({ children, app, setEnableDrag }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleTouchEnd = (event) => {
|
const handleTouchEnd = (event) => {
|
||||||
|
if(isMine) return
|
||||||
|
|
||||||
clearTimeout(longPressTimeout.current);
|
clearTimeout(longPressTimeout.current);
|
||||||
clearTimeout(maxHoldTimeout.current);
|
clearTimeout(maxHoldTimeout.current);
|
||||||
setEnableDrag(true);
|
|
||||||
if (preventClick.current) {
|
if (preventClick.current) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@ -85,6 +91,8 @@ export const ContextMenuPinnedApps = ({ children, app, setEnableDrag }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = (e) => {
|
const handleClose = (e) => {
|
||||||
|
if(isMine) return
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setMenuPosition(null);
|
setMenuPosition(null);
|
||||||
|
@ -68,10 +68,11 @@ export const useQortalGetSaveSettings = (myName) => {
|
|||||||
console.log('settings', settings, timestamp, settingsLocalLastUpdated )
|
console.log('settings', settings, timestamp, settingsLocalLastUpdated )
|
||||||
if(settings?.sortablePinnedApps && timestamp > settingsLocalLastUpdated){
|
if(settings?.sortablePinnedApps && timestamp > settingsLocalLastUpdated){
|
||||||
setSortablePinnedApps(settings.sortablePinnedApps)
|
setSortablePinnedApps(settings.sortablePinnedApps)
|
||||||
setOldPinnedApps(settings.sortablePinnedApps)
|
|
||||||
setSettingsQDNLastUpdated(timestamp || 0)
|
setSettingsQDNLastUpdated(timestamp || 0)
|
||||||
} else if(settings?.sortablePinnedApps){
|
} else if(settings?.sortablePinnedApps){
|
||||||
setSettingsQDNLastUpdated(timestamp || 0)
|
setSettingsQDNLastUpdated(timestamp || 0)
|
||||||
|
setOldPinnedApps(settings.sortablePinnedApps)
|
||||||
}
|
}
|
||||||
if(!settings){
|
if(!settings){
|
||||||
// set -100 to indicate that it couldn't fetch the publish
|
// set -100 to indicate that it couldn't fetch the publish
|
||||||
|
Loading…
x
Reference in New Issue
Block a user