Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask permissions for apps if the list of apps can't be fetched #155

Merged
merged 1 commit into from
Dec 22, 2017
Merged

Ask permissions for apps if the list of apps can't be fetched #155

merged 1 commit into from
Dec 22, 2017

Conversation

goldoraf
Copy link
Contributor

@goldoraf goldoraf commented Dec 22, 2017

Until now we didn't show the cozy-bar on Drive mobile, but we want to enable some parts of it on mobile right now. The pb is that some users that installed previous versions of Drive mobile didn't request the apps permissions when connecting their device to their Cozy, and are consequently unable to display the bar's app list. This PR adds a modal that asks the user for these permissions and renews the token so that the apps can be fetched. The modal's background is a fake app list with blurry icons, that's why I had to add the SVGs.

Imgur

Copy link
Contributor

@enguerran enguerran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks, the main is about the big return that could be divided.

<hr />
</div>
)
})}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole return is too big, we shall divide it into smaller functionnal structure. Maybe create a functionnal component for the map and for the ternary operator.

As this it consumes way too much of my neurons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I extracted the AppIconand AppIconGroup: it's not only for the FakeAppList, this is still a WIP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still too big : 40 lines and 3 return statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know, I will do it, that's why I said it's WIP :)

<AppIcon label='Cozy Photos' iconSrc={require('../assets/icons/apps/icon-photos.svg')} />
<AppIcon label='Cozy Collect' iconSrc={require('../assets/icons/apps/icon-collect.svg')} />
<AppIcon label='Cozy Store' comingSoon iconSrc={require('../assets/icons/apps/icon-store.svg')} />
</AppIconGroup>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shall refactor this with a Map

const apps = {
  'Cozy Drive': '../assets/icons/apps/icon-drive.svg',
  'Cozy Photos': '../assets/icons/apps/icon-photos.svg',
  'Cozy Collect': '../assets/icons/apps/icon-collect.svg',
  'Cozy Store': '../assets/icons/apps/icon-store.svg'
}

and a map

Object.keys(apps).map(key => (
  <AppIcon label={key} iconSrc={apps[key]} />
))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we gain much by doing this... and Cozy store needs its comingSoon argument

Copy link
Contributor

@enguerran enguerran Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a comingSoon statement, I just gave an example to be inspired by.
We gain much as it's more DRY.

@@ -30,7 +30,7 @@ class Drawer extends Component {
}

render () {
const { onClaudy, visible, isClaudyLoading, toggleSupport } = this.props
const { onClaudy, visible, isClaudyLoading, toggleSupport, renewToken } = this.props
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me very weird for a Drawer component to need a renewToken prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but I don't see a better way of passing this function to the FakeAppList

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not take this any further, but it's very weird.

@@ -12,6 +12,7 @@ class SupportModal extends Component {
}

toggle = () => {
console.log('toggle')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot a console.log

dispatch(receiveAppListForbidden())
} else {
console.warn(e.message ? e.message : e)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shall wrap by a try/catch the only instruction that need it. Maybe by extracting this instruction:

Instead of

try {
  cont app = getApp()
  app.doSomething()
} catch (Exception e) {
  dispatch(noApp())
}

we can do

const getAppWithExceptionHandling = () => {
  try {
    return getApp()
  } catch (Exception e) {
    return null
  }
}

const app = getAppWithExceptionHandling()
if(app === null) {
  dispatch(noApp())
  return
}
app.doSomething()

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stack.get.apps() call is not the only instruction needing to be try/catched, there are also the stack.get.icon() calls, that's why I put everything in the try/catch (and besides that, I need to dispatch a very specific action for a very specific error, so your suggestion wouldn't work). I thought splitting this code even more could make it less readable, and I already made it more clearer than it was imho.

fix: From review

fix: responsive permission modal

feat: Handled the renewed token

fix: Forgotten appName in translated desc

feat: Added className so that we can hide some buttons on mobile
@goldoraf goldoraf changed the title [WIP] Ask permissions for apps if the list of apps can't be fetched Ask permissions for apps if the list of apps can't be fetched Dec 22, 2017
Copy link
Contributor

@y-lohse y-lohse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I agree that the renewToken is passed around a bit too much but I don't see any better way either.

@Narkfr
Copy link
Contributor

Narkfr commented Dec 22, 2017

LGTM 👍

@goldoraf goldoraf merged commit 2fa6670 into cozy:master Dec 22, 2017
@goldoraf goldoraf deleted the apps-permission branch December 22, 2017 16:02
@y-lohse y-lohse mentioned this pull request Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants