Skip to content

Commit

Permalink
Filter "your study" cards when not publicly accessible or admin logge…
Browse files Browse the repository at this point in the history
…d in
  • Loading branch information
JackWilb committed Jan 28, 2025
1 parent 11b287e commit 997cbc6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
33 changes: 28 additions & 5 deletions src/components/ConfigSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { ErrorLoadingConfig } from './ErrorLoadingConfig';
import { ParticipantStatusBadges } from '../analysis/interface/ParticipantStatusBadges';
import { useStorageEngine } from '../storage/storageEngineHooks';
import { REVISIT_MODE } from '../storage/engines/StorageEngine';
import { FirebaseStorageEngine } from '../storage/engines/FirebaseStorageEngine';
import { useAuth } from '../store/hooks/useAuth';

const REVISIT_GITHUB_PUBLIC = 'https://github.com/revisit-studies/study/tree/main/public/';

Expand Down Expand Up @@ -197,17 +199,38 @@ export function ConfigSwitcher({
globalConfig: GlobalConfig;
studyConfigs: Record<string, ParsedConfig<StudyConfig> | null>;
}) {
const { storageEngine } = useStorageEngine();
const { configsList } = globalConfig;

const demos = configsList.filter((configName) => configName.startsWith('demo-'));
const tutorials = configsList.filter((configName) => configName.startsWith('tutorial-'));
const examples = configsList.filter((configName) => configName.startsWith('example-'));
const tests = configsList.filter((configName) => configName.startsWith('test-'));
const libraries = configsList.filter((configName) => configName.startsWith('library-'));
const others = configsList.filter((configName) => !configName.startsWith('demo-') && !configName.startsWith('tutorial-') && !configName.startsWith('example-') && !configName.startsWith('test-') && !configName.startsWith('library-'));
const others = useMemo(() => configsList.filter((configName) => !configName.startsWith('demo-') && !configName.startsWith('tutorial-') && !configName.startsWith('example-') && !configName.startsWith('test-') && !configName.startsWith('library-')), [configsList]);

const [otherStudyVisibility, setOtherStudyVisibility] = useState<Record<string, boolean>>({});
useEffect(() => {
async function getVisibilities() {
const visibility: Record<string, boolean> = {};
await Promise.all(
others.map(async (configName) => {
if (storageEngine instanceof FirebaseStorageEngine) {
const modes = await storageEngine.getModes(configName);
visibility[configName] = modes.analyticsInterfacePubliclyAccessible;
}
}),
);
setOtherStudyVisibility(visibility);
}
getVisibilities();
}, [others, storageEngine]);

const { user } = useAuth();
const othersFiltered = useMemo(() => others.filter((configName) => otherStudyVisibility[configName] || user.isAdmin), [others, otherStudyVisibility, user]);

const [searchParams] = useSearchParams();
const tab = useMemo(() => searchParams.get('tab') || (others.length > 0 ? 'Others' : 'Demos'), [others.length, searchParams]);
const tab = useMemo(() => searchParams.get('tab') || (othersFiltered.length > 0 ? 'Others' : 'Demos'), [othersFiltered.length, searchParams]);
const navigate = useNavigate();

return (
Expand All @@ -223,7 +246,7 @@ export function ConfigSwitcher({
/>
<Tabs variant="outline" defaultValue={others.length > 0 ? 'Others' : 'Demos'} value={tab} onChange={(value) => navigate(`/?tab=${value}`)}>
<Tabs.List>
{others.length > 0 && (
{othersFiltered.length > 0 && (
<Tabs.Tab value="Others">Your Studies</Tabs.Tab>
)}
<Tabs.Tab value="Demos">Demo Studies</Tabs.Tab>
Expand All @@ -233,9 +256,9 @@ export function ConfigSwitcher({
<Tabs.Tab value="Libraries">Libraries</Tabs.Tab>
</Tabs.List>

{others.length > 0 && (
{othersFiltered.length > 0 && (
<Tabs.Panel value="Others">
<StudyCards configNames={others} studyConfigs={studyConfigs} />
<StudyCards configNames={othersFiltered} studyConfigs={studyConfigs} />
</Tabs.Panel>
)}

Expand Down
10 changes: 9 additions & 1 deletion src/components/settings/GlobalSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { StoredUser } from '../../storage/engines/StorageEngine';
import { signInWithGoogle } from '../../Login';

export function GlobalSettings() {
const { user, triggerAuth } = useAuth();
const { user, triggerAuth, logout } = useAuth();
const { storageEngine } = useStorageEngine();

const [isAuthEnabled, setAuthEnabled] = useState<boolean>(false);
Expand Down Expand Up @@ -155,6 +155,14 @@ export function GlobalSettings() {
</Flex>
),
) : null}
<Flex direction="row" justify="left">
<Button
onClick={() => logout()}
mt={20}
>
Log out
</Button>
</Flex>
</Flex>
)
: null}
Expand Down

0 comments on commit 997cbc6

Please sign in to comment.