diff --git a/src/components/Profile/ProfileComponent.jsx b/src/components/Profile/ProfileComponent.jsx index e693deb70..539eef48a 100644 --- a/src/components/Profile/ProfileComponent.jsx +++ b/src/components/Profile/ProfileComponent.jsx @@ -1,16 +1,9 @@ // React Imports import React, { useContext, useEffect, useState } from 'react'; -// Other Library Imports -import dayjs from 'dayjs'; // Custom Hook Imports import { useSession } from '@hooks'; // Material UI Imports import Box from '@mui/material/Box'; -import FormControl from '@mui/material/FormControl'; -import Typography from '@mui/material/Typography'; -import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; -import { DatePicker } from '@mui/x-date-pickers/DatePicker'; -import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import useMediaQuery from '@mui/material/useMediaQuery'; import { useTheme } from '@mui/material/styles'; // Context Imports @@ -40,18 +33,14 @@ const ProfileComponent = ({ contactProfile }) => { const [profileName, setProfileName] = useState(profileData?.profileInfo?.profileName); const [nickname, setNickname] = useState(profileData?.profileInfo?.nickname); - // Private Profile Data - const [dateOfBirth, setDateOfBirth] = useState(profileData?.privateProfileData?.dateOfBirth); - const [edit, setEdit] = useState(false); const loadProfileData = async () => { - const profileDataSolid = await fetchProfileInfo(session, session.info.webId); + const profileDataSolid = await fetchProfileInfo(session.info.webId); setProfileData(profileDataSolid); setProfileName(profileDataSolid.profileInfo?.profileName); setNickname(profileDataSolid.profileInfo?.nickname); - setDateOfBirth(profileDataSolid.privateProfileInfo?.dateOfBirth); }; const handleCancelEdit = () => { @@ -71,11 +60,7 @@ const ProfileComponent = ({ contactProfile }) => { nickname }; - const inputValuesPrivate = { - dateOfBirth - }; - - await updateProfileInfo(session, profileData, inputValues, inputValuesPrivate); + await updateProfileInfo(session, profileData, inputValues); loadProfileData(); setEdit(false); @@ -85,15 +70,6 @@ const ProfileComponent = ({ contactProfile }) => { loadProfileData(); }, []); - const renderDateOfBirth = () => { - if (contactProfile) { - return contactProfile.dateOfBirth - ? dayjs(contactProfile.dateOfBirth).format('MM/DD/YYYY') - : 'No value set'; - } - return dateOfBirth ? dayjs(dateOfBirth).format('MM/DD/YYYY') : 'No value set'; - }; - const theme = useTheme(); const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm')); @@ -140,23 +116,6 @@ const ProfileComponent = ({ contactProfile }) => { setInputValue={setNickname} edit={edit} /> - - Date of Birth: - {edit ? ( - - - setDateOfBirth(newDateOfBirth)} - disableFuture - /> - - - ) : ( - renderDateOfBirth() - )} - {!contactProfile && ( { } else { await uploadProfileImage(session, profileData, event.target.files[0]); - const updatedProfileData = await fetchProfileInfo(session, session.info.webId); + const updatedProfileData = await fetchProfileInfo(session.info.webId); localStorage.setItem('profileImage', updatedProfileData.profileInfo.profileImage); setProfileImg(updatedProfileData.profileInfo.profileImage); diff --git a/src/contexts/SignedInUserContext.jsx b/src/contexts/SignedInUserContext.jsx index edcdd5956..222c4435b 100644 --- a/src/contexts/SignedInUserContext.jsx +++ b/src/contexts/SignedInUserContext.jsx @@ -10,8 +10,7 @@ import { fetchProfileInfo, updateProfileInfo, uploadProfileImage, - removeProfileImage, - generatePrivateProfileTTL + removeProfileImage } from '../model-helpers'; /** @@ -58,15 +57,14 @@ export const SignedInUserContextProvider = ({ children }) => { let fetchedPodUrl = (await getPodUrlAll(webId, { fetch: session.fetch }))[0]; fetchedPodUrl = fetchedPodUrl || webId.split('profile')[0]; setPodUrl(fetchedPodUrl); - const fetchedProfileData = await fetchProfileInfo(session, webId); + const fetchedProfileData = await fetchProfileInfo(webId); if (fetchedProfileData.profileInfo.profileImage) { localStorage.setItem('profileImage', fetchedProfileData.profileInfo.profileImage); } setProfileData(fetchedProfileData); await Promise.all([ createPASSContainer(session, fetchedPodUrl, 'Documents'), - createPASSContainer(session, fetchedPodUrl, 'Profile'), - generatePrivateProfileTTL(session, fetchedPodUrl) + createPASSContainer(session, fetchedPodUrl, 'Profile') ]); } finally { setLoadingUserInfo(false); diff --git a/src/model-helpers/Profile.js b/src/model-helpers/Profile.js index 91ae0e349..542d85da5 100644 --- a/src/model-helpers/Profile.js +++ b/src/model-helpers/Profile.js @@ -1,19 +1,14 @@ import { buildThing, createAcl, - createSolidDataset, - createThing, deleteFile, - getDate, getFile, - getSolidDataset, getSourceUrl, getStringNoLocale, getThing, getUrl, getWebIdDataset, removeStringNoLocale, - removeDate, removeUrl, saveAclFor, saveFileInContainer, @@ -32,12 +27,11 @@ import { saveSourceUrlToThing, setupAcl } from '../utils'; * card * * @function fetchProfileInfo - * @param {Session} session - Solid's Session Object {@link Session} * @param {URL} webId - WebId of user * @returns {Promise} Object - The object containing the information related * to the person on their profile card, the profile dataset, and the profile Thing */ -export const fetchProfileInfo = async (session, webId) => { +export const fetchProfileInfo = async (webId) => { const profileDataset = await getWebIdDataset(webId); const profileThing = getThing(profileDataset, webId); @@ -45,37 +39,12 @@ export const fetchProfileInfo = async (session, webId) => { const nickname = getStringNoLocale(profileThing, RDF_PREDICATES.nickname); const profileImage = getUrl(profileThing, RDF_PREDICATES.profileImg); - let privateProfileDataset; - let privateProfileThing; - let dateOfBirth; - - try { - privateProfileDataset = await getSolidDataset( - `${webId.split('profile')[0]}PASS/Profile/privateProfile.ttl`, - { fetch: session.fetch } - ); - - privateProfileThing = getThing( - privateProfileDataset, - `${webId.split('profile')[0]}PASS/Profile/privateProfile.ttl#privateProfile` - ); - - dateOfBirth = getDate(privateProfileThing, RDF_PREDICATES.dateOfBirth); - } catch { - privateProfileThing = null; - dateOfBirth = null; - } - const profileInfo = { profileName, nickname, profileImage }; - const privateProfileInfo = { dateOfBirth }; return { profileDataset, profileThing, - profileInfo, - privateProfileDataset, - privateProfileThing, - privateProfileInfo + profileInfo }; }; @@ -89,14 +58,12 @@ export const fetchProfileInfo = async (session, webId) => { * to the person on their profile card, the profile dataset, and the profile Thing * @param {object} inputValues - The inputs for updating profile information * on their profile card - * @param {object} inputValuesPrivate - The inputs for updating private profile - * information on their private profile information * @returns {Promise} Promise - Performs action to update profile card on the * user's profile card */ -export const updateProfileInfo = async (session, profileData, inputValues, inputValuesPrivate) => { - let { profileDataset, profileThing, privateProfileDataset, privateProfileThing } = profileData; - const { profileInfo, privateProfileInfo } = profileData; +export const updateProfileInfo = async (session, profileData, inputValues) => { + let { profileDataset, profileThing } = profileData; + const { profileInfo } = profileData; Object.keys(inputValues).forEach((input) => { switch (inputValues[input]) { @@ -117,37 +84,8 @@ export const updateProfileInfo = async (session, profileData, inputValues, input } }); - Object.keys(inputValuesPrivate).forEach((input) => { - if (input === 'dateOfBirth') { - switch (inputValuesPrivate[input]) { - case null: - privateProfileThing = removeDate( - privateProfileThing, - RDF_PREDICATES[input], - privateProfileInfo[input] - ); - break; - default: - if (inputValuesPrivate[input].$d === undefined) { - return; - } - privateProfileThing = buildThing(privateProfileThing) - .setDate(RDF_PREDICATES[input], inputValuesPrivate[input].$d) - .build(); - break; - } - } - }); - profileDataset = setThing(profileDataset, profileThing); await saveSolidDatasetAt(session.info.webId, profileDataset, { fetch: session.fetch }); - - privateProfileDataset = setThing(privateProfileDataset, privateProfileThing); - await saveSolidDatasetAt( - `${session.info.webId.split('profile')[0]}PASS/Profile/privateProfile.ttl`, - privateProfileDataset, - { fetch: session.fetch } - ); }; /** @@ -219,32 +157,3 @@ export const removeProfileImage = async (session, profileData) => { await deleteFile(profileImg, { fetch: session.fetch }); } }; - -/** - * Function that generates the initial private profile TTL file for user if it - * does not already exist within the user's Pod - * - * @function generatePrivateProfileTTL - * @param {Session} session - Solid's Session Object {@link Session} - * @param {URL} podUrl - Pod URL of user - * @returns {Promise} Promise - Performs action that generates a new privateProfile.ttl - * if it does not exist - */ -export const generatePrivateProfileTTL = async (session, podUrl) => { - const privateProfileUrl = `${podUrl}PASS/Profile/privateProfile.ttl`; - - try { - await getSolidDataset(privateProfileUrl, { fetch: session.fetch }); - } catch { - const privateProfileThing = buildThing(createThing({ name: 'privateProfile' })) - .addUrl(RDF_PREDICATES.url, `${podUrl}PASS/Profile/privateProfile.ttl`) - .build(); - - let newPrivateProvileDataset = createSolidDataset(); - newPrivateProvileDataset = setThing(newPrivateProvileDataset, privateProfileThing); - - await saveSolidDatasetAt(`${podUrl}PASS/Profile/privateProfile.ttl`, newPrivateProvileDataset, { - fetch: session.fetch - }); - } -}; diff --git a/src/pages/Profile.jsx b/src/pages/Profile.jsx index 124860b4e..155b2863c 100644 --- a/src/pages/Profile.jsx +++ b/src/pages/Profile.jsx @@ -97,7 +97,7 @@ const Profile = () => { useEffect(() => { const fetchContactProfile = async () => { - const profileData = await fetchProfileInfo(session, webIdUrl); + const profileData = await fetchProfileInfo(webIdUrl); setContactProfile({ ...contact, ...profileData.profileInfo, diff --git a/test/model-helpers/Profile.test.js b/test/model-helpers/Profile.test.js index 18d809c91..8eb34db50 100644 --- a/test/model-helpers/Profile.test.js +++ b/test/model-helpers/Profile.test.js @@ -44,16 +44,13 @@ describe('fetchProfileInfo', () => { }); vi.spyOn(solidClient, 'getSolidDataset').mockResolvedValue(); - const results = await fetchProfileInfo(session, session.info.webId); + const results = await fetchProfileInfo(session.info.webId); expect(results).toHaveProperty('profileInfo.profileName'); expect(results).toHaveProperty('profileInfo.nickname'); expect(results).toHaveProperty('profileInfo.profileImage'); expect(results).toHaveProperty('profileDataset'); expect(results).toHaveProperty('profileThing'); - expect(results).toHaveProperty('privateProfileInfo.dateOfBirth'); - expect(results).toHaveProperty('privateProfileDataset'); - expect(results).toHaveProperty('privateProfileThing'); }); }); @@ -77,20 +74,16 @@ describe('updateProfileInfo', () => { const mockData = { profileDataset: mockDataset, profileThing: mockDatasetThing, - profileInfo: { profileName: 'Alice', nickname: null, profileImage: null }, - privateProfileDateset: mockDataset, - privateProfileThing: mockDatasetThing, - privateProfileInfo: { dateOfBirth: null } + profileInfo: { profileName: 'Alice', nickname: null, profileImage: null } }; const mockInputValues = { profileName: 'Alice', nickname: null }; - const mockInputValuesPrivate = { dateOfBirth: null }; vi.spyOn(solidClient, 'removeStringNoLocale'); vi.spyOn(solidClient, 'buildThing'); vi.spyOn(solidClient, 'setThing').mockReturnValue(); vi.spyOn(solidClient, 'saveSolidDatasetAt'); - await updateProfileInfo(session, mockData, mockInputValues, mockInputValuesPrivate); + await updateProfileInfo(session, mockData, mockInputValues); expect(solidClient.removeStringNoLocale).not.toBeCalled(); expect(solidClient.buildThing).toBeCalledTimes(1); @@ -102,19 +95,15 @@ describe('updateProfileInfo', () => { const mockData = { profileDataset: mockDataset, profileThing: mockDatasetThing, - profileInfo: { profileName: 'Alice', nickname: null, profileImage: null }, - privateProfileDateset: mockDataset, - privateProfileThing: mockDatasetThing, - privateProfileInfo: { dateOfBirth: null } + profileInfo: { profileName: 'Alice', nickname: null, profileImage: null } }; const mockInputValues = { profileName: 'Alice', nickname: 'Al' }; - const mockInputValuesPrivate = { dateOfBirth: null }; vi.spyOn(solidClient, 'removeStringNoLocale'); vi.spyOn(solidClient, 'buildThing'); vi.spyOn(solidClient, 'saveSolidDatasetAt'); - await updateProfileInfo(session, mockData, mockInputValues, mockInputValuesPrivate); + await updateProfileInfo(session, mockData, mockInputValues); expect(solidClient.removeStringNoLocale).not.toBeCalled(); expect(solidClient.buildThing).toBeCalledTimes(2); @@ -126,19 +115,15 @@ describe('updateProfileInfo', () => { const mockData = { profileDataset: mockDataset, profileThing: mockDatasetThing, - profileInfo: { profileName: 'Alice', nickname: null, profileImage: null }, - privateProfileDateset: mockDataset, - privateProfileThing: mockDatasetThing, - privateProfileInfo: { dateOfBirth: null } + profileInfo: { profileName: 'Alice', nickname: null, profileImage: null } }; const mockInputValues = { profileName: '', nickname: 'Al' }; - const mockInputValuesPrivate = { dateOfBirth: null }; vi.spyOn(solidClient, 'removeStringNoLocale'); vi.spyOn(solidClient, 'buildThing'); vi.spyOn(solidClient, 'saveSolidDatasetAt'); - await updateProfileInfo(session, mockData, mockInputValues, mockInputValuesPrivate); + await updateProfileInfo(session, mockData, mockInputValues); expect(solidClient.removeStringNoLocale).toBeCalledTimes(1); expect(solidClient.buildThing).toBeCalledTimes(1); @@ -166,10 +151,7 @@ describe('uploadProfileImage', () => { const mockData = { profileDataset: mockDataset, profileThing: mockDatasetThing, - profileInfo: { profileName: 'Alice', nickname: null, profileImage: null }, - privateProfileDateset: mockDataset, - privateProfileThing: mockDatasetThing, - privateProfileInfo: { dateOfBirth: null } + profileInfo: { profileName: 'Alice', nickname: null, profileImage: null } }; const mockImageData = new Blob(new Array(9).fill(0), { type: 'image/png' }); const mockInputImage = new File([mockImageData], 'image.png', { type: 'image/png' });