Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Philreact committed Dec 2, 2024
1 parent e22072d commit 03d0bf0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/components/Apps/AppsNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function saveToLocalStorage(key, subKey, newValue) {
}
}

export const AppsNavBar = () => {
export const AppsNavBar = ({appsMode}) => {
const [tabs, setTabs] = useState([]);
const [selectedTab, setSelectedTab] = useState(null);
const [isNewTabWindow, setIsNewTabWindow] = useState(false);
Expand All @@ -77,10 +77,11 @@ export const AppsNavBar = () => {
const [navigationController, setNavigationController] = useRecoilState(navigationControllerAtom)

const isDisableBackButton = useMemo(()=> {
if(isNewTabWindow && appsMode === 'viewer') return true
if(selectedTab && navigationController[selectedTab?.tabId]?.hasBack) return false
if(selectedTab && !navigationController[selectedTab?.tabId]?.hasBack) return true
return false
}, [navigationController, selectedTab])
}, [navigationController, selectedTab, isNewTabWindow, appsMode])

const setSettingsLocalLastUpdated = useSetRecoilState(
settingsLocalLastUpdatedAtom
Expand Down
2 changes: 1 addition & 1 deletion src/components/Apps/useQortalMessageListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ isDOMContentLoaded: false
} else if (
event?.data?.action === 'PUBLISH_MULTIPLE_QDN_RESOURCES' ||
event?.data?.action === 'PUBLISH_QDN_RESOURCE' ||
event?.data?.action === 'ENCRYPT_DATA' || event?.data?.action === 'ENCRYPT_DATA_WITH_SHARING_KEY' || 'ENCRYPT_QORTAL_GROUP_DATA'
event?.data?.action === 'ENCRYPT_DATA' || event?.data?.action === 'ENCRYPT_DATA_WITH_SHARING_KEY' || event?.data?.action === 'ENCRYPT_QORTAL_GROUP_DATA'

) {
let data;
Expand Down
3 changes: 2 additions & 1 deletion src/components/Embeds/AttachmentEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import DownloadIcon from "@mui/icons-material/Download";
import SaveIcon from '@mui/icons-material/Save';
import { useSetRecoilState } from "recoil";
import { blobControllerAtom } from "../../atoms/global";
import { decodeIfEncoded } from "../../utils/decode";


export const AttachmentCard = ({
Expand Down Expand Up @@ -206,7 +207,7 @@ export const AttachmentCard = ({
color: "white",
}}
>
Created by {owner}
Created by {decodeIfEncoded(owner)}
</Typography>
<Typography
sx={{
Expand Down
13 changes: 7 additions & 6 deletions src/components/Embeds/ImageEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import OpenInNewIcon from "@mui/icons-material/OpenInNew";
import { CustomLoader } from "../../common/CustomLoader";
import ImageIcon from "@mui/icons-material/Image";
import CloseIcon from "@mui/icons-material/Close";
import { decodeIfEncoded } from "../../utils/decode";

export const ImageCard = ({
image,
Expand All @@ -37,11 +38,11 @@ export const ImageCard = ({
}
}, [isOpen]);

useEffect(()=> {
if(errorMsg){
setHeight('300px')
}
}, [errorMsg])
// useEffect(()=> {
// if(errorMsg){
// setHeight('300px')
// }
// }, [errorMsg])

return (
<Card
Expand Down Expand Up @@ -113,7 +114,7 @@ export const ImageCard = ({
color: "white",
}}
>
Created by {owner}
Created by {decodeIfEncoded(owner)}
</Typography>
<Typography
sx={{
Expand Down
5 changes: 3 additions & 2 deletions src/components/Group/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import { useHandleMobileNativeBack } from "../../hooks/useHandleMobileNativeBack
import { AdminSpace } from "../Chat/AdminSpace";
import { useSetRecoilState } from "recoil";
import { selectedGroupIdAtom } from "../../atoms/global";
import { sortArrayByTimestampAndGroupName } from "../../utils/time";

// let touchStartY = 0;
// let disablePullToRefresh = false;
Expand Down Expand Up @@ -910,7 +911,7 @@ export const Group = ({
if (message?.action === "SET_GROUPS") {

// Update the component state with the received 'sendqort' state
setGroups(message.payload);
setGroups(sortArrayByTimestampAndGroupName(message.payload));
getLatestRegularChat(message.payload);
setMemberGroups(message.payload);

Expand Down Expand Up @@ -2673,7 +2674,7 @@ export const Group = ({
)}
{(isMobile && mobileViewMode === "apps" && appsMode !== 'home') && !mobileViewModeKeepOpen && (
<>
<AppsNavBar />
<AppsNavBar appsMode={appsMode} />
</>
)}
</>
Expand Down
16 changes: 16 additions & 0 deletions src/utils/decode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function decodeIfEncoded(input) {
try {
// Check if input is URI-encoded by encoding and decoding
const encoded = encodeURIComponent(decodeURIComponent(input));
if (encoded === input) {
// Input is URI-encoded, so decode it
return decodeURIComponent(input);
}
} catch (e) {
// decodeURIComponent throws an error if input is not encoded
console.error("Error decoding URI:", e);
}

// Return input as-is if not URI-encoded
return input;
}
18 changes: 18 additions & 0 deletions src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ export function formatTimestamp(timestamp: number): string {
const date = moment(unixTimestamp, 'x').fromNow()

return date
}

export function sortArrayByTimestampAndGroupName(array) {
return array.sort((a, b) => {
if (a.timestamp && b.timestamp) {
// Both have timestamp, sort by timestamp descending
return b.timestamp - a.timestamp;
} else if (a.timestamp) {
// Only `a` has timestamp, it comes first
return -1;
} else if (b.timestamp) {
// Only `b` has timestamp, it comes first
return 1;
} else {
// Neither has timestamp, sort alphabetically by groupName
return a.groupName.localeCompare(b.groupName);
}
});
}

0 comments on commit 03d0bf0

Please sign in to comment.