Skip to content

Commit

Permalink
Revert "try to deal with offline project listings - not working"
Browse files Browse the repository at this point in the history
Now fixed in another PR.

Signed-off-by: Steve Cassidy <steve.cassidy@mq.edu.au>
  • Loading branch information
stevecassidy committed Dec 11, 2024
1 parent 8e140e8 commit 9299089
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 43 deletions.
4 changes: 1 addition & 3 deletions app/src/context/functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ const getProjects = async (url: string, token: string) => {
headers: {
Authorization: `Bearer ${token}`,
},
}).catch(() => {
return null;
});

if (response === null || (response && !response.ok)) {
if (!response.ok) {
console.error(`Error fetching projects from ${url}`);
return [] as ProjectObject[];
}
Expand Down
36 changes: 0 additions & 36 deletions app/src/context/projects-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
import {activate_project} from '../sync/process-initialization';
import {ProjectExtended} from '../types/project';
import {getLocalActiveMap, getProjectMap, getRemoteProjects} from './functions';
import {getAvailableProjectsFromListing} from '../sync/projects';
import {getAllListingIDs, getListing} from '../sync/state';

export const ProjectsContext = createContext<{
projects: ProjectExtended[];
Expand All @@ -32,7 +30,6 @@ export const ProjectsContext = createContext<{
export function ProjectsProvider({children}: {children: ReactNode}) {
const [projects, setProjects] = useState<ProjectExtended[]>([]);

console.debug('projectsProvider', projects);
useEffect(() => {
initProjects();
}, []);
Expand All @@ -55,36 +52,6 @@ export function ProjectsProvider({children}: {children: ReactNode}) {

const localActiveMap = await getLocalActiveMap();

// if we're offline, remote projects is empty so just
// return the local ones we know already

if (remoteProjects.length === 0) {
const allStoredProjects: ProjectExtended[] = [];
getAllListingIDs().forEach(async (listing_id: string) => {
const storedProjects =
await getAvailableProjectsFromListing(listing_id);
console.debug('storedProjects', storedProjects);
// storedProjects is ProjectInformation[] and we need ProjectExtended[]
const listing = await getListing(listing_id);
allStoredProjects.concat(
storedProjects.map(project => {
return {
...project,
_id: project.project_id,
conductor_url: listing.listing.conductor_url,
listing: listing_id,
activated: localActiveMap.has(project.project_id),
sync: localProjectsMap.get(project.project_id)?.sync ?? false,
// do we also need the two database connections here???
};
})
);
});
console.debug('allStoredProjects', allStoredProjects);
setProjects(allStoredProjects);
return;
}

for (const remoteProject of remoteProjects) {
const activated =
localProjectsMap.get(remoteProject._id)?.activated ??
Expand All @@ -103,7 +70,6 @@ export function ProjectsProvider({children}: {children: ReactNode}) {
});
}

console.debug('setting projects', [...newProjectsMap.values()]);
setProjects([...newProjectsMap.values()]);
};

Expand All @@ -121,8 +87,6 @@ export function ProjectsProvider({children}: {children: ReactNode}) {
const projectsMap = getProjectMap(projects);
const newProjectsMap = getProjectMap(projects);

if (remoteProjects.length === 0) return;

// update project list, preserve activated and sync states from existing list
for (const remoteProject of remoteProjects) {
newProjectsMap.set(remoteProject._id, {
Expand Down
2 changes: 0 additions & 2 deletions app/src/dbs/projects-db.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const updateProjectsDB = async (projects: ProjectExtended[]) =>
* @returns A promise that resolves when the project is activated.
*/
export const activateProjectDB = async (_id: string) => {
console.debug('activateProjectDB', await db.info());
const doc = await db.get(_id);

await db.put({
Expand Down Expand Up @@ -74,7 +73,6 @@ export const setSyncProjectDB = async (_id: string, sync: boolean) => {
* @returns An array of local projects.
*/
export const getProjectsDB = async () => {
console.debug('getProjectsDB', await db.info());
const {rows} = await db.allDocs({include_docs: true});

return rows.map(row => row?.doc?.project).filter(x => x !== undefined);
Expand Down
2 changes: 0 additions & 2 deletions app/src/gui/components/workspace/notebooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export default function NoteBooks() {

const activatedProjects = projects.filter(({activated}) => activated);

console.debug('PPPPP', projects, activatedProjects);

const [tabID, setTabID] = useState('1');

const history = useNavigate();
Expand Down

0 comments on commit 9299089

Please sign in to comment.